labthings_fastapi.client.in_server
A mock client that uses a Thing directly.
Currently this is not a subclass of ThingClient, that may need to change. It’s a good idea to create a DirectThingClient at module level, so that type hints work.
This module may get moved in the near future.
Module Contents
Classes
Functions
Create a correctly-typed descriptor that gets and/or sets a property |
|
Generates an action method and adds it to an attrs dict |
|
Add a property to a DirectThingClient subclass |
|
Create a DirectThingClient from a Thing class and a path |
API
- class labthings_fastapi.client.in_server.DirectThingClient(request: fastapi.Request, **dependencies: Mapping[str, Any])
Initialization
Wrapper for a Thing that makes it work like a ThingClient
This class is designed to be used as a FastAPI dependency, and will retrieve a Thing based on its
thing_pathattribute. Finding the Thing by class may also be an option in the future.- __globals__
‘globals(…)’
- thing_class: type[labthings_fastapi.thing.Thing]
None
- labthings_fastapi.client.in_server.property_descriptor(property_name: str, model: Union[type, pydantic.BaseModel], description: Optional[str] = None, readable: bool = True, writeable: bool = True, property_path: Optional[str] = None) labthings_fastapi.client.PropertyClientDescriptor
Create a correctly-typed descriptor that gets and/or sets a property
This is copy-pasted from labthings_fastapi.client.init.property_descriptor TODO: refactor this into a shared function.
- labthings_fastapi.client.in_server.add_action(attrs: dict[str, Any], dependencies: list[inspect.Parameter], name: str, action: labthings_fastapi.descriptors.action.ActionDescriptor) None
Generates an action method and adds it to an attrs dict
FastAPI Dependencies are appended to the
dependencieslist.