Skip to main content

Yaml configuration library for python

Project description

Coyaml

Coyaml is an intuitive Python library designed to simplify YAML configuration management. It lets you split your configurations into smaller files, embed environment variables, and reuse configuration nodes—keeping your settings organized, maintainable, and scalable.

Developed with practical insights from real-world projects, Coyaml is ideal for Python developers who require flexible, powerful, and simple configuration handling.

Tests Coverage Publish PyPI PyPI - License PyPI - Downloads

Documentation: https://coyaml.readthedocs.io

Source Code: https://github.com/kuruhuru/coyaml


Why Coyaml?

Coyaml simplifies common YAML tasks and stays pragmatic:

  • Dot notation access: cfg.section.option
  • Templates that work: ${{ env:VAR }}, ${{ file:path }}, ${{ config:node }}, ${{ yaml:file }}
  • Pydantic interop: convert any node to models via .to(Model)
  • Zero‑boilerplate DI: @coyaml + Annotated[..., YResource] injects values into any function
  • Smart search: inject by parameter name, optionally constrained by glob masks (*, **)

Quick Start

Install Coyaml:

pip install coyaml

Load and resolve YAML configurations:

from coyaml import YSettings
from coyaml.sources.yaml import YamlFileSource
from coyaml.sources.env import EnvFileSource

cfg = (
    YSettings()
    .add_source(YamlFileSource('config.yaml'))
    .add_source(EnvFileSource('.env'))
)
cfg.resolve_templates()

Example YAML Configuration

debug:
  db:
    url: "postgres://user:password@localhost/dbname"
    user: ${{ env:DB_USER }}
    password: ${{ env:DB_PASSWORD:strong:/-password }}
    init_script: ${{ file:tests/config/init.sql }}
llm: "path/to/llm/config"
index: 9
stream: true
app:
  db_url: "postgresql://${{ config:debug.db.user }}:${{ config:debug.db.password }}@localhost:5432/app_db"
  extra_settings: ${{ yaml:tests/config/extra.yaml }}

Using configurations in code

# Access nested configuration
print(cfg.debug.db.url)

# Access environment variables with defaults
print(cfg.debug.db.password)

# Access embedded file content
print(cfg.debug.db.init_script)

# Access YAML-included configurations
print(cfg.app.extra_settings)

# Modify configuration dynamically
cfg.index = 10

# Validate configuration via Pydantic
from pydantic import BaseModel

class AppConfig(BaseModel):
    db_url: str
    extra_settings: dict

app_config = cfg.app.to(AppConfig)
print(app_config)

Coyaml resolves templates and references automatically, keeping configs consistent and adaptable.

Zero‑boilerplate injection

from typing import Annotated
from coyaml import YRegistry, YResource, coyaml

YRegistry.set_config(cfg)

@coyaml(mask='debug.**')
def connect(user: Annotated[str | None, YResource()] = None) -> str | None:
    return user  # found by name within the masked subtree

print(connect())

Quick links

For detailed documentation, more examples, and a complete API reference, visit Coyaml Documentation.


License: Apache License 2.0

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

coyaml-0.10.2.tar.gz (18.1 kB view details)

Uploaded Source

Built Distribution

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

coyaml-0.10.2-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

Details for the file coyaml-0.10.2.tar.gz.

File metadata

  • Download URL: coyaml-0.10.2.tar.gz
  • Upload date:
  • Size: 18.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for coyaml-0.10.2.tar.gz
Algorithm Hash digest
SHA256 5444a6a4bd4d875ed0617476817c313703ab3e9504b7833a3e88470afd38b827
MD5 a06e7b5df46801bf2590c22809b6f4e5
BLAKE2b-256 96a27ff3ba574f0067545fb00c986ce73e7ebae6a4ce8a744bff535f67967b5e

See more details on using hashes here.

File details

Details for the file coyaml-0.10.2-py3-none-any.whl.

File metadata

  • Download URL: coyaml-0.10.2-py3-none-any.whl
  • Upload date:
  • Size: 6.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for coyaml-0.10.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c6ffd8c12291ff1deae0915f5b1c1d71f710eb6b919e19b578964f8d9fc21b6b
MD5 bfafe2ee9dcf619756eb97f162a61300
BLAKE2b-256 c20235f23974df4e6db3735ca1e88d259798335c24f1facd44aabca9cda1f8d5

See more details on using hashes here.

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