You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A Python implementation of the LabThings API structure, based on the Flask microframework.
10
+
A thread-based Python implementation of the LabThings API structure, based on the Flask microframework.
11
11
12
12
## Installation
13
13
@@ -18,54 +18,140 @@ A Python implementation of the LabThings API structure, based on the Flask micro
18
18
This example assumes a `PretendSpectrometer` class, which already has `data` and `integration_time` attributes, as well as an `average_data(n)` method. LabThings allows you to easily convert this existing instrument control code into a fully documented, standardised web API complete with auto-discovery and automatic background task threading.
19
19
20
20
```python
21
-
from labthings import fields, create_app
21
+
#!/usr/bin/env python
22
+
import time
23
+
24
+
from labthings import ActionView, PropertyView, create_app, fields, find_component, op
22
25
from labthings.example_components import PretendSpectrometer
26
+
from labthings.json import encode_json
27
+
28
+
"""
29
+
Class for our lab component functionality. This could include serial communication,
30
+
equipment API calls, network requests, or a "virtual" device as seen here.
31
+
"""
32
+
33
+
34
+
"""
35
+
Create a view to view and change our integration_time value,
36
+
and register is as a Thing property
37
+
"""
38
+
39
+
40
+
# Wrap in a semantic annotation to autmatically set schema and args
Copy file name to clipboardExpand all lines: docs/basic_usage/app_thing_server.rst
+7-3Lines changed: 7 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -33,12 +33,16 @@ The LabThing object is our main entrypoint, and handles creating API views, mana
33
33
.. autoclass:: labthings.LabThing
34
34
:noindex:
35
35
36
-
Two key methods are :meth:`labthings.LabThing.build_property` and :meth:`labthings.LabThing.build_action`. These methods allow the automation creation of Property and Action API views from Python object attributes and methods. By passing schemas to these methods, argument and response marshalling is automatically performed. Offloading actions to background threads is also handled automatically.
37
36
38
-
.. automethod:: labthings.LabThing.build_property
37
+
Views
38
+
-----
39
+
40
+
Thing interaction affordances are created using Views. Two main View types correspond to properties and actions.
0 commit comments