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
These features allow for more dynamic, reusable, and environment-aware configurations.
Syntax
ModYaml extends standard YAML syntax with the !include directive:
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
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.
- 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') }}
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:
# Dump Collected YAML after includes proocessing
export MODYAML_DEBUG_STAGE_1=1
# Dump the YAML contents after jinja2 processing (including env vars substitution)
export MODYAML_DEBUG_STAGE_2=1
# Dump the resulted dict as loaded from yaml
export MODYAML_DEBUG_STAGE_3=1
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.post11.tar.gz.
File metadata
- Download URL: modyaml-0.0.post11.tar.gz
- Upload date:
- Size: 3.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
80a812598a2a0cd6cca955d7e4262fd4eeaac05d5c6626e9dcf8c4eeafe1fb69
|
|
| MD5 |
e38b11c1918d5a96f1ff7213eca08553
|
|
| BLAKE2b-256 |
6bc5f3e098fca154184ebe3871c4db4ac13372349f837d588be8aefd5bc803ef
|
File details
Details for the file modyaml-0.0.post11-py3-none-any.whl.
File metadata
- Download URL: modyaml-0.0.post11-py3-none-any.whl
- Upload date:
- Size: 2.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
56e29a4454c59b816f005871859415d3eceb1aaecf4c7a486c56fe04374f5cf9
|
|
| MD5 |
d9a53c7b25ff463f2a777f061cd4a0d1
|
|
| BLAKE2b-256 |
7caac99ca95db236ac7b74e2157498d3de2ceccca31e95f01071d3b7f308755d
|