j2cli is a command-line tool that enables Jinja2 templating directly within shell scripts, leveraging the powerful Jinja2 library. It supports various data sources, including INI, YAML, JSON files, and environment variables. The current PyPI version is 0.3.10. While still functional for many use cases, active development on PyPI appears to have slowed, with the last release in 2019, though newer versions (0.3.12b*) are seen in some Linux distributions.
pip install j2cliNo compatibility data collected yet for this library.
This example demonstrates rendering a Jinja2 template (`config.j2`) using data from a JSON file (`data.json`) via the `j2` command-line tool. The `-f json` flag specifies the input data format. The output is printed to stdout.
Consider using alternative templating CLIs like `jinjanator` for Python 3.12+, or use an older Python version (e.g., Python 3.11 or earlier) with j2cli.
For new projects or environments requiring Python 3.12+, it is recommended to evaluate actively maintained alternatives like `jinjanator` or `j2y` (which plans to rename to `j2-cli`).
Install with `pip install j2cli[yaml]` if you plan to use YAML files as data sources.
Be mindful of `--format` and `--import-env` options when working with environment variables to avoid unexpected behavior or variable overwrites. Explicitly provide a data source or `--format` when not intending to use environment variables.
Use a Python version older than 3.12 (e.g., Python 3.11 or earlier) or consider migrating to an actively maintained alternative like `jinjanator`.
Ensure the template file path is correct, consider using an absolute path, or place the template file in the current working directory from where you run the `j2` command.
Install `j2cli` with the YAML extra: `pip install j2cli[yaml]`.
Ensure your Python virtual environment is activated, or manually add the `pip` script directory (e.g., `~/.local/bin` on Linux/macOS or `Scripts` in a Windows virtual environment) to your system's PATH.
For complex data structures, use `--format json` or `--format yaml` with a data file, or pre-process environment variables into a format that `j2cli` can interpret as structured data before passing them to the template.