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 Protein
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.
Protein 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
protein input.yaml -o output.yaml
input.yaml→ your YAML file with YAMLpp directivesoutput.yaml→ the fully expanded YAML after preprocessing
To consult the help:
protein --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" |
Metadata
Release files for protein-lang 0.6.1
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 |
|---|---|---|---|---|
| protein_lang-0.6.1.tar.gz | 66.6 kB | Without provenance | Details for protein_lang-0.6.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| protein_lang-0.6.1-py3-none-any.whl | Python 3 | none | any | Details for protein_lang-0.6.1-py3-none-any.whl |
Total release size: 146.5 kB
Release files / protein_lang-0.6.1.tar.gz
| Download URL | protein_lang-0.6.1.tar.gz |
|---|---|
| Size | 66.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6e70368fda059b01afcd7bf859dca63f7c53a96cf9b6f438897a017196d5240f
|
|
BLAKE2b-256 checksum How to use checksums |
dfba905004e33e895fb1bef9e363782cec44fbf655e15ef0c29dc3b14a62c8a9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / protein_lang-0.6.1-py3-none-any.whl
| Download URL | protein_lang-0.6.1-py3-none-any.whl |
|---|---|
| Size | 80.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2f2de383a64a7b03c43925ca5ebed5eeecd374139bde056b2b401c53340948fb
|
|
BLAKE2b-256 checksum How to use checksums |
2080838e35f1e8f568b390644cd1043f3ddc06eebf7e65072f7402a89a2498bd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Security for protein-lang 0.6.1
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.