Skip to main content

Order of the Template: A Python package for parsing Jinja templates and YAML files with environment variables.

Project description

Order of the Template (OOT)

In the sacred halls of Dev, the Order of the Template (OOT) stands as a bastion of structure and order amidst the chaos. The order, founded by the ancients, carries the mission of maintaining harmony between variables and templates, ensuring every template adheres to its rightful structure, and bringing light to the shadowy corners of Jinja and YAML.

The Order of the Template provides a noble toolkit for Python developers, aiding them in their quests to parse YAML files and Jinja templates, resolve environment variables, and validate schemas.

The Code of the Order

A Noble Quest

The Templars are trained not only in the ancient art of parsing Jinja templates but also in the mastery of environments, skillfully resolving environment variables. They are the keepers of schemas, using their wisdom to ensure that data structures adhere to their rightful schemas.

Consider a quest where a Templar must decode an ancient manuscript, a YAML file filled with Jinja templates and environment variables:

# manuscript.yaml
Templar: {{ TEMPLAR_NAME|default('Unknown Templar') }}
HallOfHonor: ${HALL_OF_HONOR:"Hall of the Wicked"}

The Templar starts his task. He replaces the TEMPLAR_NAME variable with the name of a famous Templar. He then resolves the HALL_OF_HONOR environment variable, revealing the name of the sacred hall. Once the manuscript has been decoded, he validates it, ensuring it adheres to the ancient schema:

from oot import parse_file

file_path = "manuscript.yaml"
variables = {"TEMPLAR_NAME": "Jacques de Molay"}
os.environ["HALL_OF_HONOR"] = "Hall of the Brave" # Environmental variables will be automatically substituted

# The Templar decodes the manuscript
manuscript = parse_file(file_path, context=variables)

# The manuscript is decoded:
assert manuscript == {"Templar": "Jacques de Molay", "HallOfHonor": "Hall of the Brave"}

# The Templar validates the manuscript against the ancient schema
schema_path = "schema.json"
manuscript = parse_file(file_path, context=variables, validation_schema=schema_path)

In the above example, schema.json might be a JSON schema file that defines the structure of the decoded manuscript:

{
    "type": "object",
    "properties": {
        "Templar": {"type": "string"},
        "HallOfHonor": {"type": "string"}
    }
}

Joining the Order

The Order welcomes all who seek order in their templates and harmony in their variables. To install the Order's toolkit, simple run:

pip install oot

May the Order guide you in your quests.

Closing Words

  • OOT was born out of the re-occuring necessity to parse Jinja templates and resolve environment variables across multiple projects.
  • To separate concerns, enhance productivity and spare myself the need to setup code and tests within each project, I encapsulated the functionality.
  • OOT's primary objective is to painlessly handle the resolution of environmental variables and/or templating in your YAML files.
  • I came up with the name and theme. the README is a glorious work of ChatGPT.

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

oot-0.1.0.3.tar.gz (5.2 kB view details)

Uploaded Source

Built Distribution

oot-0.1.0.3-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

Details for the file oot-0.1.0.3.tar.gz.

File metadata

  • Download URL: oot-0.1.0.3.tar.gz
  • Upload date:
  • Size: 5.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.10.6 Linux/5.15.0-1041-azure

File hashes

Hashes for oot-0.1.0.3.tar.gz
Algorithm Hash digest
SHA256 df95a54412e7562486ba21b9f24708b663aa6d6b0a44a142a61f0a646ae10a53
MD5 ea8c4281c178f31babb1b26032891f6a
BLAKE2b-256 b8bbf62055ec866e06162641e53d64f1298908d1542f2a0cccdf254631c32d44

See more details on using hashes here.

File details

Details for the file oot-0.1.0.3-py3-none-any.whl.

File metadata

  • Download URL: oot-0.1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 7.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.10.6 Linux/5.15.0-1041-azure

File hashes

Hashes for oot-0.1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 c48a655e400b0173c7b1097ab4b96c044c120818aa8e89d1d2868e77256f325d
MD5 7bc5755abcf614e96e7b17e1ea7f8c9e
BLAKE2b-256 bad14e1e116d0726641daf1f67736d44b908c058f981d7fad786c7f88e3faf11

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page