Core Primitives¶
Use this page when you want the main configuration building blocks:
BaseConfigandConfigMetafor defining config containers.Field,field(),Group, andgroup()for declaring config attributes.Varfor direct access to the boundContextVarwrapper.
liblaf.conf.BaseConfig
¶
Group related configuration variables behind a singleton object.
Subclasses declare Field descriptors for scalar values
and group descriptors for nested configuration
sections. Instances expose helpers for loading environment variables,
applying temporary overrides, and serializing the current state.
Methods:
-
load_env–Refresh every field from its configured environment variable.
-
override–Temporarily override one or more values within a context manager.
-
set–Update fields or groups from a mapping and keyword arguments.
-
to_dict–Serialize the current config tree to nested dictionaries.
-
to_namespace–Serialize the current config tree to nested namespaces.
Attributes:
-
env_prefix(str) – -
name(str) –
load_env
¶
Refresh every field from its configured environment variable.
Source code in src/liblaf/conf/_config.py
override
¶
Temporarily override one or more values within a context manager.
Parameters:
-
changes(Mapping[str, Any] | None, default:None) –Optional mapping of names to temporary values.
-
**kwargs(Any, default:{}) –Additional name-to-value overrides.
Yields:
-
Generator[None]–Nonewhile the overrides are active.
Source code in src/liblaf/conf/_config.py
set
¶
Update fields or groups from a mapping and keyword arguments.
Nested groups accept mapping values and forward them to the nested
config's own set() method.
Source code in src/liblaf/conf/_config.py
to_dict
¶
Serialize the current config tree to nested dictionaries.
Source code in src/liblaf/conf/_config.py
to_namespace
¶
to_namespace() -> SimpleNamespace
Serialize the current config tree to nested namespaces.
Source code in src/liblaf/conf/_config.py
liblaf.conf.ConfigMeta
¶
Bases: type
flowchart TD
liblaf.conf.ConfigMeta[ConfigMeta]
click liblaf.conf.ConfigMeta href "" "liblaf.conf.ConfigMeta"
Build config classes and cache a singleton instance per subclass.
Methods:
-
__call__–Return the cached config instance, creating it on first access.
-
__new__–Create a config class with derived metadata and descriptor maps.
__call__
¶
__call__[T: BaseConfig](*args, **kwargs) -> T
Return the cached config instance, creating it on first access.
Source code in src/liblaf/conf/_config.py
__new__
¶
__new__(
mcs,
name: str,
bases: tuple[type, ...],
namespace: dict[str, Any],
/,
**_kwargs: Any,
) -> type
Create a config class with derived metadata and descriptor maps.
Source code in src/liblaf/conf/_config.py
liblaf.conf.Field
dataclass
¶
Field(
env: str | None = None,
default: T | MissingType = MISSING,
factory: Factory[T] | None = None,
converter: Converter[T] = identity,
)
Describe a config value and lazily bind it to a Var.
The descriptor stores the environment-variable name, default value, optional factory, and string converter used when it creates a bound variable for a config instance.
Parameters:
-
env(str | None, default:None) – -
default(T | MissingType, default:<MissingType.MISSING: 1>) – -
factory(T | None, default:None) – -
converter(T, default:<function identity at 0x7fe03ade6c40>) –
Attributes:
Methods:
-
__get__–Return the descriptor on the class or a cached bound variable.
-
__set_name__–Record the attribute name assigned by the owning config class.
__get__
¶
Return the descriptor on the class or a cached bound variable.
Source code in src/liblaf/conf/_field.py
__set_name__
¶
liblaf.conf.field
¶
field[T](
*,
env: str | None = None,
default: T | MissingType = MISSING,
factory: Factory[T] | None = None,
converter: Converter[T] = identity,
) -> Field[T]
Create a Field descriptor for a config attribute.
Source code in src/liblaf/conf/_field.py
liblaf.conf.Group
dataclass
¶
Group(factory: Callable[[], T])
Cache a nested config or computed object per owning instance.
Parameters:
-
factory(Callable[[], T]) –
Attributes:
Methods:
-
__get__–Return the descriptor on the class or the cached group value.
-
__set_name__–Record the attribute name assigned by the owning class.
__get__
¶
Return the descriptor on the class or the cached group value.
Source code in src/liblaf/conf/_group.py
__set_name__
¶
liblaf.conf.group
¶
liblaf.conf.Var
dataclass
¶
Var(
name: str,
default: T | MissingType = MISSING,
factory: Factory[T] | None = None,
env: str | None = None,
converter: Converter[T] | None = None,
)
Store one typed configuration value in a ContextVar.
Values can be seeded from a default, a factory, or an environment variable.
Temporary overrides use normal ContextVar semantics, so they are scoped to
the active context.
Parameters:
-
env(str | None) – -
converter(T) –
Methods:
-
__hash__–Hash the wrapped context variable.
-
get–Return the current value or a caller-provided fallback.
-
load_env–Reload the current value from the configured environment variable.
-
override–Temporarily set a value for the duration of a context manager.
-
reset–Restore the value captured by
set(). -
set–Set the current value and return the reset token.
Attributes:
Source code in src/liblaf/conf/_var.py
get
¶
load_env
¶
Reload the current value from the configured environment variable.
Source code in src/liblaf/conf/_var.py
override
¶
override(value: T) -> Generator[None]
Temporarily set a value for the duration of a context manager.
Parameters:
-
value(T) –Temporary value to expose inside the context.
Yields:
-
Generator[None]–Nonewhile the override is active.