{"id":4060,"library":"jinja2-cli","title":"Jinja2 CLI","description":"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.","status":"active","version":"1.0.1","language":"en","source_language":"en","source_url":"https://github.com/mattrobenolt/jinja2-cli","tags":["jinja2","cli","templating","automation","configuration"],"install":[{"cmd":"pip install jinja2-cli","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Core templating engine","package":"Jinja2","optional":false},{"reason":"Required for YAML input format (--format=yaml)","package":"PyYAML","optional":true},{"reason":"Required for XML input format (--format=xml)","package":"xmltodict","optional":true},{"reason":"Required for .env file input (--env-file)","package":"python-dotenv","optional":true},{"reason":"Required for TOML input format (--format=toml)","package":"pytoml","optional":true}],"imports":[{"note":"jinja2-cli is primarily a command-line tool. Direct programmatic imports of its internal `cli` module are uncommon for typical templating tasks, which are handled via the shell. This import is generally only for advanced programmatic orchestration or testing.","symbol":"cli","correct":"from jinja2_cli import cli"}],"quickstart":{"code":"echo '{\"name\": \"World\"}' > data.json\necho 'Hello, {{ name }}!' > template.j2\njinja2 template.j2 data.json\nrm data.json template.j2","lang":"bash","description":"Create a simple JSON data file and a Jinja2 template, then render the template using the `jinja2` command. The output will be 'Hello, World!'."},"warnings":[{"fix":"Upgrade to Python 3.8 or newer before upgrading jinja2-cli to v1.0.0 or later.","message":"Python 2 support was dropped in v1.0.0. Projects upgrading from older versions (pre-1.0.0) on Python 2 will break.","severity":"breaking","affected_versions":"<1.0.0"},{"fix":"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.","message":"Specific input data formats (e.g., YAML, TOML, XML) require additional Python packages to be installed alongside `jinja2-cli`.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use the `--env-vars` flag to expose all environment variables to the template, or `--env-file <path>` to load variables from a .env file.","message":"Environment variables are not automatically passed as data to the template. You must explicitly request them.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"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`.","message":"The Jinja2 default behavior allows accessing undefined variables without raising an error. This can mask typos or missing data.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}