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 Use Coyaml?

Coyaml simplifies common YAML management tasks:

  • Dot Notation Access: Easily access nested configuration (config.section.option).
  • Pydantic Integration: Automatic validation and type safety for your settings.
  • Environment Variables: Direct integration of OS or .env variables, with defaults.
  • External File & YAML Inclusion: Embed file contents and additional YAML files seamlessly.
  • Reusable Nodes: Reference and reuse YAML configuration sections dynamically.

Quick Start

Install Coyaml:

pip install coyaml

Load and resolve YAML configurations:

from coyaml import YConfig

config = (
    YConfig()
    .add_yaml_source('config.yaml')
    .add_env_source()
)
config.resolve_templates() # is necessary only when using template placeholders within the YAML configuration.

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(config.debug.db.url)

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

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

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

# Modify configuration dynamically
config.index = 10

# Validate configuration via Pydantic
from pydantic import BaseModel

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

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

Coyaml resolves references automatically, ensuring your configurations remain consistent and adaptable.

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: coyaml-0.9.3.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.9.3.tar.gz
Algorithm Hash digest
SHA256 c1b07669220bca20edade76ca53aeb73714f2e9aa6380c04d329aaa43a4ac675
MD5 3e74c757eb44a0c7b9883bd13a3760c9
BLAKE2b-256 0acae8763232b40bc889e73fbef72cb5c71ac86c265c3c39ec657ba277243aa8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: coyaml-0.9.3-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.9.3-py3-none-any.whl
Algorithm Hash digest
SHA256 fef0d9c396e4d5c7e27e6d2d9737bb619e1191142821dae203f15310c8fbba6d
MD5 24ff072a772d32761107d56a5bae2d7a
BLAKE2b-256 f260446dce17a9142647802da290e2c48b1b2a215e1aa98a8d76452c37b2090f

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