Zero-dependency configuration library for the molcrafts ecosystem
Project description
molcfg
molcfg is a zero-dependency Python configuration library for applications that need predictable config loading, merging, validation, interpolation, and safe in-memory mutation.
PyPI distribution name: molcrafts-molcfg
Import name: molcfg
Version 1.0.0 stabilizes the public API around four core areas:
- layered loading from dictionaries, files, environment variables, and CLI arguments
- nested configuration access with freeze, snapshot, rollback, and change callbacks
- schema validation with recursive nested schemas, defaults, and unknown-field control
- source tracking via
Config.meta()so callers can explain where a value came from
Why molcfg
- Runtime dependency free
- Python
3.12+ - Small surface area
- Works well for services, CLIs, and internal tooling
Install
pip install molcrafts-molcfg
Optional local workflows:
pip install "molcrafts-molcfg[dev]"
pip install "molcrafts-molcfg[docs]"
pip install "molcrafts-molcfg[release]"
Quick Start
from molcfg import CliSource, ConfigLoader, DictSource, EnvSource, Range, validate
defaults = DictSource(
{
"app": {"name": "molcfg-demo"},
"db": {"host": "localhost", "port": 5432},
},
name="defaults",
)
env = EnvSource(prefix="APP", name="env")
cli = CliSource(["--db.port=6432", "--app.debug=true"], name="cli")
cfg = ConfigLoader([defaults, env, cli]).load()
class DbSchema:
host: str
port: int
__constraints__ = {"port": [Range(1, 65535)]}
validated_db = validate(
cfg["db"].to_dict(),
DbSchema,
allow_extra=False,
apply_defaults=True,
)
assert cfg["db.port"] == 6432
assert cfg.meta("db.port") == {
"source": "cli",
"history": ("defaults", "cli"),
}
assert validated_db == {"host": "localhost", "port": 6432}
Feature Overview
Sources
DictSourceJsonFileSourceTomlFileSourceEnvSourceCliSource
EnvSource and CliSource coerce values by default:
"true"/"false"->bool"5432"->int"3.14"->float"null"/"none"->None- JSON-looking values like
["a", "b"]-> parsed Python objects
Pass coerce=False to keep raw strings.
Config Container
Config supports:
- attribute access:
cfg.db.host - dotted access:
cfg["db.host"] - freezing:
cfg.freeze() - rollback:
cfg.snapshot()andcfg.rollback() - serialization:
cfg.to_dict()andcfg.to_json() - metadata lookup:
cfg.meta("db.host")
Validation
validate() supports:
- primitive types
Literallist[T]dict[K, V]- nested class-based schemas
- optional fields
- defaults via
apply_defaults=True - extra field rejection via
allow_extra=False - built-in constraints:
Range,Length,Pattern,OneOf
Merging
Strategies:
MergeStrategy.DEEP_MERGEMergeStrategy.OVERRIDEMergeStrategy.APPEND
All merge paths return isolated data structures and do not share nested mutable state with the inputs.
Documentation
This repository includes a Zensical documentation site in docs/.
Common commands:
pip install ".[docs]"
zensical serve
zensical build
Deployment is expected to happen from Cloudflare Pages rather than GitHub Actions.
Development
pip install ".[dev]"
pytest -q
See CONTRIBUTING.md for contribution workflow and RELEASING.md for the 1.x release process.
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
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 molcrafts_molcfg-1.0.0.tar.gz.
File metadata
- Download URL: molcrafts_molcfg-1.0.0.tar.gz
- Upload date:
- Size: 25.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fc55d89979102a4e5e0b7130aee91e0c4f231c2f34336795080b3d207b03a555
|
|
| MD5 |
561f969038f433ccc0af9a7bf71d4617
|
|
| BLAKE2b-256 |
3494897866457e6df7d47af0af87419d061f49073bf89c3906cd8495f479c91b
|
Provenance
The following attestation bundles were made for molcrafts_molcfg-1.0.0.tar.gz:
Publisher:
release.yml on MolCrafts/molcfg
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
molcrafts_molcfg-1.0.0.tar.gz -
Subject digest:
fc55d89979102a4e5e0b7130aee91e0c4f231c2f34336795080b3d207b03a555 - Sigstore transparency entry: 1280214059
- Sigstore integration time:
-
Permalink:
MolCrafts/molcfg@8c8a08d4b6170026b93642b1ea75557c1e10881e -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/MolCrafts
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@8c8a08d4b6170026b93642b1ea75557c1e10881e -
Trigger Event:
push
-
Statement type:
File details
Details for the file molcrafts_molcfg-1.0.0-py3-none-any.whl.
File metadata
- Download URL: molcrafts_molcfg-1.0.0-py3-none-any.whl
- Upload date:
- Size: 15.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
096959909fff3d433906e3a15a7bbc22b08382b0e817c149323dd8c78aa1d017
|
|
| MD5 |
b31e96bbba004b21842a7da88b7d4c13
|
|
| BLAKE2b-256 |
6b5d9331e83978dfefbf9dc23d94bef2c3d195de19560c46bd91783b1352ee50
|
Provenance
The following attestation bundles were made for molcrafts_molcfg-1.0.0-py3-none-any.whl:
Publisher:
release.yml on MolCrafts/molcfg
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
molcrafts_molcfg-1.0.0-py3-none-any.whl -
Subject digest:
096959909fff3d433906e3a15a7bbc22b08382b0e817c149323dd8c78aa1d017 - Sigstore transparency entry: 1280214061
- Sigstore integration time:
-
Permalink:
MolCrafts/molcfg@8c8a08d4b6170026b93642b1ea75557c1e10881e -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/MolCrafts
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@8c8a08d4b6170026b93642b1ea75557c1e10881e -
Trigger Event:
push
-
Statement type: