ConfZ

class confz.ConfZ

Bases: BaseModel

Base class, parent of every config class. Internally wraps :class:`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.

CONFIG_SOURCES: ClassVar[Optional[ConfZSources]] = None

Sources to use as input.

confz_instance: ClassVar[Optional[Any]] = None

for internal use only

listeners: ClassVar[Optional[List[Any]]] = None

for internal use only

classmethod change_config_sources(config_sources: confz.confz_source.ConfZSources) 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.

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

ConfZException – If any config could not be loaded.