Another Config lib for python, basically load config/yaml/toml/... files and add some features like relative import and templating.
Project description
yaconfiglib
yaconfiglib is a modern, extensible configuration parser library for Python. It allows you to seamlessly load, merge, and interpolate multiple configurations in a variety of formats (YAML, TOML, JSON, INI, .env), or execute scripts/commands directly to retrieve configuration objects dynamically.
Zero required runtime dependencies (except standard pathlib, with optional packages to enable extra backends).
Features
- Standard Library API Parity: Drop-in replacements for standard serialization modules using
yaconfiglib.load(),loads(),dump(), anddumps(). - Backend Registry & Plugins: Core loaders for TOML, YAML, JSON, INI, and
.env. Easily extend the library by registering custom configuration loader classes. - Model Validation (
load_as): Automatic hydration and verification of Pydantic models or standard Pythondataclassesdirectly from loaded configuration files. - Dot-Notation Access: Configuration results are wrapped in a
DotAccessibleDictsupporting deep traversal likeconfig.database.credentials.userand toggleabledigoptions. - Shell & Command Execution: Execute arbitrary commands or shell scripts dynamically (e.g.
cmd://aws...or./generate.sh) and auto-parse their outputs, with support for shebang-based format routing (e.g.#!jsonheader). - YAML Includes: Out-of-the-box support for
!includeand!loadYAML constructors to seamlessly and recursively import child configurations or commands. - Advanced Templating: Interleave configurations with Jinja2. Generate configuration blocks dynamically, auto-inject
os.environviaenv.VAR_NAME, or reference previously declared values using Jinja's{% do %}statements. - Environment Overlays: Load prefixed environment variables as flat or nested configuration, with optional scalar coercion for booleans, numbers, nulls, arrays, and objects.
- Path Agnostic: Compatible with both standard
pathlib.Pathand optionally pathlib_next for URI loading (HTTP, SFTP, etc.) exactly like standard file paths.
Installation
Install using pip:
pip install yaconfiglib
Optional dependencies:
| Extra | Adds | Needed for |
|---|---|---|
yaconfiglib[yaml] |
pyyaml |
Parsing YAML configuration files and !include tags |
yaconfiglib[toml] |
toml |
Parsing TOML configuration files |
yaconfiglib[jinja2] |
jinja2 |
Jinja2 templating, environment variables injection, and transformations |
Quick Start
1. Simple Parsing and Dot-Notation Access
import yaconfiglib
# Load a YAML file
config = yaconfiglib.load("config.yaml", interpolate=True)
# Traverse configuration like attributes
print(f"Server starting on: {config.server.host}:{config.server.port}")
2. Hydrate Model (Pydantic / Dataclasses)
from pydantic import BaseModel
import yaconfiglib
class DBConfig(BaseModel):
host: str
port: int
# Hydrate the Pydantic model directly
db_settings = yaconfiglib.load_as(DBConfig, "config.yaml", loader="yaml")
print(db_settings.host)
3. Dynamic Includes & Shell Commands
In your config.yaml:
# Recursively include other files
database: !include "db_settings.toml"
# Dynamically execute commands to retrieve parameters (e.g. secrets)
secrets: !include 'cmd+json://python -c "import json; print(json.dumps({\"token\": \"super-secret\"}))"'
4. Environment Variable Overlays
from yaconfiglib import ConfigLoader
from yaconfiglib.backends.env import EnvVarBackend
# APP_DB__PORT=5432 -> {"db": {"port": 5432}}
config = ConfigLoader().load(
loader=EnvVarBackend(prefix="APP_", nested_delimiter="__", coerce=True)
)
API Overview
| Module | Purpose |
|---|---|
yaconfiglib.loader |
Core ConfigLoader orchestrator, load(), loads(), dumps(), and DotAccessibleDict |
yaconfiglib.backends |
ConfigBackend protocol & registry |
yaconfiglib.backends.yaml |
YamlConfig parsing and include tag construction |
yaconfiglib.backends.toml |
TomlConfig parsing (using stdlib tomllib or toml package fallback) |
yaconfiglib.backends.json |
JsonConfig parsing |
yaconfiglib.backends.ini |
IniConfig parsing |
yaconfiglib.backends.dotenv |
DotenvBackend for parsing .env files |
yaconfiglib.backends.env |
EnvVarBackend for loading os.environ variables with prefix matching |
yaconfiglib.backends.command |
CommandBackend for running processes and auto-routing outputs |
yaconfiglib.backends.python_backend |
PythonBackend for in-memory python dict injection |
yaconfiglib.utils.merge |
Deep dict/list merge algorithms and custom merge methods |
yaconfiglib.utils.jinja2 |
Custom Jinja2 interpolation environments and render utilities |
Development
pip install -e ".[dev]"
pytest -q
Releasing
This project follows Semantic Versioning and keeps a
CHANGELOG.md. Pushing a tag matching v* triggers the release
workflow: test gate → build → publish → docs deploy.
Documentation site
MkDocs builds the API reference from docs/, published on every release. To preview locally:
.venv/Scripts/pip install -e ".[docs]"
.venv/Scripts/mkdocs serve
License
MIT — see LICENSE.
Project details
Release history Release notifications | RSS feed
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 yaconfiglib-0.11.0.tar.gz.
File metadata
- Download URL: yaconfiglib-0.11.0.tar.gz
- Upload date:
- Size: 60.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9a790ed2bec0c0319d1917dbcba69390af2931dd77e9f7f5f9681021ea8eae3e
|
|
| MD5 |
7a35a5ec563401374413ddfc0845536b
|
|
| BLAKE2b-256 |
15321528bd5156bfd473c04303457cc875c632e83d274be3fccadd7823d26c89
|
Provenance
The following attestation bundles were made for yaconfiglib-0.11.0.tar.gz:
Publisher:
release.yml on jose-pr/yaconfiglib
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
yaconfiglib-0.11.0.tar.gz -
Subject digest:
9a790ed2bec0c0319d1917dbcba69390af2931dd77e9f7f5f9681021ea8eae3e - Sigstore transparency entry: 2206713148
- Sigstore integration time:
-
Permalink:
jose-pr/yaconfiglib@13960090569bd03db5c0baafc8634f412fc53d90 -
Branch / Tag:
refs/tags/v0.11.0 - Owner: https://github.com/jose-pr
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@13960090569bd03db5c0baafc8634f412fc53d90 -
Trigger Event:
push
-
Statement type:
File details
Details for the file yaconfiglib-0.11.0-py3-none-any.whl.
File metadata
- Download URL: yaconfiglib-0.11.0-py3-none-any.whl
- Upload date:
- Size: 42.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9722f9bccc60e5110311383a372cb9f3cb68fc752cd1b2cf166fdef8f0eaefd6
|
|
| MD5 |
c38422376635ab9ab2b8f7c0ee05595c
|
|
| BLAKE2b-256 |
d4119b7bcb9f337ed3dad49e833a38c06200d376e4c84ebe2e5b831a4817ac95
|
Provenance
The following attestation bundles were made for yaconfiglib-0.11.0-py3-none-any.whl:
Publisher:
release.yml on jose-pr/yaconfiglib
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
yaconfiglib-0.11.0-py3-none-any.whl -
Subject digest:
9722f9bccc60e5110311383a372cb9f3cb68fc752cd1b2cf166fdef8f0eaefd6 - Sigstore transparency entry: 2206713159
- Sigstore integration time:
-
Permalink:
jose-pr/yaconfiglib@13960090569bd03db5c0baafc8634f412fc53d90 -
Branch / Tag:
refs/tags/v0.11.0 - Owner: https://github.com/jose-pr
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@13960090569bd03db5c0baafc8634f412fc53d90 -
Trigger Event:
push
-
Statement type: