labthings_fastapi.server.config_model

Pydantic models to enable server configuration to be loaded from file.

The models in this module allow ThingConfig dataclasses to be constructed from dictionaries or JSON files. They also describe the full server configuration with ServerConfigModel. These models are used by the cli module to start servers based on configuration files or strings.

Attributes

ThingName

ThingsConfig

Functions

normalise_things_config(...)

Ensure every Thing is defined by a ThingConfig object.

Module Contents

labthings_fastapi.server.config_model.ThingName
type labthings_fastapi.server.config_model.ThingsConfig = Mapping[ThingName, ThingConfig | ImportString]
labthings_fastapi.server.config_model.normalise_things_config(things: ThingsConfig) collections.abc.Mapping[ThingName, ThingConfig]

Ensure every Thing is defined by a ThingConfig object.

Things may be specified either using a ThingConfig object, or just a bare Thing subclass, if the other parameters are not needed. To simplify code that uses the configuration, this function wraps bare classes in a ThingConfig so the values are uniformly typed.

Parameters:

things – A mapping of names to Things, either classes or ThingConfig objects.

Returns:

A mapping of names to ThingConfig objects.

Raises:

ValueError – if a Python object is passed that’s neither a type nor a dict.