Skip to main content

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.

PyPI - Python Version PyPI - Status PyPI - License

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 jinjitsu and adding examples as a --searchpath will 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 -o option:

    # 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 &lt;World&gt;
    

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/--var flags override --vars files, 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/--searchpath directories to the above.

Troubleshooting

  • “YAML file not supported” or similar

    • Install a YAML parser: pip install PyYAML (or ruamel.yaml).
  • “Unsupported vars file type …”

    • Only .json, .yaml/.yml, .toml, .ini are supported.
  • “Template not found” or includes fail

    • Check the path and add directories with --searchpath PATH.
  • “UndefinedError” or missing variables

    • Default mode is strict. Provide values via -D/--var, --vars FILE, or --module; or use --undefined default.
  • Newline/whitespace looks wrong

    • Try --trim-blocks, --lstrip-blocks, and set --newline-sequence. Use --keep-trailing-newline to preserve a single trailing newline.
  • I need a Python traceback

    • Add --traceback for full tracebacks on errors.

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)

Source distribution for jinjitsu 0.1.1
File Size Uploaded
jinjitsu-0.1.1.tar.gz 11.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for jinjitsu 0.1.1
File Interpreter ABI Platform
jinjitsu-0.1.1-py3-none-any.whl Python 3 none any Details

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

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page