Typed Python configuration models with environment loading and context-local overrides.
Project description
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 when you want built-in string parsing. - 🔄 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
[!NOTE]
liblaf-confsupports Python 3.12 and newer.
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(default=["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.
⌨️ 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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file liblaf_conf-0.1.1.tar.gz.
File metadata
- Download URL: liblaf_conf-0.1.1.tar.gz
- Upload date:
- Size: 11.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9d639afbe9087d08d620b54521ed46cf58426deca2ac341c6666d38876199b35
|
|
| MD5 |
e13d6bb9038177f597e184f929578559
|
|
| BLAKE2b-256 |
8860d4ca967489dcfd5f11577c9263d4bad358ced2a514569702edf9d02fc39c
|
Provenance
The following attestation bundles were made for liblaf_conf-0.1.1.tar.gz:
Publisher:
python-release.yaml on liblaf/conf
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
liblaf_conf-0.1.1.tar.gz -
Subject digest:
9d639afbe9087d08d620b54521ed46cf58426deca2ac341c6666d38876199b35 - Sigstore transparency entry: 1241772567
- Sigstore integration time:
-
Permalink:
liblaf/conf@954c53d3ae18eacd254c4d2badfd854985638dc6 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/liblaf
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-release.yaml@954c53d3ae18eacd254c4d2badfd854985638dc6 -
Trigger Event:
push
-
Statement type:
File details
Details for the file liblaf_conf-0.1.1-py3-none-any.whl.
File metadata
- Download URL: liblaf_conf-0.1.1-py3-none-any.whl
- Upload date:
- Size: 15.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bac62566ca0ba320c53d616dae486bb509c4b280e1c5b186483da8d250cab7fd
|
|
| MD5 |
b4dba86bb781257ddda50bec6d4cf460
|
|
| BLAKE2b-256 |
19e2c996a51f96dbf4d571f810a22da3a2170c763868af15cb13c6f647fa1070
|
Provenance
The following attestation bundles were made for liblaf_conf-0.1.1-py3-none-any.whl:
Publisher:
python-release.yaml on liblaf/conf
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
liblaf_conf-0.1.1-py3-none-any.whl -
Subject digest:
bac62566ca0ba320c53d616dae486bb509c4b280e1c5b186483da8d250cab7fd - Sigstore transparency entry: 1241772621
- Sigstore integration time:
-
Permalink:
liblaf/conf@954c53d3ae18eacd254c4d2badfd854985638dc6 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/liblaf
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-release.yaml@954c53d3ae18eacd254c4d2badfd854985638dc6 -
Trigger Event:
push
-
Statement type: