labthings_fastapi.utilities

Submodules

Package Contents

Classes

LabThingsObjectData

Functions

class_attributes

A list of all the attributes of an object’s class

attributes

A list of all the attributes of an object not starting with __

labthings_data

Get (or create) a dictionary for LabThings properties

get_blocking_portal

Retrieve a blocking portal from a Thing

wrap_plain_types_in_rootmodel

Ensure a type is a subclass of BaseModel.

model_to_dict

Convert a pydantic model to a dictionary

Data

LABTHINGS_DICT_KEY

API

labthings_fastapi.utilities.class_attributes(obj: Any) Iterable[tuple[str, Any]]

A list of all the attributes of an object’s class

labthings_fastapi.utilities.attributes(cls: Any) Iterable[tuple[str, Any]]

A list of all the attributes of an object not starting with __

labthings_fastapi.utilities.LABTHINGS_DICT_KEY

‘__labthings’

class labthings_fastapi.utilities.LabThingsObjectData
property_observers: Dict[str, weakref.WeakSet]

‘Field(…)’

action_observers: Dict[str, weakref.WeakSet]

‘Field(…)’

labthings_fastapi.utilities.labthings_data(obj: labthings_fastapi.thing.Thing) labthings_fastapi.utilities.LabThingsObjectData

Get (or create) a dictionary for LabThings properties

labthings_fastapi.utilities.get_blocking_portal(obj: labthings_fastapi.thing.Thing) Optional[anyio.from_thread.BlockingPortal]

Retrieve a blocking portal from a Thing

labthings_fastapi.utilities.wrap_plain_types_in_rootmodel(model: type) type[pydantic.BaseModel]

Ensure a type is a subclass of BaseModel.

If a BaseModel subclass is passed to this function, we will pass it through unchanged. Otherwise, we wrap the type in a RootModel. In the future, we may explicitly check that the argument is a type and not a model instance.

labthings_fastapi.utilities.model_to_dict(model: Optional[pydantic.BaseModel]) Dict[str, Any]

Convert a pydantic model to a dictionary

We convert only the top level model, i.e. we do not recurse into submodels. This is important to avoid serialising Blob objects in action inputs. This function returns dict(model), with exceptions for the case of None (converted to an empty dictionary) and RootModels (checked to see if they correspond to empty input).

If RootModels with non-empty input are allowed, this function will need to be updated to handle them.