Type checker for your Jinja2 templates
Project description
Typja
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.0
hooks:
- id: typja-check
# With args
# args: ["--strict", "--fix"]
Documentation
- Configuration Guide - Detailed configuration options
- Syntax Guide - Template syntax and type annotations
Contributing
See CONTRIBUTING.md for development instructions.
License
See LICENSE for details.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file typja-0.1.1.tar.gz.
File metadata
- Download URL: typja-0.1.1.tar.gz
- Upload date:
- Size: 27.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b18dba93a8d7e0a66bd191935fe468bf39a1376ff00ffc044b0c17c3d68076e9
|
|
| MD5 |
6fa7c333bb53e986ec1cb53a86f4d0ef
|
|
| BLAKE2b-256 |
d52ab3dbfcd8519561a9fa5efd34c56510880afb8cea388602e8bbb1bab6a273
|
Provenance
The following attestation bundles were made for typja-0.1.1.tar.gz:
Publisher:
ci.yml on Daniel-Brai/Typja
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
typja-0.1.1.tar.gz -
Subject digest:
b18dba93a8d7e0a66bd191935fe468bf39a1376ff00ffc044b0c17c3d68076e9 - Sigstore transparency entry: 952652879
- Sigstore integration time:
-
Permalink:
Daniel-Brai/Typja@6a9a94e5a81146cab94f0ab564a52142f5903710 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Daniel-Brai
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@6a9a94e5a81146cab94f0ab564a52142f5903710 -
Trigger Event:
push
-
Statement type:
File details
Details for the file typja-0.1.1-py3-none-any.whl.
File metadata
- Download URL: typja-0.1.1-py3-none-any.whl
- Upload date:
- Size: 36.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ccaa24acce5e372f547e0fdbca06768142fd4904d070442f50775bae2888d9f6
|
|
| MD5 |
5f3ac603d45221467cd8b719ec4e04f3
|
|
| BLAKE2b-256 |
0c85ec3db1aea72f0cc096129c0c068704543195624c783c941b73acd116df1f
|
Provenance
The following attestation bundles were made for typja-0.1.1-py3-none-any.whl:
Publisher:
ci.yml on Daniel-Brai/Typja
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
typja-0.1.1-py3-none-any.whl -
Subject digest:
ccaa24acce5e372f547e0fdbca06768142fd4904d070442f50775bae2888d9f6 - Sigstore transparency entry: 952652885
- Sigstore integration time:
-
Permalink:
Daniel-Brai/Typja@6a9a94e5a81146cab94f0ab564a52142f5903710 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Daniel-Brai
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@6a9a94e5a81146cab94f0ab564a52142f5903710 -
Trigger Event:
push
-
Statement type: