ConfZ¶
- class confz.BaseConfig¶
Bases:
BaseModel
Base class, parent of every config class. Internally wraps
BaseModel
of pydantic and behaves transparent except for two cases:If the constructor gets config_sources as kwarg, these sources are used as input to enrich the other kwargs.
If the class has the class variable CONFIG_SOURCES defined, these sources are used as input.
In the latter case, a singleton mechanism is activated, returning the same config class instance every time the constructor is called.
- classmethod change_config_sources(config_sources: confz.config_source.ConfigSources) AbstractContextManager ¶
Change the CONFIG_SOURCES class variable within a controlled context. Within this context, the sources will be different and the singleton reset. This can be useful in unit tests to temporarily change a configuration.
- Parameters:
config_sources – The temporary config sources for within the context.
- Returns:
Context manager for change of config sources.
- model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {}¶
A dictionary of computed field names and their corresponding ComputedFieldInfo objects.
- model_config: ClassVar[ConfigDict] = {'frozen': True}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- confz.depends_on(*args)¶
Decorator to transform a function into a singleton and register it to a set of config classes.
- confz.validate_all_configs(include_listeners: bool = False)¶
Instantiates all config classes with a singleton mechanism (CONFIG_SOURCES set). This allows to catch validation errors early instead of waiting for the first access.
- Parameters:
include_listeners – Whether all listeners (marked with
depends_on()
) should be included.- Raises:
ConfigException – If any config could not be loaded.