Skip to main content

CfgForge

Multi-source configuration loader and merger for Python. Supports env, json, yaml, ini, 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.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for CfgForge 0.1.1
File Size Uploaded Provenance
cfgforge-0.1.1.tar.gz 5.2 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for CfgForge 0.1.1
File Interpreter ABI Platform
cfgforge-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 11.4 kB

Release files / cfgforge-0.1.1.tar.gz

Download URL cfgforge-0.1.1.tar.gz
Size 5.2 kB
Tags Source
SHA-256 checksum
How to use checksums
eee6dc4799a8f45b9b052dcdb721f604b465e4f682978d922ce4e9d62aeaf0c9
BLAKE2b-256 checksum
How to use checksums
5a376bd69e39db7bf6e6cfe8b0507364bc780f3aef1e46965b0a8031e540c935
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.1-py3-none-any.whl

Download URL cfgforge-0.1.1-py3-none-any.whl
Size 6.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6eccf0bb6d255583f67215556b5f6524196627f0a98d5b931ca7dba4deac3d73
BLAKE2b-256 checksum
How to use checksums
e49fe96f74e53ee10472d9cc742fc15b99cb714934034581e67abb92f7ac7345
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.1

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page