Hierarchical Yaml Python Config

0.7.0 · active · verified Thu Apr 16

HiYaPyCo is a Python library (current version 0.7.0) that facilitates hierarchical overlay and merging of configuration files written in YAML. It supports multiple merge methods, including deep merge, and features variable interpolation using Jinja2. The library is actively maintained with regular releases. [1, 2, 3]

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates loading and merging two YAML documents provided as strings. It uses `hiyapyco.METHOD_MERGE` for a deep merge and enables Jinja2 interpolation to resolve variables like `{{ first }}`. The resulting merged configuration is then pretty-printed. [1, 3]

import hiyapyco
import pprint

yaml1_str = """
first: first element
second: xxx
deep:
  k1:
    - 1
    - 2
"""

yaml2_str = """
second: again {{ first }}
deep:
  k1:
    - 4
    - 6
  k2:
    - 3
    - 6
"""

# Load and merge YAML documents from strings
# METHOD_MERGE performs a deep merge.
# interpolate=True enables Jinja2 variable substitution.
conf = hiyapyco.load(
    [yaml1_str, yaml2_str],
    method=hiyapyco.METHOD_MERGE,
    interpolate=True
)

pprint.pprint(conf)

# Example of dumping the merged configuration back to YAML
# print(hiyapyco.dump(conf, default_flow_style=False))

view raw JSON →