class MeasurementAction(ActionView): # Expect JSON parameters in the request body. # Pass to post function as dictionary argument. args = { "averages": fields.Integer( missing=20, example=20, description="Number of data sets to average over", ) } # Marshal the response as a list of numbers schema = fields.List(fields.Number) # Main function to handle POST requests @op.invokeaction def post(self, args): """Start an averaged measurement""" logging.warning("Starting a measurement") # Find our attached component my_component = find_component("org.labthings.example.mycomponent") # Get arguments and start a background task n_averages = args.get("averages") logging.warning("Finished a measurement") # Return the task information return my_component.average_data(n_averages)
class QuickDataProperty(PropertyView): schema = fields.List(fields.Float()) # Main function to handle GET requests def get(self): """Show the current data value""" # Find our attached component my_component = find_component("org.labthings.example.mycomponent") return my_component.data
class QuickDataProperty(PropertyView): """Show the current data value""" # Marshal the response as a list of floats schema = fields.List(fields.Float()) @op.readproperty def get(self): # Find our attached component my_component = find_component("org.labthings.example.mycomponent") return my_component.data
class UserSchema(Schema): name = fields.String(required=True, validate=validate.Length(min=1, max=255)) age = fields.Float() created = fields.DateTime() created_formatted = fields.DateTime(format="%Y-%m-%d", attribute="created", dump_only=True) created_iso = fields.DateTime(format="iso", attribute="created", dump_only=True) updated = fields.DateTime() species = fields.String(attribute="SPECIES") id = fields.String(default="no-id") homepage = fields.Url() email = fields.Email() balance = fields.Decimal() registered = fields.Boolean() hair_colors = fields.List(fields.Raw) sex_choices = fields.List(fields.Raw) finger_count = fields.Integer() uid = fields.UUID() time_registered = fields.Time() birthdate = fields.Date() since_created = fields.TimeDelta() sex = fields.Str(validate=validate.OneOf( choices=["male", "female", "non_binary", "other"], labels=["Male", "Female", "Non-binary/fluid", "Other"], )) various_data = fields.Dict() addresses = fields.Nested(Address, many=True, validate=validate.Length(min=1, max=3)) github = fields.Nested(GithubProfile) const = fields.String(validate=validate.Length(equal=50)) bytestring = fields.Bytes()
class ListSchema(Schema): bar = fields.List(fields.Nested(InnerSchema), required=True)
class ListSchema(Schema): foo = fields.List(fields.String(), required=True)