Jinja is a fast, expressive, and extensible Python template engine that renders data into final documents like HTML using Python-like placeholders.
- 3.1.6
- Published at
- Mar 5, 2025
- 11,796
- Stars
- 83,220
- Download
- Synced at
- 8d ago
Latest release
3.1.6Mar 5, 2025, 08:05 PMDownloads slow? Switch the source anytime above
README
Project Overview
Jinja is a fast, expressive, and extensible Python templating engine. Templates use special placeholders with Python-like syntax, and data is passed in to render the final document. It is widely used for web pages and general text generation, with autoescaping, sandboxing, template inheritance, and i18n built in. Templates are compiled to optimized Python code just-in-time and cached for excellent performance.
| Item | Value |
|---|---|
| Language | Python |
| Type | Template engine |
| License | BSD-3-Clause |
| Async | AsyncIO support |
Application logic stays in Python while template designers keep full freedom.
Key Features
- Template inheritance: reuse layouts with extends and block, plus includes
- Macros: define and import macros within templates for reusable fragments
- Autoescaping: HTML templates escape untrusted input automatically to prevent XSS
- Sandboxing: a sandboxed environment renders untrusted templates safely
- Async support: AsyncIO support for generating templates and calling async functions
- Internationalization: I18N support with Babel
- JIT compilation: templates compile to optimized Python code and get cached
- Extensible: filters, tests, functions, and even syntax are customizable
- Debuggable: exceptions point to the correct template line
Target Audience
- Flask and Python web developers
- Backend engineers generating HTML emails and reports
- Static site and documentation tool builders
- Developers needing code-generation templates
Quick Start
- Install:
pip install jinja2 - Load and render a template from code
from jinja2 import Template
tpl = Template('Hello, {{ name }}!')
print(tpl.render(name='Jinja'))- In web apps, use inheritance and blocks across template files
{% extends 'base.html' %}
{% block content %}
<ul>
{% for user in users %}
<li><a href='{{ user.url }}'>{{ user.username }}</a></li>
{% endfor %}
</ul>
{% endblock %}Core Advantages
- Great performance: just-in-time compilation and caching keep rendering cheap
- Secure defaults: autoescaping and sandboxing lower injection risks
- Expressive: control structures, filters, and macros out of the box
- Wide adoption: the template engine behind Flask, Pelican, Ansible, and more
System Requirements
| Item | Requirement |
|---|---|
| Language | Python 3 |
| OS | Linux, macOS, Windows |
Notes
- Manual construction escapes nothing: rendering via the
Templateclass does not autoescape, use an autoescape-enabled Environment for web output - Keep logic out of templates: put complex business logic in Python and let templates focus on display
Release history
Sort