Type safety and editor intelligence for Jinja2 templates.
Project description
TypedJinja
Python companion package for the VSCode extension that adds type safety and LSP features to Jinja2 templates by generating Python stub files (.pyi).
Installation
pip install typedjinja
Usage
1. Annotate Types
In your Jinja2 template, declare variables using an @types block:
{# @types
from mytypes import User
user: User
#}
Hello, {{ user.name }}!
Generate a stub:
python -m typedjinja path/to/sample_template.html
This creates sample_template.pyi alongside your template.
2. Annotate Macros
Use an @typedmacro block to define macro signatures:
{# @typedmacro
one_macro(name: str = "world")
This macro greets a user.
#}
{% macro one_macro(name = "world") %}
Hello, {{ name }}!
{% endmacro %}
Stub output includes:
def one_macro(name: str = "world"): ...
Examples
Browse samples/templates:
sample_template.htmlfor@typesanother_template.htmlfor@typedmacro
License
MIT
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 typedjinja-0.1.3.tar.gz.
File metadata
- Download URL: typedjinja-0.1.3.tar.gz
- Upload date:
- Size: 9.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.22
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
733ffbb3835ab0da2cf62a3439b7f2473ddfe9a6290bf6bbf23da69c83b900c8
|
|
| MD5 |
f878d0f2a0c52f806eda873311f0eb36
|
|
| BLAKE2b-256 |
b339c8f837430f4e211eed27c197b1ef8019b25c6fb439ea57812f72ba4af91f
|
File details
Details for the file typedjinja-0.1.3-py3-none-any.whl.
File metadata
- Download URL: typedjinja-0.1.3-py3-none-any.whl
- Upload date:
- Size: 9.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.22
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2073f8bb73440b1aaeb63e4244f74fb24afdcf71b0621cbccb4c9cfa8554913a
|
|
| MD5 |
e8f05a85280345953b84c69fca6ad115
|
|
| BLAKE2b-256 |
4135f79f4047e01e8314e8aa3b96dd8bf800c5f6902dda30b559f1d74d6f2114
|