README.md

June 1, 2026 · View on GitHub

 molcfg

Layered configuration for Python — predictable loading, merging, validation, and source tracking.

CI PyPI Python License Ruff

Documentation  ·  Quick start  ·  Ecosystem

molcfg loads configuration from dicts, files, environment variables, and CLI arguments into a single layered Config, remembering where every value came from. It adds schema validation, string-tag construction, interpolation, and thread-safe access on top.

Capabilities

ModuleCapability
configConfig container — attribute and dotted-path access, freeze, snapshot/rollback, change notification, JSON/TOML/YAML round-trip
sourceConfig sources — DictSource, JsonFileSource, TomlFileSource, YamlFileSource, EnvSource, CliSource behind a common Source interface
mergeOVERRIDE / APPEND / DEEP_MERGE strategies, ConfigLoader for layered loading, and ProfileLoader for profile-based config
validationType-and-constraint validation — Range, OneOf, Pattern, Length descriptors, Build, and the validate entry point
registryRegistry — maps string keys (e.g. "silu") to factories, resolving short and long forms into classes or instances
concurrencyThreadSafeConfig wrapper, POSIX FileLock, and the ${path} / ${env:VAR} interpolate engine
pathsproject_config_dir — resolves and creates the shared ~/.molcrafts/<name>/config/ directory
errorsException hierarchy — ConfigError, FrozenConfigError, CircularReferenceError, ValidationError

Install

pip install molcrafts-molcfg

Requires Python 3.12+. The only runtime dependency is pyyaml.

Quick start

from molcfg import CliSource, ConfigLoader, DictSource, EnvSource

cfg = ConfigLoader([
    DictSource({"db": {"host": "localhost", "port": 5432}}, name="defaults"),
    EnvSource(prefix="APP", name="env"),
    CliSource(["--db.port=6432"], name="cli"),
]).load()

assert cfg["db.port"] == 6432
assert cfg.meta("db.port") == {"source": "cli", "history": ("defaults", "cli")}

Documentation

Full documentation lives in docs/:

MolCrafts ecosystem

ProjectRole
molpyPython toolkit — the shared molecular data model & workflow layer
molrsRust core — molecular data structures & compute kernels (native + WASM)
molpackPackmol-grade molecular packing (Rust + Python)
molvisWebGL molecular visualization & editing
molexpWorkflow & experiment-management platform
molnexMolecular machine-learning framework
molqUnified job queue — local / SLURM / PBS / LSF
molcfgLayered configuration library — this repo
mollogStructured logging, stdlib-compatible
molhubMolecular dataset hub
molmcpMCP server for the ecosystem
molrecAtomistic record specification

Contributing

See CONTRIBUTING.md.

License

BSD-3-Clause — see LICENSE.


Crafted with 💚 by MolCrafts