Modular Yaml for configuration management
Project description
ModYaml
ModYaml is a Python module designed for advanced YAML configuration management, offering modular, flexible, and powerful configuration capabilities.
Purpose
The primary purpose of ModYaml is to enhance YAML configurations by providing:
- Modular configuration through file inclusion
- Support for various file sources (local, remote, cloud storage)
- Environment variable interpolation
- Jinja2 templating support
- Ability to disable interpolation for specific values or blocks
These features allow for more dynamic, reusable, and environment-aware configurations.
Syntax
ModYaml extends standard YAML syntax with the following directives:
File Inclusion
key: !include path/to/another/file.yaml
The path/to/another/file.yaml can be: A local file path A URL (http, https, ftp, etc.) A cloud storage path (s3://, gs://, etc.)
ModYaml uses fsspec (Filesystem Specification) to handle file access, supporting a wide range of file systems and protocols.
database:
!include configs/database.yaml
logging:
!include https://example.com/logging-config.yaml
cloud_settings:
!include gs://my-bucket/cloud-config.yaml
Disabling Interpolation
ModYaml provides two ways to disable interpolation when needed:
- For single values using the
!rawtag:
# This value will not be interpolated
config_string: !raw "{{ VARIABLE }}"
- For blocks of text using Jinja2's
{% raw %}and{% endraw %}tags:
text_block: >
{% raw %}
This entire block will not have {{ any }} variables
{{ interpolated }} even though they use the
standard {{ SYNTAX }}.
{% endraw %}
Processing Stages
ModYaml processes your configuration in the following stages:
- File Loading: The main YAML file is loaded, and all !include directives are resolved recursively.
- YAML Parsing: The complete YAML structure (including included files) is parsed into a Python dictionary.
- Jinja2 Templating: The parsed YAML is rendered as a Jinja2 template, allowing for dynamic content generation.
- During this stage, content marked with
!rawor inside{% raw %}{% endraw %}blocks will not be interpolated.
- During this stage, content marked with
- Environment Variable Interpolation: Environment variables are interpolated into the configuration.
- Final Parsing: The resulting string is parsed again as YAML to produce the final configuration dictionary.
Using Environment Variables
Environment variables can be used in your YAML files for flexible configuration and debugging. They are accessible in the Jinja2 templating stage.
Example:
debug_mode: {{ DEBUG | default('false') }}
database_url: {{ DB_URL | default('localhost:5432') }}
# This will preserve the literal text "{{ ENV_VAR }}" without interpolation
raw_value: !raw "{{ ENV_VAR }}"
Command-line interface
ModYaml ships a small CLI for use in build pipelines. The current command
is flatten, which resolves !include directives into a single
self-contained YAML document while preserving jinja-style placeholders
({{ VAR }}) as plain strings. This is the right thing for build-time
artifact generation: the resulting file can be safely published and then
rendered at runtime by modyaml.load() inside the target environment,
where the real env vars live.
Install
modyaml exposes a console-script entry point, so it works with pipx:
# Run without installing (recommended for CI):
pipx run modyaml flatten config.yml -o config.flattened.yml
# Or install once and call directly:
pipx install modyaml
modyaml flatten config.yml -o config.flattened.yml
Plain pip install modyaml also works and gives you the same modyaml
executable on $PATH.
Usage
# Write flattened YAML to a file:
modyaml flatten config.yml -o config.flattened.yml
# Write to stdout (default when -o is omitted):
modyaml flatten config.yml > config.flattened.yml
# Or be explicit about stdout:
modyaml flatten config.yml -o -
<input> may be any path or URL that fsspec understands, the same as
!include itself (local path, s3://, gs://, http(s)://, ...).
What flatten does (and does not) do
| Directive / construct | flatten behaviour |
|---|---|
!include path/to/file.yml |
Inlined recursively at flatten time |
{{ VAR }} |
Preserved verbatim as a string |
!raw "..." |
Converted to a plain string (the marker is no longer needed because flatten never renders jinja) |
{% raw %}...{% endraw %} |
Preserved as part of the surrounding string |
For full processing (includes + jinja + env vars) use modyaml.load()
from Python, which is unchanged.
Python API
The same behaviour is available programmatically:
import modyaml
import yaml
data = modyaml.flatten('config.yml') # !include resolved, jinja kept
with open('config.flattened.yml', 'w') as f:
yaml.safe_dump(data, f, sort_keys=False, allow_unicode=True)
Debugging configs
It is possible to trigger the config flow processing debug to standard logger. In order to do this, the following environment variables can be used:
export MODYAML_LOG_LEVEL=DEBUG
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 modyaml-0.0.post29.tar.gz.
File metadata
- Download URL: modyaml-0.0.post29.tar.gz
- Upload date:
- Size: 12.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0285efa799558ff1be8545dd113e403c7f17911572f081cafd098060728f81f5
|
|
| MD5 |
af5c1dc15c440594ea2eec3b8238cf21
|
|
| BLAKE2b-256 |
60465f2408e82d5eb3ffe2ee9f5649c2c24b6158b6c3b9f4ed1cfc1a8da4fc81
|
Provenance
The following attestation bundles were made for modyaml-0.0.post29.tar.gz:
Publisher:
python-publish.yml on AlexMKX/modyaml
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
modyaml-0.0.post29.tar.gz -
Subject digest:
0285efa799558ff1be8545dd113e403c7f17911572f081cafd098060728f81f5 - Sigstore transparency entry: 1572840336
- Sigstore integration time:
-
Permalink:
AlexMKX/modyaml@37b53255ef84a7299d05ab4396b794284be4dfa7 -
Branch / Tag:
refs/heads/docs/cli-usage - Owner: https://github.com/AlexMKX
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@37b53255ef84a7299d05ab4396b794284be4dfa7 -
Trigger Event:
push
-
Statement type:
File details
Details for the file modyaml-0.0.post29-py3-none-any.whl.
File metadata
- Download URL: modyaml-0.0.post29-py3-none-any.whl
- Upload date:
- Size: 9.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a1670f7c1e46e48fa98c1719923d884fd4bd5c7bcce8e0ebdeaf945ea8c18a9a
|
|
| MD5 |
537aec6e67d1e30cf7c247f99b12172a
|
|
| BLAKE2b-256 |
2534e876ea3fd3e6d62f3233615ea815b2ab2205456abb35af9bfc74ffa29c07
|
Provenance
The following attestation bundles were made for modyaml-0.0.post29-py3-none-any.whl:
Publisher:
python-publish.yml on AlexMKX/modyaml
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
modyaml-0.0.post29-py3-none-any.whl -
Subject digest:
a1670f7c1e46e48fa98c1719923d884fd4bd5c7bcce8e0ebdeaf945ea8c18a9a - Sigstore transparency entry: 1572840355
- Sigstore integration time:
-
Permalink:
AlexMKX/modyaml@37b53255ef84a7299d05ab4396b794284be4dfa7 -
Branch / Tag:
refs/heads/docs/cli-usage - Owner: https://github.com/AlexMKX
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@37b53255ef84a7299d05ab4396b794284be4dfa7 -
Trigger Event:
push
-
Statement type: