Protein: a macro language for data composition and templating
Project description
Protein, a Data Composer and Templating Tool
Problem
Nowadays, a lot of software is piloted by data files, typically JSON or YAML files.
JSON and YAML are excellent file formats but they are essentially static. Sometimes, the content of a 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 with the same boiler-plate data can be time-consuming and error-prone.
Introducing YAMLpp
What if we had a way to generate a new data file (or more than one) according to a single set of source data?
The purpose of Protein is to help programmers prepare data files in various formats, (JSON, YAML, but also HTML, etc.) with rules that produce your data 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:
.local:
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 .local, .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 protein-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
🔧 A Sample of Protein Constructs
| Construct | Purpose | Minimal Example |
|---|---|---|
.local |
Define local variables valid for siblings and descendants. | .local: 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. | .local: 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" |
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
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 protein_lang-0.5.2.tar.gz.
File metadata
- Download URL: protein_lang-0.5.2.tar.gz
- Upload date:
- Size: 65.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4bd4fda5c3bb475fd5c837eee52e07e817bf7b16b9debfc363b4837bf4db5a0c
|
|
| MD5 |
1e2099f657dfc174e6ae1a1515533aee
|
|
| BLAKE2b-256 |
647c67aac346b0b4b6ef0f87790fa5465e631fbf36888f51597d6e8e01d1b4e5
|
File details
Details for the file protein_lang-0.5.2-py3-none-any.whl.
File metadata
- Download URL: protein_lang-0.5.2-py3-none-any.whl
- Upload date:
- Size: 75.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5029547d07d1572900c8ea59d14c8afa8c3088d8704b2b81830278ffc4e6db1e
|
|
| MD5 |
3b5be0d57af9576f7aba7d5e5b58109f
|
|
| BLAKE2b-256 |
e7ecdfa88d04fb23475ae78baed2d013391846d115380226c37154dc00f2de2d
|