jinjitsu
Minimal Jinja CLI for rendering templates from files or stdin with variables, config files, and Python modules. Fast, predictable way to render Jinja2 templates from the terminal.
Installation • Quick Start • CLI • Examples • Troubleshooting • Contributing • License
Quick Start
-
Hello world:
$ echo "Hello {{ name }}" | jinjitsu --stdin -D name=World Hello World
-
Render a template with includes from a different directory
docs/README.j2.md:# Dynamically rendered README ```ts {% include 'code.ts' %} ```
examples/code.ts:export const greeting = "Hello, User";
Now, rendering it with
jinjitsuand addingexamplesas a--searchpathwill produce the following result:$ jinjitsu docs/README.j2.md -s examples/ # Dynamically rendered README ```ts export const greeting = "Hello, User"; ```Or render it directly to a file by redirecting
>the output or using the-ooption:# Like so $ jinjitsu docs/README.j2.md -s examples/ -o README.md # Or like so $ jinjitsu docs/README.j2.md -s examples/ > README.md
-
Autoescape HTML and feed template as a Heredoc (
<<EOF)$ jinjitsu --stdin -D name='<World>' --autoescape on <<EOF Hello {{ name }} EOF Hello <World>
CLI
Usage: jinjitsu [OPTIONS] [TEMPLATE]
Render a Jinja template.
Source (choose one)
TEMPLATE Path to a template file.
--stdin Read template from STDIN (heredoc/pipe).
Variables
-D, --var KEY=VALUE Set a string variable (repeatable). Highest precedence.
--vars FILE Load variables from FILE [json|yaml|toml|ini] (repeatable).
-m, --module PATH Import Python file; its top‑level names become variables (repeatable).
Template search paths
--searchpath PATH Add a directory for includes/imports (repeatable).
Jinja behavior
--autoescape {smart,on,off} Default smart (by extension).
--autoescape-exts EXT,EXT Override smart extensions (default: html,htm,xml,xhtml).
--undefined {strict,default,debug,chain} Missing variables policy (default: strict).
--trim-blocks, --lstrip-blocks, --keep-trailing-newline
--newline-sequence {\n,\r\n,\r}
Output and diagnostics
-o, --output PATH Write output to PATH (use - for stdout).
--traceback Show full Python tracebacks on errors.
Installation
Run using uv without needing to install anything:
uvx jinjitsu
Or install as a system-wide tool:
# Using uv
uv tool install jinjitsu
# Using pipx
pipx install jinjitsu
Of course, you can also install as a package in the current virtual environment:
./.venv/bin/activate && pip install jinjitsu
Examples
Let's consider an example with dynamically generated release notes. We want to render a template that uses a function from a Python module, includes a reusable sub-template, and uses variables from a vars file and the CLI.
# First, let's create a Python module with a two functions and a private variable
$ cat > extras.py <<'PY'
from datetime import datetime
def greet(name: str) -> str:
"""Greet someone."""
return f"Greetings, {name}!"
def today() -> str:
"""Return today's date."""
return datetime.now().strftime('%Y-%m-%d')
_private_variable = "visible"
PY
# Then, we create a vars.json file with additional variables
$ echo '{ "changelog": "CHANGELOG.md" }' > vars.json
# Let's also create a reusable template in the "shared" directory
$ mkdir -p shared && echo 'Release type: {{ type }}' > shared/type.j2
# Finally, let's define the main template
$ cat > deployment_summary.j2 <<'J2'
Deployment summary {{ today() }}
* {% include 'type.j2' %}
* Changelog: {{ changelog }}
* Status: {{ _private_variable }}
J2
# Now, render the template with jinjitsu
$ jinjitsu deployment_summary.j2 \
--module extras.py \
--vars vars.json \
-D type=PROD \
--searchpath shared
Expected output:
Deployment summary 2023-04-10
* Release type: PROD
* Changelog: CHANGELOG.md
* Status: visible
Configuration & Notes
- Variable precedence:
- Later sources override earlier ones
-D/--varflags override--varsfiles, which override-m/--modules.
- Include/import search order:
- template’s directory;
- for
--stdin, falls back to the current working directory; - always adds all provided
-s/--searchpathdirectories to the above.
Troubleshooting
-
“YAML file not supported” or similar
- Install a YAML parser:
pip install PyYAML(orruamel.yaml).
- Install a YAML parser:
-
“Unsupported vars file type …”
- Only
.json,.yaml/.yml,.toml,.iniare supported.
- Only
-
“Template not found” or includes fail
- Check the path and add directories with
--searchpath PATH.
- Check the path and add directories with
-
“UndefinedError” or missing variables
- Default mode is strict. Provide values via
-D/--var,--vars FILE, or--module; or use--undefined default.
- Default mode is strict. Provide values via
-
Newline/whitespace looks wrong
- Try
--trim-blocks,--lstrip-blocks, and set--newline-sequence. Use--keep-trailing-newlineto preserve a single trailing newline.
- Try
-
I need a Python traceback
- Add
--tracebackfor full tracebacks on errors.
- Add
Contributing
Pull requests and issues are welcome.
License
Apache 2.0. See LICENSE.
Metadata
Release files for jinjitsu 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| jinjitsu-0.1.1.tar.gz | 11.5 kB | Without provenance | Details for jinjitsu-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| jinjitsu-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for jinjitsu-0.1.1-py3-none-any.whl |
Total release size: 24.6 kB
Release files / jinjitsu-0.1.1.tar.gz
| Download URL | jinjitsu-0.1.1.tar.gz |
|---|---|
| Size | 11.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
78f420b35390239146bf6e248f284e2ef6c9f4530a86ac827b0937efa4ff7f3f
|
|
BLAKE2b-256 checksum How to use checksums |
808bc115ab487245778c4d08e427e2d3ec1dfe1a6bcf989c36f926846c5b8e9d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.8.22
|
Release files / jinjitsu-0.1.1-py3-none-any.whl
| Download URL | jinjitsu-0.1.1-py3-none-any.whl |
|---|---|
| Size | 13.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3206ac6affb04c84ee99fb7523701a083ae93c0d435e54cc53c4cb9b8582adfb
|
|
BLAKE2b-256 checksum How to use checksums |
0a9c6d5be70e40fe00e9bbe2c2f1988375ec9c595ab44509b62bc9b7c365f197
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.8.22
|
Security for jinjitsu 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.