liblaf-conf lets Python applications define typed configuration once, load it
from environment variables, and apply scoped runtime overrides with
contextvars.
✨ Features
- 🧩 Descriptor-based config models: Build config objects from
BaseConfig,Field, andgroup()instead of wiring ad hoc globals or nested dicts. - 🌱 Environment-ready defaults: Bind fields to derived or explicit
environment variable names and refresh a whole config tree with
load_env(). - 🎯 Typed helper factories: Reach for
field_bool,field_json,field_path, and the temporal helpers for one conversion path shared by environment values and direct assignments. - 🔄 Context-local overrides: Use
Var.override()orBaseConfig.override()to change values temporarily without leaking across contexts. - 🪺 Nested serialization helpers: Compose related sections and export the
active state with
to_dict()orto_namespace().
📦 Installation
uv add liblaf-conf
🚀 Quick Start
from liblaf import conf
class DatabaseConfig(conf.BaseConfig):
url: conf.Field[str] = conf.field_str(default="sqlite:///app.db")
class AppConfig(conf.BaseConfig):
debug: conf.Field[bool] = conf.field_bool(default=False)
allowed_hosts: conf.Field[list[str]] = conf.field_list_str(
factory=lambda: ["localhost"]
)
database: conf.Group[DatabaseConfig] = conf.group(DatabaseConfig)
cfg = AppConfig()
cfg.set(database={"url": "sqlite:///dev.db"})
cfg.load_env()
cfg.debug.set(True)
with cfg.override(debug=False):
assert cfg.debug.get() is False
assert cfg.to_dict() == {
"debug": True,
"allowed_hosts": ["localhost"],
"database": {"url": "sqlite:///dev.db"},
}
BaseConfig subclasses are cached singletons, so AppConfig() returns the
same config object each time while each field still stores its active value in
a ContextVar. Mutable defaults are copied when first read in each context;
use a factory when constructing the value needs more than a copy.
Semantics
load_env(), set(), and override() affect only the active contextvars
context. Child async tasks inherit values when they are created; existing tasks
and threads keep their own context. to_dict() and to_namespace() read one
active-context view and include active overrides. They allocate new container
objects but do not deep-copy mutable field values.
For a field with an environment variable, load_env() is deterministic: a
present variable is converted and installed; an absent variable clears the
current value, so the next read uses a fresh declared default or factory value.
Conversion errors always propagate. Direct set() and override() use that
same field converter, rather than bypassing validation.
⌨️ Local Development
Clone the repository and use the maintained task surfaces:
git clone https://github.com/liblaf/conf.git
cd conf
mise install
mise run lint
nox --tags test
mise run docs:serve
mise provides the primary setup, lint, and docs commands in this repository.
nox drives the Python test matrix used by CI.
🤝 Contributing
Issues and pull requests are welcome, especially when they improve the public API, typed converter helpers, or documentation examples.
🔗 Links
📝 License
Metadata
Release files for liblaf-conf 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| liblaf_conf-0.2.0.tar.gz | 12.9 kB | With provenance | Details for liblaf_conf-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| liblaf_conf-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for liblaf_conf-0.2.0-py3-none-any.whl |
Total release size: 30.3 kB
Release files / liblaf_conf-0.2.0.tar.gz
| Download URL | liblaf_conf-0.2.0.tar.gz |
|---|---|
| Size | 12.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6f87657a0756698d88172f0654bd4981108942090170439b43d0e14849035b48
|
|
BLAKE2b-256 checksum How to use checksums |
597570384e4e3cf62f182e3db8ba0136fd65069c4eedbe1fcf979948fc139052
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 6, 2026.
Transparency logRelease files / liblaf_conf-0.2.0-py3-none-any.whl
| Download URL | liblaf_conf-0.2.0-py3-none-any.whl |
|---|---|
| Size | 17.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9a789ecec9cda0c592ad832e51764a1fe25274fe69a420c5add55618e5736f1b
|
|
BLAKE2b-256 checksum How to use checksums |
c8cb03b37f13812b8a66ff5fbfa17ce27c46000787a0583c4eb034c109da6241
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 6, 2026.
Transparency logSecurity for liblaf-conf 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for liblaf_conf-0.2.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 6, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.