{"id":5641,"library":"j2cli","title":"j2cli: Jinja2 Command-Line Tool","description":"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.","status":"maintenance","version":"0.3.10","language":"en","source_language":"en","source_url":"https://github.com/kolypto/j2cli","tags":["cli","templating","jinja2","automation","shell","configuration"],"install":[{"cmd":"pip install j2cli","lang":"bash","label":"Base installation"},{"cmd":"pip install j2cli[yaml]","lang":"bash","label":"With YAML support"}],"dependencies":[{"reason":"Core templating engine","package":"Jinja2","optional":false},{"reason":"Required for YAML data source support","package":"PyYAML","optional":true},{"reason":"Alternative JSON parser (optional)","package":"simplejson","optional":true}],"imports":[],"quickstart":{"code":"# Create a Jinja2 template file\ncat <<EOF > config.j2\nserver {\n  listen 80;\n  server_name {{ app.hostname }};\n  root {{ app.webroot }};\n  index index.htm;\n}\nEOF\n\n# Create a JSON data file\ncat <<EOF > data.json\n{\n  \"app\": {\n    \"hostname\": \"localhost\",\n    \"webroot\": \"/var/www/myproject\"\n  }\n}\nEOF\n\n# Render the template using j2cli\nj2 -f json config.j2 data.json\n\n# Expected output:\n# server {\n#   listen 80;\n#   server_name localhost;\n#   root /var/www/myproject;\n#   index index.htm;\n# }","lang":"bash","description":"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."},"warnings":[{"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.","message":"j2cli 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+.","severity":"breaking","affected_versions":"0.3.10 (and potentially 0.3.12b*) on Python 3.12+"},{"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`).","message":"The `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.","severity":"deprecated","affected_versions":"0.3.10 and earlier"},{"fix":"Install with `pip install j2cli[yaml]` if you plan to use YAML files as data sources.","message":"To 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]`.","severity":"gotcha","affected_versions":"All versions"},{"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.","message":"When 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=`.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}