77"""
88
99from __future__ import annotations
10- from typing import AsyncGenerator , Optional , TypeVar
10+ from typing import Any , AsyncGenerator , Optional , TypeVar
1111from typing_extensions import Self
1212import os
1313
@@ -65,6 +65,7 @@ def __init__(
6565 self ,
6666 things : ThingsConfig ,
6767 settings_folder : Optional [str ] = None ,
68+ application_config : Optional [Mapping [str , Any ]] = None ,
6869 ) -> None :
6970 r"""Initialise a LabThings server.
7071
@@ -81,10 +82,18 @@ def __init__(
8182 arguments, and any connections to other `.Thing`\ s.
8283 :param settings_folder: the location on disk where `.Thing`
8384 settings will be saved.
85+ :param application_config: A mapping containing custom configuration for the
86+ application. This is not processed by LabThings. Each `.Thing` can access
87+ application. This is not processed by LabThings. Each `.Thing` can access
88+ this via the Thing-Server interface.
8489 """
8590 self .startup_failure : dict | None = None
8691 configure_thing_logger () # Note: this is safe to call multiple times.
87- self ._config = ThingServerConfig (things = things , settings_folder = settings_folder )
92+ self ._config = ThingServerConfig (
93+ things = things ,
94+ settings_folder = settings_folder ,
95+ application_config = application_config ,
96+ )
8897 self .app = FastAPI (lifespan = self .lifespan )
8998 self ._set_cors_middleware ()
9099 self ._set_url_for_middleware ()
@@ -148,6 +157,15 @@ def things(self) -> Mapping[str, Thing]:
148157 """
149158 return MappingProxyType (self ._things )
150159
160+ @property
161+ def application_config (self ) -> Mapping [str , Any ] | None :
162+ """Return the application configuration from the config file.
163+
164+ :return: The custom configuration as specified in the configuration
165+ file.
166+ """
167+ return self ._config .application_config
168+
151169 ThingInstance = TypeVar ("ThingInstance" , bound = Thing )
152170
153171 def things_by_class (self , cls : type [ThingInstance ]) -> Sequence [ThingInstance ]:
0 commit comments