labthings_fastapi.dependencies.raw_thing ======================================== .. py:module:: labthings_fastapi.dependencies.raw_thing .. autoapi-nested-parse:: FastAPI dependency to obtain a `.Thing` directly. This module allows actions to obtain a `.Thing` instance without the `.DirectThingClient` wrapper. As a rule, it is best to use `.DirectThingClient` where possible. Attributes ---------- .. autoapisummary:: labthings_fastapi.dependencies.raw_thing.ThingInstance Functions --------- .. autoapisummary:: labthings_fastapi.dependencies.raw_thing.find_raw_thing_by_class Module Contents --------------- .. py:data:: ThingInstance .. py:function:: find_raw_thing_by_class(cls: type[ThingInstance]) -> Callable[[fastapi.Request], ThingInstance] Generate a function that locates the instance of a Thing subclass. .. warning:: Using a `.Thing` directly can be tricky: unless you really need to, it is usually better to use a `.DirectThingClient`, which provides an interface that should be identical to the HTTP thing client in Python. This is safer, and means code should be easier to translate between server and client-side. In order to access the instance of ``OtherThing`` attached to your thing server, declare your argument type as: .. code-block:: python OtherThingDep = Annotated[ OtherThing, Depends(find_raw_thing_by_class(OtherThing)) ] def endpoint(other_thing: OtherThingDep): pass LabThings will supply this argument automatically through the :ref:`dependencies` mechanism. Note that this function *returns* a dependency - it should be called with arguments inside `fastapi.Depends`. :param cls: is the `.Thing` subclass that will be returned by the dependency. :return: a dependency suitable for use with `fastapi.Depends` (see example).