ConfigDependency#
- class safir.dependencies.config.ConfigDependency(base_model, default_config_path, path_env)#
Bases:
GenericProvides the configuration as a dependency.
We want a production deployment to default to one configuration path, but allow that path to be overridden by the test suite and, if the path changes, to reload the configuration (which allows sharing the same set of global singletons across multiple tests). Do this by loading the config dynamically when it’s first requested and reloading it whenever the configuration path is changed.
- Parameters:
config_model – Base model for the configuration.
default_config_path (
Union[Path,str]) – Default path to the configuration file.path_env (
str) – Environment variable from which to get the path to the configuration file, if set, overriding the default path.base_model (
type[TypeVar(T, bound=YamlBaseSettings)])
Attributes Summary
Path to the configuration file.
Methods Summary
__call__()Load the configuration if necessary and return it.
config()Load the configuration if necessary and return it.
set_config_path(path)Change the configuration path and reload the config.
Attributes Documentation
- config_path#
Path to the configuration file.
Methods Documentation
- async __call__()#
Load the configuration if necessary and return it.
- Return type:
TypeVar(T, bound=YamlBaseSettings)
- config()#
Load the configuration if necessary and return it.
This is equivalent to using the dependency as a callable except that it’s not async and can therefore be used from non-async functions.
- Return type:
TypeVar(T, bound=YamlBaseSettings)