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.3.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.3-py3-none-any.whl (22.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: coyaml-0.10.3.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.3.tar.gz
Algorithm Hash digest
SHA256 5bb66d491c6ded7893f584afb58bb947c755d8651bf4fe576403c9a027264d5e
MD5 61c400892187621f5b4503874ebd0d5d
BLAKE2b-256 fefc373106e82129d67e62aaf53831456de661c3c5993ac851355885de1cc1b6

See more details on using hashes here.

File details

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

File metadata

  • Download URL: coyaml-0.10.3-py3-none-any.whl
  • Upload date:
  • Size: 22.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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 7e1610cf0f29ee2ec388d7190e65e2fe917614f58f213bc8e620f485721e9051
MD5 433925aa0c0053a3005ae03b4a50321d
BLAKE2b-256 494691268d7282bdb88c05dae7accffabb07f5db8eee87314f3b8e3f194dc10d

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