Skip to content

molcfg Manual

molcfg

Load configuration from dicts, files, environment variables, and CLI arguments; merge the layers into one immutable object; validate it against a schema; and ask any value where it came from. A single runtime dependency, and every operation returns an isolated copy.

molcfg

At a glance

Layers in, one explained config out

Stack sources lowest-priority first. ConfigLoader merges them into an immutable Config, and meta() reports the winning source and the full override history for any value.

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")}

What molcfg gives you

Everything a config layer needs, nothing it doesn't

Find your page

The manual in seven chapters