labthings_fastapi.server

Code supporting the LabThings server.

LabThings wraps the fastapi.FastAPI application in a ThingServer, which provides the tools to serve and manage Thing instances.

See the LabThings-FastAPI tutorial for examples of how to set up a ThingServer.

Submodules

Attributes

ThingDescription

_thing_servers

PATH_REGEX

Functions

object_reference_to_object(→ Any)

Convert a string reference to an object.

server_from_config(→ ThingServer)

Create a ThingServer from a configuration dictionary.

Package Contents

labthings_fastapi.server.object_reference_to_object(object_reference: str) Any

Convert a string reference to an object.

This is taken from: https://packaging.python.org/en/latest/specifications/entry-points/

The format of the string is module_name:qualname where qualname is the fully qualified name of the object within the module. This is the same format used by entrypoints` in setup.py files.

Parameters:

object_reference – a string referencing a Python object to import.

Returns:

the Python object.

Raises:

ImportError – if the referenced object cannot be found or imported.

labthings_fastapi.server.ThingDescription
labthings_fastapi.server._thing_servers: weakref.WeakSet[labthings_fastapi.server.ThingServer]
labthings_fastapi.server.PATH_REGEX
labthings_fastapi.server.server_from_config(config: dict) ThingServer

Create a ThingServer from a configuration dictionary.

This function creates a ThingServer and adds a number of Thing instances from a configuration dictionary.

Parameters:

config – A dictionary, in the format used by Configuration files

Returns:

A ThingServer with instances of the specified Thing subclasses attached. The server will not be started by this function.

Raises:

ImportError – if a Thing could not be loaded from the specified object reference.