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.
pip install jinja2-cliVerified import paths — ran on the pinned version, not inferred.
Create a simple JSON data file and a Jinja2 template, then render the template using the `jinja2` command. The output will be 'Hello, World!'.
Upgrade to Python 3.8 or newer before upgrading jinja2-cli to v1.0.0 or later.
Install the necessary optional dependencies, e.g., `pip install jinja2-cli[yaml]` for YAML support, `pip install jinja2-cli[xml]` for XML, or `pip install 'jinja2-cli[all]'` for all supported formats.
Use the `--env-vars` flag to expose all environment variables to the template, or `--env-file <path>` to load variables from a .env file.
Use the `--strict` flag to make Jinja2 raise an error when an undefined variable is accessed, improving template robustness: `jinja2 --strict template.j2 data.json`.