Skip to main content

Typja

Python Version Build and Test Typja codecov License: MIT

An experimental tool to check Jinja templates for type errors using Python's type hints. It parses Jinja templates, extracts variable usage, and checks them against provided type information.

Features

  • Type Checking for Jinja2 Templates: Validate that variables in your Jinja2 templates match their declared types
  • Python Type Hints Integration: Leverage your existing Python type annotations to catch template errors early
  • Pre-commit Integration: Built-in pre-commit hook for automated checking
  • Flexible Configuration: Customize checking behavior with typja.toml
  • Rich Error Reports: Detailed error messages with code snippets and suggestions
  • Watch Mode: Monitor templates for changes and run checks automatically

Quick Start

Installation

pip install typja

Basic Usage

# Check all templates in current directory
typja check

# Run in watch mode
typja watch

# Initialize a new typja.toml configuration
typja init

Configuration

Create a typja.toml file in your project root with typja init or manually:

[project]
root = "."
paths = ["./models/**/*.py"]
fail_on_warning = false

[environment]
template_dirs = ["./templates"]
include_patterns = ["*.html", "*.jinja", "*.jinja2"]

[linting]
strict = false
prefer_pep604_unions = true
validate_imports = true
validate_variables = true

[errors]
verbosity = "normal"
show_snippets = true
show_hints = true
color = "auto"

Type Annotations in Templates

Use special Jinja2 comments to declare variable types:

{# typja:var user: User #}
{# typja:var items: list[str] #}
{# typja:var count: int #}

<h1>{{ user.name }}</h1>
<ul>
  {% for item in items %}
    <li>{{ item }}</li>
  {% endfor %}
</ul>

Examples

See the examples/fastapi/ directory for a complete FastAPI application with Jinja2 template type checking.

Pre-commit Integration

Add to your .pre-commit-config.yaml:

repos:
  - repo: https://github.com/Daniel-Brai/Typja
    rev: v0.1.3
    hooks:
      - id: typja-check
        # With args
        # args: ["--strict", "--fix"]

Documentation

Contributing

See CONTRIBUTING.md for development instructions.

License

See LICENSE for details.

Metadata

Release files for typja 0.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for typja 0.1.3
File Size Uploaded
typja-0.1.3.tar.gz 29.9 kB Details

Built distribution (wheel)

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

Total release size: 68.6 kB

Release files / typja-0.1.3.tar.gz

Download URL typja-0.1.3.tar.gz
Size 29.9 kB
Tags Source
SHA-256 checksum
How to use checksums
b52418ac167f215e57b8d9d602d03c79453bca880a09e0def95a61eb8c198022
BLAKE2b-256 checksum
How to use checksums
b83cb4eb449166b99d1891b4e4f6b64764078d1781886ec0d132eb8bbf89efde
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Feb 15, 2026.

Transparency log

Release files / typja-0.1.3-py3-none-any.whl

Download URL typja-0.1.3-py3-none-any.whl
Size 38.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d330c1bd8a3feb9018b67cf4eb95ddb4be884ddae9e1ed92617de96a5d1cf3e4
BLAKE2b-256 checksum
How to use checksums
094bd8fd4e914b32118e4172011b5253929cc8f1f4765a96dbeaf60c83dfc045
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Feb 15, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.3 This release

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

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