diff --git a/examples/builder.py b/examples/builder.py deleted file mode 100644 index 3d22bf92..00000000 --- a/examples/builder.py +++ /dev/null @@ -1,55 +0,0 @@ -from labthings import create_app, semantics, fields -from labthings.example_components import PretendSpectrometer - - -# Create LabThings Flask app -app, labthing = create_app( - __name__, - title="My Lab Device API", - description="Test LabThing-based API", - version="0.1.0", - types=["org.labthings.examples.builder"], -) - -# Attach an instance of our component -# Usually a Python object controlling some piece of hardware -my_spectrometer = PretendSpectrometer() -labthing.add_component(my_spectrometer, "org.labthings.example.mycomponent") - -# Make some properties and actions out of our component - -labthing.build_property( - my_spectrometer, # Python object - "integration_time", # Objects attribute name - description="Single-shot integration time", - semtype=semantics.moz.LevelProperty(100, 500, example=200, unit="microsecond"), -) - -labthing.build_property( - my_spectrometer, # Python object - "settings", # Objects attribute name - description="A big dictionary of little settings", - schema={ # Property is a dictionary, with these value types - "voltage": fields.Int(), - "mode": fields.String(), - "light_on": fields.Bool(), - "user": {"name": fields.String(), "id": fields.Int()}, - }, -) - -labthing.build_action( - my_spectrometer, # Python object - "average_data", # Objects method name - description="Take an averaged measurement", - safe=True, # Is the state of the Thing unchanged by calling the action? - idempotent=True, # Can the action be called repeatedly with the same result?, - args={ # How do we convert from the request input to function arguments? - "n": fields.Int(description="Number of averages to take", example=5, default=5) - }, -) - -# Start the app -if __name__ == "__main__": - from labthings.server.wsgi import Server - - Server(app).run() diff --git a/examples/docs_example.py b/examples/docs_example.py deleted file mode 100644 index 96e24a39..00000000 --- a/examples/docs_example.py +++ /dev/null @@ -1,50 +0,0 @@ -from labthings import fields, create_app -from labthings.example_components import PretendSpectrometer - - -# Create LabThings Flask app -app, labthing = create_app( - __name__, - title="My PretendSpectrometer API", - description="LabThing API for PretendSpectrometer", - version="0.1.0", -) - - -# Make some properties and actions out of our component -my_spectrometer = PretendSpectrometer() - -# Single-shot data property -labthing.build_property( - my_spectrometer, # Python object - "data", # Objects attribute name - description="A single-shot measurement", - readonly=True, - schema=fields.List(fields.Number()), -) - -# Integration time property -labthing.build_property( - my_spectrometer, # Python object - "integration_time", # Objects attribute name - description="Single-shot integration time", - schema=fields.Int(min=100, max=500, example=200, unit="microsecond"), -) - -# Averaged measurement action -labthing.build_action( - my_spectrometer, # Python object - "average_data", # Objects method name - description="Take an averaged measurement", - schema=fields.List(fields.Number()), - args={ # How do we convert from the request input to function arguments? - "n": fields.Int(description="Number of averages to take", example=5, default=5) - }, -) - - -# Start the app -if __name__ == "__main__": - from labthings import Server - - Server(app).run()