Skip to main content

Descriptor-based 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, and group() 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() or BaseConfig.override() to change values temporarily without leaking across contexts.
  • 🪺 Nested serialization helpers: Compose related sections and export the active state with to_dict() or to_namespace().

📦 Installation

[!NOTE] liblaf-conf supports 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.

PR WELCOME

Contributors

🔗 Links


📝 License

Copyright © 2026 liblaf.
This project is MIT licensed.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

liblaf_conf-0.1.2.tar.gz (12.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

liblaf_conf-0.1.2-py3-none-any.whl (16.5 kB view details)

Uploaded Python 3

File details

Details for the file liblaf_conf-0.1.2.tar.gz.

File metadata

  • Download URL: liblaf_conf-0.1.2.tar.gz
  • Upload date:
  • Size: 12.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for liblaf_conf-0.1.2.tar.gz
Algorithm Hash digest
SHA256 6914b38717af82731b10c12c27bd0df66a06ed5624c4ca2541ca0c589bccab37
MD5 8f8786f91f0260d9f7bdc6af08d416de
BLAKE2b-256 876c8554064e2a0c4fb24928fd93dae15cb130f186afa6a5282e7efe106642a0

See more details on using hashes here.

Provenance

The following attestation bundles were made for liblaf_conf-0.1.2.tar.gz:

Publisher: python-release.yaml on liblaf/conf

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file liblaf_conf-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: liblaf_conf-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 16.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for liblaf_conf-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 95d04fd766c2307ddc85c39dc77cb550dc919e0f20712aedc1bd17d573ef57d2
MD5 e701777c1826abdb89871997fb92e1cc
BLAKE2b-256 76251d96d12fc79a38938b9f193b66e8d40f920492cf17c085b3d59bf3b3a4fd

See more details on using hashes here.

Provenance

The following attestation bundles were made for liblaf_conf-0.1.2-py3-none-any.whl:

Publisher: python-release.yaml on liblaf/conf

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page