Skip to main content

Another Config lib for python, basically load config/yaml/toml/... files and add some features like relative import and templating.

Project description

yaconfiglib

PyPI version Python versions License: MIT Docs CI

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(), and dumps().
  • 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 Python dataclasses directly from loaded configuration files.
  • Dot-Notation Access: Configuration results are wrapped in a DotAccessibleDict supporting deep traversal like config.database.credentials.user and toggleable dig options.
  • 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. #!json header).
  • YAML Includes: Out-of-the-box support for !include and !load YAML constructors to seamlessly and recursively import child configurations or commands.
  • Advanced Templating: Interleave configurations with Jinja2. Generate configuration blocks dynamically, auto-inject os.environ via env.VAR_NAME, or reference previously declared values using Jinja's {% do %} statements.
  • Path Agnostic: Compatible with both standard pathlib.Path and 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\"}))"'

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

See AGENTS.md (and the language-specific directive it points to, e.g. PYTHON.md) for environment setup, dependency install, and test commands.

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 (see AGENTS.md's "Repository Structure" section and the language-specific CI/CD notes for the concrete jobs).

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

yaconfiglib-0.9.3.tar.gz (28.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

yaconfiglib-0.9.3-py3-none-any.whl (27.5 kB view details)

Uploaded Python 3

File details

Details for the file yaconfiglib-0.9.3.tar.gz.

File metadata

  • Download URL: yaconfiglib-0.9.3.tar.gz
  • Upload date:
  • Size: 28.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for yaconfiglib-0.9.3.tar.gz
Algorithm Hash digest
SHA256 626964c8857935e20f1717e16f7ee6162b34f3b6a1c11ce8c35ab481760c5f5d
MD5 226939d7603f3d46a76f282674c5f915
BLAKE2b-256 e1ec365780d2827988859cbd65869443234db48a4c9d1e301cb93f08e1a40637

See more details on using hashes here.

Provenance

The following attestation bundles were made for yaconfiglib-0.9.3.tar.gz:

Publisher: release.yml on jose-pr/yaconfiglib

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file yaconfiglib-0.9.3-py3-none-any.whl.

File metadata

  • Download URL: yaconfiglib-0.9.3-py3-none-any.whl
  • Upload date:
  • Size: 27.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for yaconfiglib-0.9.3-py3-none-any.whl
Algorithm Hash digest
SHA256 377697874bc63305c420524e6384615fafb2465bb9cc95eb0b114d6dbee86dcf
MD5 e9b6ea1f9a851cb4fdbd452ceef9d181
BLAKE2b-256 b06575478872f97b041db0c37bf550a369783246562cb82adbd810e8273ab44f

See more details on using hashes here.

Provenance

The following attestation bundles were made for yaconfiglib-0.9.3-py3-none-any.whl:

Publisher: release.yml on jose-pr/yaconfiglib

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page