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

Uploaded Python 3

File details

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

File metadata

  • Download URL: coyaml-0.9.4.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.4.tar.gz
Algorithm Hash digest
SHA256 973c878459377b0e8ec736c316d80ac4b3ed8bdf94582195da25f1e955662c65
MD5 ef7db0ca65483a8cede26f86a5746b11
BLAKE2b-256 568486ad8b6d43dd10686a67a8246e13c56f2d892dffd6b1dffc054a9eb80236

See more details on using hashes here.

File details

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

File metadata

  • Download URL: coyaml-0.9.4-py3-none-any.whl
  • Upload date:
  • Size: 22.6 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.4-py3-none-any.whl
Algorithm Hash digest
SHA256 382527723d6c76fc589cf464d345f58bddee4b943072667be0f1a454f06dbb6a
MD5 5a00d785a42c127177b1ff04a22cb8a6
BLAKE2b-256 82f3f8f81297de37b19eebaabc5f8f4042aa78c5c57e2baddeb6717e4743ba83

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