Skip to main content

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.html for @types
  • another_template.html for @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

typedjinja-0.1.3.tar.gz (9.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

typedjinja-0.1.3-py3-none-any.whl (9.4 kB view details)

Uploaded Python 3

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

Hashes for typedjinja-0.1.3.tar.gz
Algorithm Hash digest
SHA256 733ffbb3835ab0da2cf62a3439b7f2473ddfe9a6290bf6bbf23da69c83b900c8
MD5 f878d0f2a0c52f806eda873311f0eb36
BLAKE2b-256 b339c8f837430f4e211eed27c197b1ef8019b25c6fb439ea57812f72ba4af91f

See more details on using hashes here.

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

Hashes for typedjinja-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 2073f8bb73440b1aaeb63e4244f74fb24afdcf71b0621cbccb4c9cfa8554913a
MD5 e8f05a85280345953b84c69fca6ad115
BLAKE2b-256 4135f79f4047e01e8314e8aa3b96dd8bf800c5f6902dda30b559f1d74d6f2114

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page