YAML File Preprocessor (YAMLpp)
Problem
YAML is an excellent file format but it is essentially static. Sometimes, the content of a YAML file must change according to circumstances (typically when the environment changes or when you have different configuratons for test or production, etc.).
Manually maintaining different versions can be time-consuming and error-prone.
Introducing YAMLpp
What if we had a way to generate a new YAML file (or more than one) according to a single pattern?
The purpose of YAML Preprocessor (YAMLpp) is to help programmers prepare YAML files from a template, with rules that produce the YAML tree according to source data. It extends standard YAML with constructs for variable declaration, conditionals, iteration, functions, importing and exporting YAML files, and importing Python modules.
YAMLpp is a macro language, since it manipulates the YAML tree on which it resides.
Here is a simple example:
YAMLpp:
.frame:
name: "Alice"
message: "Hello, {{ name }}!"
Output:
message: "Hello, Alice!"
General principles
The language is composed of constructs, which are denoted keys starting with a dot (.), such
as .frame, .if, .switch, etc.
The YAMLpp preprocessor uses these constructs modify the tree, and the constructs disappear.
The result is pure YAML.
YAMLpp obeys the rules of YAML syntax:
- It provides declarative constructs without breaking YAML syntax.
- It allows modular, reusable, and expressive constructs that create YAML files
🚀 Quickstart
Installation
pip install yamlpp-lang
Command-line usage
yamlpp input.yaml -o output.yaml
input.yaml→ your YAML file with YAMLpp directivesoutput.yaml→ the fully expanded YAML after preprocessing
To consult the help:
yamlpp --help
Python API
from yamlpp import Interpreter
FILENAME = 'my_file.yaml'
i = Interpreter()
# the initial (source) tree:
initial_tree = i.load(FILENAME)
# the destination (target) tree (pure YAML):
tree = i.render()
# print the resulting YAML
print(i.yaml)
🔧 YAMLpp Constructs (Quick Reference)
| Construct | Purpose | Minimal Example |
|---|---|---|
.frame |
Define local variables valid for siblings and descendants. | .frame: name: "Alice" message: "Hello {{ name }}" |
.do |
Execute a sequence or map of instructions. | .do: - step: "Init" - step: "Run" |
.foreach |
Iterate over values with a loop body. | .frame: items: [1,2] .foreach: .values: [x, items] .do: - val: "{{ x }}" |
.switch |
Branch to a different node based on an expression and cases. | .switch: .expr: "{{ color }}" .cases: red: {msg: "Stop"} .default: {msg: "?"} |
.if |
Conditional node creation with then and else. |
.if: .cond: "{{ x>0 }}" .then: {res: "Pos"} .else: {res: "Neg"} |
.load |
Insert and preprocess another YAMLpp (or YAML) file. | .import_module: "other.yaml" |
.function |
Define a reusable block with arguments and a body. | .function: .name: "greet" .args: ["n"] .do: - msg: "Hi {{ n }}" |
.call |
Invoke a previously defined function with arguments. | .call: .name: "greet" .args: ["Bob"] |
.import_module |
Import a Python module exposing functions, filters, and variables. | .module: "module.py" |
.export |
Export a portion of the tree into an external file. | .export: .filename: "out.yaml" .do: - foo: "bar" |
Metadata
Release files for yamlpp-lang 0.3.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| yamlpp_lang-0.3.3.tar.gz | 53.0 kB | Without provenance | Details for yamlpp_lang-0.3.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| yamlpp_lang-0.3.3-py3-none-any.whl | Python 3 | none | any | Details for yamlpp_lang-0.3.3-py3-none-any.whl |
Total release size: 115.2 kB
Release files / yamlpp_lang-0.3.3.tar.gz
| Download URL | yamlpp_lang-0.3.3.tar.gz |
|---|---|
| Size | 53.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
bbbfa3ec19ec3dc93a9d6740ad6a9e51acf6212704b84d65d6707e36e8dbb3f8
|
|
BLAKE2b-256 checksum How to use checksums |
ba74b6ffc6a61130a3b85ea16145d47818b07e0f9b801f11ded21c9e08e2c33e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / yamlpp_lang-0.3.3-py3-none-any.whl
| Download URL | yamlpp_lang-0.3.3-py3-none-any.whl |
|---|---|
| Size | 62.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
04bd6b31071f3c5e28eac8d711e9000eb3d0abe49dbbd0e40b930cfe3632c7fc
|
|
BLAKE2b-256 checksum How to use checksums |
dea7b0c100c02ecff524f2c88b7da8f476776d242b4caa6ee47cb8972ee8a66c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Security for yamlpp-lang 0.3.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.