CfgForge
Multi-source configuration loader and merger for Python.
Supports env, json, yaml, and toml — with priority-based merging,
dot-path access, and type checking.
Features
- Load multiple config sources in order; later ones override earlier ones
- Dot-path access:
config.get("db.host") - Type validation:
config.expect("db.port", int) - Required keys:
config.get("api.key", required=True) - Optional dependencies: install only what you need
- Clear error messages for missing keys, wrong types, and parse failures
Installation
pip install CfgForge
With YAML support:
pip install CfgForge[yaml]
With all optional formats:
pip install CfgForge[all]
Quick Start
from CfgForge import config
# Load sources (later overrides earlier)
config.load(".env", "config.yaml", defaults={"db.host": "localhost"})
# Read by dot-path
host = config.get("db.host") # "localhost"
port = config.get("db.port", 5432) # with default
key = config.get("api.key", required=True) # raises if missing
# Type check
port = config.expect("db.port", int)
Supported Formats
| Format | Extension | Dependency |
|---|---|---|
| env | .env |
none |
| JSON | .json |
none |
| YAML | .yaml / .yml |
pyyaml |
| TOML | .toml |
tomllib (3.11+) or tomli |
API Reference
config.load(*paths, defaults=None)
Load one or more config files. Later sources override earlier ones.
defaults has the lowest priority.
config.load(".env", "config.yaml", defaults={"db.host": "localhost"})
config.get(key, default=None, required=False)
Read a value by dot-path.
config.get("db.host") # None if missing
config.get("db.host", "localhost") # fallback value
config.get("db.host", required=True) # raises if missing
config.expect(key, type_)
Read a value and validate its type.
port = config.expect("db.port", int) # raises ConfigTypeError if not int
config.has(key)
Check whether a key exists.
if config.has("db.password"):
...
config.update(data)
Inject config manually (useful for tests or runtime overrides).
config.update({"db": {"host": "localhost"}})
config.all()
Return a shallow copy of all config data.
data = config.all()
Exception Hierarchy
CfgForgeError
├── ConfigNotFoundError
├── ConfigTypeError
└── ConfigFileError
Catch all at once:
from CfgForge import CfgForgeError
try:
config.load("config.yaml")
config.get("db.host", required=True)
except CfgForgeError as e:
print(f"Config error: {e}")
License
MIT
Metadata
Release files for CfgForge 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| cfgforge-0.1.0.tar.gz | 2.6 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| cfgforge-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 4.9 kB
Release files / cfgforge-0.1.0.tar.gz
| Download URL | cfgforge-0.1.0.tar.gz |
|---|---|
| Size | 2.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
784c6070cb9192fc4187ae4024096ca79c0c2768620ff7402c4660127b751bea
|
|
BLAKE2b-256 checksum How to use checksums |
398930dfd2245fbec461fb978c247cce0b181afdb09465ca27697218aa0f7a84
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.11.5
|
Release files / cfgforge-0.1.0-py3-none-any.whl
| Download URL | cfgforge-0.1.0-py3-none-any.whl |
|---|---|
| Size | 2.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
fdafff196526f793ff828b25e6a2c172b5648d96445b41a7f24efbbf8e2c54df
|
|
BLAKE2b-256 checksum How to use checksums |
298c97c9dcf5436cac7a99a6318594fce2bbf7d239a98f6d8ba33c2b89275da6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.11.5
|
Security for CfgForge 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.