labthings_fastapi.server.config_model ===================================== .. py:module:: labthings_fastapi.server.config_model .. autoapi-nested-parse:: 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 ---------- .. autoapisummary:: labthings_fastapi.server.config_model.ThingImportString labthings_fastapi.server.config_model.ThingName labthings_fastapi.server.config_model.ThingsConfig Exceptions ---------- .. autoapisummary:: labthings_fastapi.server.config_model.ThingImportFailure Functions --------- .. autoapisummary:: labthings_fastapi.server.config_model.contain_import_errors labthings_fastapi.server.config_model.normalise_things_config Module Contents --------------- .. py:exception:: ThingImportFailure Bases: :py:obj:`BaseException` Failed to import Thing. Raise with import traceback. Initialize self. See help(type(self)) for accurate signature. .. py:function:: contain_import_errors(value: Any, handler: pydantic.ValidatorFunctionWrapHandler) -> Any Prevent errors during import from causing odd validation errors. This is used to wrap the pydantic ImportString validator, and ensures that any module that won't import shows up with a single clear error. :param value: The value being validated. :param handler: The validator handler. :return: The validated value. :raises ThingImportFailure: if an import error occurs, with the stack trace from retrying the import. :raises Exception: In the unlikely event that the import error cannot be reproduced .. py:data:: ThingImportString .. py:data:: ThingName .. py:type:: ThingsConfig :canonical: Mapping[ThingName, ThingConfig | ThingImportString] .. py:function:: 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. :param things: A mapping of names to Things, either classes or `.ThingConfig` objects. :return: A mapping of names to `.ThingConfig` objects. :raises ValueError: if a Python object is passed that's neither a `type` nor a `dict`\ .