Ouroboros Jinja
Expand Jinja2 templates that back-reference other values in the same document — the snake eats its own tail.
# defaults.yaml
slug: ~
domain: "{{ slug }}.nimbus.fi"
volume-name: "{{ slug }}-volume"
permanent-ip-name: "{{ domain }}"
# server.toml
name = "Prominence 2: Hasturian Era"
slug = "hasturian"
import ouroboros_jinja
config = ouroboros_jinja.load("defaults.yaml", "server.toml")
# {
# "slug": "hasturian",
# "domain": "hasturian.nimbus.fi",
# "volume-name": "hasturian-volume",
# "permanent-ip-name": "hasturian.nimbus.fi",
# "name": "Prominence 2: Hasturian Era"
# }
API
expand(*mappings)— shallow-merge mappings (later ones win) and expand every string value as a Jinja2 template.loads(*yaml_texts)— parse YAML texts, merge and expand.load(*paths)— read files (.tomlviatomllib, everything else as YAML), merge and expand.
Templates may reference any top-level key, including nested content
({{ an_object.description }}) and lists ({% for port in ports %}).
Values are expanded lazily and recursively, in dependency order.
Semantics
- Reference cycles raise
CircularReferenceErrorwith the chain spelled out:Circular reference detected: item_1 -> item_2 -> item_3 -> item_1. - Unknown variables raise
ExpansionError(Jinja2StrictUndefined). - A top-level key with a null value (
slug: ~) is a required override: referencing it before it has been overridden raisesExpansionErrorinstead of silently interpolating"None". - Only strings containing
{{or{%are touched; other values (ints, lists, …) pass through unchanged.
Testing
uv run pytest
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
ouroboros_jinja-0.1.0.tar.gz
(28.9 kB
view details)
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 ouroboros_jinja-0.1.0.tar.gz.
File metadata
- Download URL: ouroboros_jinja-0.1.0.tar.gz
- Upload date:
- Size: 28.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.12.1 {"installer":{"name":"uv","version":"0.12.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
610a7bd00c1019ac09a72d833b24b0a8856c42593de599ccf37c9311f13a737f
|
|
| MD5 |
24bb91ed3564b0c5fbd9dc73209fdd59
|
|
| BLAKE2b-256 |
326af9e7bc6b3c717c614bbae68cf76dc988863f9c07218afdb002781e7719b1
|
File details
Details for the file ouroboros_jinja-0.1.0-py3-none-any.whl.
File metadata
- Download URL: ouroboros_jinja-0.1.0-py3-none-any.whl
- Upload date:
- Size: 4.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.12.1 {"installer":{"name":"uv","version":"0.12.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c65ad9e05e4fee8a96f8c712d9820ad3664fa0c546f45b97052590fecc6febde
|
|
| MD5 |
2701417e40c91afd1a55da81fe401870
|
|
| BLAKE2b-256 |
09ce00c974a9976e21e85871959557c4c60d7a68aa09f8e298494bdf4551107a
|