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.
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
- Docs: https://coyaml.readthedocs.io
- Tutorials: Basic · Templates · Injection · Merging · Registry
- Concepts: YSettings · YNode · Templates · Injection
- API: https://coyaml.readthedocs.io/en/latest/api/modules/
For detailed documentation, more examples, and a complete API reference, visit Coyaml Documentation.
License: Apache License 2.0
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file coyaml-0.11.0.tar.gz.
File metadata
- Download URL: coyaml-0.11.0.tar.gz
- Upload date:
- Size: 19.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0ce5cc0be6f0ef55149590d2fee760692b0f70eb9ff35d7ca608f92d7c66a9e1
|
|
| MD5 |
1482c6e761ab615a23ce2321e9835b63
|
|
| BLAKE2b-256 |
a1740a12b0409f02f4420c8063ce31ae1af0bec0dfe8c1b8bd3cc156f46f1756
|
File details
Details for the file coyaml-0.11.0-py3-none-any.whl.
File metadata
- Download URL: coyaml-0.11.0-py3-none-any.whl
- Upload date:
- Size: 23.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7800f39a969e1c2e9239f91d6ad7ef4f51818c0f22c7c084433d7f42fdcc5125
|
|
| MD5 |
4fd2af1eb3b79a766a3dc5e114923b07
|
|
| BLAKE2b-256 |
03ddd1c5d06951c160d838c53d5f61e72a6c816896c4e06c8c8be95b3436dca5
|