labthings_fastapi.client
A first pass at a client library for LabThings-FastAPI
This will become its own package if it’s any good. The goal is to see if we can make a client library that produces introspectable Python objects from a Thing Description.
Submodules
Package Contents
Classes
A client for a LabThings-FastAPI Thing |
|
Functions
Retrieve a link from an object’s |
|
Retrieve the |
|
Extract the endpoint address from a task dictionary |
|
Poll a task until it finishes, and return the return value |
|
Create a correctly-typed descriptor that gets and/or sets a property |
|
Add an action to a ThingClient subclass |
|
Add a property to a ThingClient subclass |
Data
API
- labthings_fastapi.client.ACTION_RUNNING_KEYWORDS
[‘idle’, ‘pending’, ‘running’]
- labthings_fastapi.client.get_link(obj: dict, rel: str) collections.abc.Mapping
Retrieve a link from an object’s
linkslist, by itsrelattribute
- labthings_fastapi.client.get_link_href(obj: dict, rel: str) str
Retrieve the
hreffrom an object’slinkslist, by itsrelattribute
- labthings_fastapi.client.task_href(t)
Extract the endpoint address from a task dictionary
- labthings_fastapi.client.poll_task(client, task, interval=0.5, first_interval=0.05)
Poll a task until it finishes, and return the return value
- class labthings_fastapi.client.ThingClient(base_url: str, client: Optional[httpx.Client] = None)
A client for a LabThings-FastAPI Thing
NB ThingClient must be subclassed to add actions/properties, so this class will be minimally useful on its own.
Initialization
- follow_link(response: dict, rel: str) httpx.Response
Follow a link in a response object, by its
relattribute
- classmethod from_url(thing_url: str, client: Optional[httpx.Client] = None, **kwargs) typing_extensions.Self
Create a ThingClient from a URL
This will dynamically create a subclass with properties and actions, and return an instance of that subclass pointing at the Thing URL.
Additional
kwargswill be passed to the subclass constructor, in particular you may pass aclientobject (useful for testing).
- class labthings_fastapi.client.PropertyClientDescriptor
- labthings_fastapi.client.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
- labthings_fastapi.client.add_action(cls: type[labthings_fastapi.client.ThingClient], action_name: str, action: dict)
Add an action to a ThingClient subclass
- labthings_fastapi.client.add_property(cls: type[labthings_fastapi.client.ThingClient], property_name: str, property: dict)
Add a property to a ThingClient subclass