Jinja2
Fast and expressive template engine for Python with powerful flexibility.
3. Used by agents' projects
Dependency in 134 public GitHub projects set up for AI coding agents that we scanned (2.1%).
4. Agent access
Agent skills for this library in the skills catalog; community skills are written by others, read them before you install.
From the package registry and GitHub, checked daily. Tap a verdict to see its source.How we checkedReport an error
What Jinja2 does
Jinja is the Pallets project's Python templating engine: templates use near-Python syntax and are compiled to Python code, and the README says a sandboxed environment can safely render untrusted templates.
Jinja2 popularity
Gid Score measures public popularity and activity, not quality. How the Gid Score is calculated
How Jinja2 is used
- Jinja2 is a dependency in 134 of the 6,258 public GitHub projects set up for AI coding agents that we scanned (8.3% of the 1,623 Python ones), #4 of 149 in markdown, editors and content.
- Counting the projects our scan samples by dependency (Solana 3,067, Ethereum and EVM 1,774, 3D and games 3,130, agent frameworks and SDKs 13,750), it appears in 1,516; those are left out of every share on this page.
- The most used alternative in our scan is Mako (13 projects).
- Projects that use it most often also use Pydantic (66.4%), Uvicorn (59.7%), FastAPI (59.0%).
- It is more common in projects set up for OpenClaw (4.2%) than for Gemini CLI (1.1%).
By coding agent
Often used with
Jinja2 in practice
Strengths
The README says templates are compiled to optimized Python code. This can happen just-in-time with caching, or ahead-of-time.
The README says a sandboxed environment "can safely render untrusted templates."
In the README's example, a page uses <code>{% extends "base.html" %}</code> and fills named blocks such as <code>title</code> and <code>content</code>. The README also says you can define macros and import them within templates.
The README says exceptions "point to the correct line in templates to make debugging easier."
Watch out for
The README says HTML templates "can use autoescaping to prevent XSS from untrusted user input." The docs FAQ has an entry titled "Why is HTML escaping not the default?" The answer to that entry is not in the pages reviewed here.
The maintainers describe 3.1.6 as a security release. Its listed change is that the <code>|attr</code> filter "does not bypass the environment's attribute lookup, allowing the sandbox to apply its checks." The notes link a GitHub security advisory and say the release "should not result in breaking changes compared to the latest feature release."
The README states the philosophy that application logic belongs in Python "if possible." It adds that Jinja "shouldn't make the template designer's job difficult by restricting functionality too much." The docs FAQ also asks "Isn’t it a bad idea to put logic in templates?"
A child template that extends a base layout
{% extends "base.html" %}
{% block title %}Members{% endblock %}
{% block content %}
<ul>
{% for user in users %}
<li><a href="{{ user.url }}">{{ user.username }}</a></li>
{% endfor %}
</ul>
{% endblock %}More about Jinja2
Funding
- GitHub Sponsors: https://github.com/pallets
- Own page: https://palletsprojects.com/donate
- Tidelift: https://tidelift.com/funding/github/pypi/Flask
- thanks.dev: https://thanks.dev/u/gh/pallets
- 31 GitHub sponsors
Packages around it
- pydantic: Data validation
- requests: HTTP client
- python-dotenv: .env config loading
- uvicorn: ASGI server
- fastapi: Web API framework
- pyyaml: YAML parsing
More in Markdown, editors and content
Alternatives
Jinja2 This page
High-performance Python templating engine with flexible syntax for generating HTML, emails and other text.
Get started
Install it.
pip install jinja2Rules for your agent
## Jinja2
- The latest release in the sources is 3.1.6, which the maintainers call a security release.
- Editor's recommendation, not from the docs: prefer a version that includes the 3.1.6 change to the `|attr` filter if you use the sandbox.
- For HTML templates that show untrusted user input, the README says they "can use autoescaping to prevent XSS". Read the docs' Autoescaping section and the FAQ entry "Why is HTML escaping not the default?" before relying on it.
- The README says the sandboxed environment "can safely render untrusted templates". Editor's recommendation: use it for templates written by users, and read the docs' Sandbox "Security Considerations" section.
- Structure pages with `{% extends %}` and `{% block %}`, as in the README example. Macros can be defined in templates and imported.
- Follow the README's philosophy: put application logic in Python "if possible", and pass the results to the template as data.