Skip to main content

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:

  1. Modular configuration through file inclusion
  2. Support for various file sources (local, remote, cloud storage)
  3. Environment variable interpolation
  4. Jinja2 templating support
  5. 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:

  1. For single values using the !raw tag:
# This value will not be interpolated
config_string: !raw "{{ VARIABLE }}"
  1. 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:

  1. File Loading: The main YAML file is loaded, and all !include directives are resolved recursively.
  2. YAML Parsing: The complete YAML structure (including included files) is parsed into a Python dictionary.
  3. Jinja2 Templating: The parsed YAML is rendered as a Jinja2 template, allowing for dynamic content generation.
    • During this stage, content marked with !raw or inside {% raw %}{% endraw %} blocks will not be interpolated.
  4. Environment Variable Interpolation: Environment variables are interpolated into the configuration.
  5. 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 }}"

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

modyaml-0.0.post28.tar.gz (11.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

modyaml-0.0.post28-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

Details for the file modyaml-0.0.post28.tar.gz.

File metadata

  • Download URL: modyaml-0.0.post28.tar.gz
  • Upload date:
  • Size: 11.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for modyaml-0.0.post28.tar.gz
Algorithm Hash digest
SHA256 579b2e6b5ae038b9e9b5145c45cff27bcd3ef25559b162bf6c2588fcffb837a4
MD5 df33730c39cfefe52280aaa168dcf3c9
BLAKE2b-256 838e6480a59877c83b34f9002c516b3f18edf9b199f30bc6f44faf6d73a251ea

See more details on using hashes here.

Provenance

The following attestation bundles were made for modyaml-0.0.post28.tar.gz:

Publisher: python-publish.yml on AlexMKX/modyaml

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file modyaml-0.0.post28-py3-none-any.whl.

File metadata

  • Download URL: modyaml-0.0.post28-py3-none-any.whl
  • Upload date:
  • Size: 7.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for modyaml-0.0.post28-py3-none-any.whl
Algorithm Hash digest
SHA256 fcd7cc0d72559f4c8cc4acac81b0207ef2b7b9e2ed448241b97bd41227dad388
MD5 097581fcaf63be616a2b0784d688eda5
BLAKE2b-256 771aed170b1c874a809aadacc12860feaa738fa79e67354b481dab3c2d133b76

See more details on using hashes here.

Provenance

The following attestation bundles were made for modyaml-0.0.post28-py3-none-any.whl:

Publisher: python-publish.yml on AlexMKX/modyaml

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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