# Jinja2 — card for AI agents

Fast and expressive template engine for Python with powerful flexibility.

Category: Markdown, editors and content · PyPI package `jinja2` · latest version 3.1.6 (checked 2026-11-01)
Install: `pip install jinja2`
License: BSD (permissive)

In your own product (generator, app, hosted service): **yes**. Permissive license: ship it inside your own product, closed or open source, and keep its license and copyright notice.

## Rules for AI agents (paste into AGENTS.md or CLAUDE.md)

## 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.

## What it is
- Jinja is a templating engine whose templates are compiled to Python code. The README says the Pallets organization "develops and supports Jinja." The project is BSD-3-Clause licensed. The current documentation covers the 3.1.x line, and the latest release is 3.1.6, published 2025-03-05.
- The README says a template contains "special placeholders" that allow "writing code similar to Python syntax." You then pass data to the template to render the final document. Templates are compiled to optimized Python code just-in-time and cached, or they can be compiled ahead-of-time. The README also lists template inheritance and inclusion, macros, AsyncIO support and I18N with Babel.
- The README states the philosophy that application logic belongs in Python "if possible." It also says this "shouldn't make the template designer's job difficult by restricting functionality too much." The documentation has integration pages for Flask, Django, Babel and Pylons. It also has guides for switching from Django and Mako templates.

## Caveats
- Read the escaping FAQ before rendering HTML: 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.
- 3.1.6 was a sandbox security release: The maintainers describe 3.1.6 as a security release. Its listed change is that the `|attr` 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."
- Application logic belongs in Python "if possible": 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?"

## Numbers (AgentGid data)
- Gid Score: 79.4 (#111 of all tools, 3 of 149 in its category)
- Used in 134 public projects set up for AI coding agents (2.1%)
- Downloads last week: 163,954,731 (as of 2026-11-24), +16.0% over 4 weeks
- GitHub stars: 11,829 (as of 2026-11-24)
- Last push: 2025-06-14

## Often used with
Pydantic 66.4%, Uvicorn 59.7%, FastAPI 59.0%, PyYAML 56.0%, Requests 56.0%, python-dotenv 52.2%

## Checked alternatives (same job)
- Mako: https://agentgid.com/tools/mako/agent.md

## Links
- AgentGid page: https://agentgid.com/tools/jinja2/
- Repository: https://github.com/pallets/jinja
- Source: https://github.com/pallets/jinja#readme
- Source: https://github.com/pallets/jinja
- Source: https://github.com/pallets/jinja/releases
- Source: https://jinja.palletsprojects.com

---
AgentGid's catalog is curated: every entry was checked against the maker's official pages (registry, repository, license and pricing pages) on the date shown; a license value shows the quote it stands on wherever AgentGid has one. Usage numbers come from AgentGid's own scan of public repositories set up for AI coding agents. Claims by makers are reported, not tested by AgentGid.
