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

DirectThingClient

Functions

property_descriptor

Create a correctly-typed descriptor that gets and/or sets a property

add_action

Generates an action method and adds it to an attrs dict

add_property

Add a property to a DirectThingClient subclass

direct_thing_client_class

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])
__globals__

‘globals(…)’

thing_class: type[labthings_fastapi.thing.Thing]

None

thing_path: str

None

__init__(request: fastapi.Request, **dependencies: Mapping[str, Any])

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_path attribute. Finding the Thing by class may also be an option in the future.

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 dependencies list.

labthings_fastapi.client.in_server.add_property(attrs: dict[str, Any], property_name: str, property: labthings_fastapi.descriptors.property.ThingProperty) None

Add a property to a DirectThingClient subclass

labthings_fastapi.client.in_server.direct_thing_client_class(thing_class: type[labthings_fastapi.thing.Thing], thing_path: str, actions: Optional[list[str]] = None)

Create a DirectThingClient from a Thing class and a path

This is a class, not an instance: it’s designed to be a FastAPI dependency.