labthings_fastapi.dependencies.action_manager ============================================= .. py:module:: labthings_fastapi.dependencies.action_manager .. autoapi-nested-parse:: Context Var access to the Action Manager. This module provides a context var to access the Action Manager instance. While LabThings tries pretty hard to conform to FastAPI's excellent convention that everything should be passed as a parameter, there are some cases where that's hard. In particular, generating URLs when responses are serialised is difficult, because `pydantic` doesn't have a way to access the `fastapi.Request` object and use `fastapi.Request.url_for`. If an endpoint uses the `.ActionManagerDep` dependency, then the `.ActionManager` is supplied as an argument. More usefully, when the output is serialised the `.ActionManager` is available using `.ActionManagerContext.get()`. This is currently only used by `.Blob` objects, as "serialising" a `.Blob` involves adding it to the `.ActionManager` and generating a download URL. Attributes ---------- .. autoapisummary:: labthings_fastapi.dependencies.action_manager.ActionManagerDep labthings_fastapi.dependencies.action_manager.ActionManagerContext labthings_fastapi.dependencies.action_manager.ActionManagerContextDep Functions --------- .. autoapisummary:: labthings_fastapi.dependencies.action_manager.action_manager_from_thing_server labthings_fastapi.dependencies.action_manager.make_action_manager_context_available Module Contents --------------- .. py:function:: action_manager_from_thing_server(request: fastapi.Request) -> labthings_fastapi.actions.ActionManager Retrieve the Action Manager from the Thing Server. This is for use as a FastAPI dependency. We use the ``request`` to access the `.ThingServer` and thus access the `.ActionManager`. :param request: the FastAPI request object. This will be supplied by FastAPI when this function is used as a dependency. :return: the `.ActionManager` object associated with our `.ThingServer`. .. py:data:: ActionManagerDep A ready-made dependency type for the `ActionManager` object. .. py:data:: ActionManagerContext .. py:function:: make_action_manager_context_available(action_manager: ActionManagerDep) -> AsyncGenerator[labthings_fastapi.actions.ActionManager] :async: Make the Action Manager available in the context variable. The action manager may be accessed using `ActionManagerContext.get()` within this context manager. :param action_manager: The `.ActionManager` object. Note that this is an annotated type so it will be supplied automatically when used as a FastAPI dependency. :yield: the `.ActionManager` object. .. py:data:: ActionManagerContextDep :type: typing_extensions.TypeAlias