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 hashes)

Uploaded Source

Built Distribution

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

Uploaded Python 3

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