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.0.tar.gz (1.5 MB 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.0-py3-none-any.whl (22.5 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for coyaml-0.10.0.tar.gz
Algorithm Hash digest
SHA256 5c3cea6635bd02513cb9316712fbba91b3cef003d29342849c59236ea28275dc
MD5 dc5cd6848c48332d55a27d1b2a3245fa
BLAKE2b-256 d7716262b2fb06d8b765b2e32fecc0e3004f795eb48f69afb3f7af49dc68075a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: coyaml-0.10.0-py3-none-any.whl
  • Upload date:
  • Size: 22.5 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4f5f1d10292f90ca9189697189cecdac92e1d41c3cb50b821e498bf71c4eb3b6
MD5 f6b260348dbb8bd4113e5663f28b236a
BLAKE2b-256 525559df4912ca6f07ca616edc9fe327f55d8d8bf64d384f2c6ddeb1fba58557

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