Jinja2 CLI
jinja2-cli is a command-line interface for rendering Jinja2 templates. It allows users to combine data from various sources (JSON, YAML, INI, TOML, environment variables) with Jinja2 templates directly from the shell. The current version is 1.0.1, actively maintained, with a focus on stability and new input formats, while ensuring backwards compatibility since v1.0.0, except for Python 2 support.
Warnings
- breaking Python 2 support was dropped in v1.0.0. Projects upgrading from older versions (pre-1.0.0) on Python 2 will break.
- gotcha Specific input data formats (e.g., YAML, TOML, XML) require additional Python packages to be installed alongside `jinja2-cli`.
- gotcha Environment variables are not automatically passed as data to the template. You must explicitly request them.
- gotcha The Jinja2 default behavior allows accessing undefined variables without raising an error. This can mask typos or missing data.
Install
-
pip install jinja2-cli
Imports
- cli
from jinja2_cli import cli
Quickstart
echo '{"name": "World"}' > data.json
echo 'Hello, {{ name }}!' > template.j2
jinja2 template.j2 data.json
rm data.json template.j2