Registry / devops / j2cli
library0.3.10pypypiunverified

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 j2cli
INSTALL
IMPORT
SIG · J2CLI
J
j2cli
devopspythonv0.3.10
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

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.

# Create a Jinja2 template file cat <<EOF > config.j2 server { listen 80; server_name {{ app.hostname }}; root {{ app.webroot }}; index index.htm; } EOF # Create a JSON data file cat <<EOF > data.json { "app": { "hostname": "localhost", "webroot": "/var/www/myproject" } } EOF # Render the template using j2cli j2 -f json config.j2 data.json # Expected output: # server { # listen 80; # server_name localhost; # root /var/www/myproject; # index index.htm; # }
j2cli --version
Debug
Known issues
breakingj2cli is incompatible with Python 3.12 and newer versions due to its reliance on the removed `imp` module. This prevents `j2cli` from running on Python 3.12+.
fix
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.
affects: 0.3.10 (and potentially 0.3.12b*) on Python 3.12+
deprecatedThe `j2cli` project appears to be largely unmaintained by its original author on PyPI, with the last release being in 2019. While the project is still widely used, the lack of updates has led to critical compatibility issues with newer Python versions.
fix
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`).
affects: 0.3.10 and earlier
gotchaTo enable YAML data source parsing, `j2cli` requires the `pyyaml` dependency. This is not installed by default and must be explicitly included during installation using `pip install j2cli[yaml]`.
fix
Install with `pip install j2cli[yaml]` if you plan to use YAML files as data sources.
affects: All versions
gotchaWhen no data file is provided, `j2cli` defaults to reading environment variables (implicitly setting `--format=env`). To explicitly import environment variables into the template as a specific variable (e.g., `env`), use `--import-env VAR` (or `-e VAR`). To import all environment variables into the global scope (which can overwrite existing variables), use `--import-env=`.
fix
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.
affects: All versions
Errors
Common errors & fixes
j2cli is incompatible with Python 3.12
j2cli (version 0.3.10 and older PyPI versions) relies on the `imp` module, which was removed in Python 3.12, causing execution to fail.
fix
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`.
jinja2.exceptions.TemplateNotFound: [template_name.j2]
The `j2cli` command cannot locate the specified template file, often due to an incorrect file path or the file not existing in the expected directory.
fix
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.
j2cli yaml parsing error
YAML data parsing fails because the `pyyaml` dependency, required for YAML support, is not installed by default with `j2cli`.
fix
Install `j2cli` with the YAML extra: `pip install j2cli[yaml]`.
j2: command not found
The directory where `pip` installs executable scripts (like `j2`) is not included in your system's PATH environment variable.
fix
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.
j2cli environment variable list not looping correctly
Environment variables or other data sources are often interpreted as single strings by default, even when they contain values that should be treated as lists or dictionaries in Jinja2 templates.
fix
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.
Upgrade
Version history
0.3.10latest on PyPI · released Jun 7, 2019
Audit
Dependencies
Jinja2requiredCore templating engine
PyYAMLoptionalRequired for YAML data source support
simplejsonoptionalAlternative JSON parser (optional)
Agent activity
12 hits · last 30 days
node
10
Resources
j2cli — pip install j2cli · libregistry