pallets

jinja: Render Dynamic Templates in Python

Jinja is a fast, extensible template engine that turns templates and application data into documents. Python developers use it for HTML and other generated text, with features such as inheritance, autoescaping, async support, and sandboxing.

Stars
11.8k
Forks
1.8k
Stars, last 7 days
+0

Our take

Health score

51/100

How it is scored
Activity
20
Community
80
Issues
84
Pull requests
21

+0 stars in the last 7 days

  • Closes issues faster than 82% of the projects we track
  • More contributors than 77% of the projects we track

Overview

Jinja is a Python template engine for generating documents from reusable templates and application data. It lets developers keep presentation structure in templates while using familiar, Python-like syntax for variables, loops, and other template logic.

It suits applications that need more than basic string substitution, such as shared layouts, reusable template components, or HTML rendering with autoescaping. Templates can also be sandboxed when they come from untrusted sources, though the application must still choose and configure the appropriate environment.

Key Features

  • Inherit layouts and include other templates to reuse structure.
  • Define and import macros for reusable template components.
  • Autoescape HTML output to help prevent XSS from untrusted values.
  • Use a sandboxed environment to render untrusted templates.
  • Support asynchronous rendering and calls to async functions.
  • Add filters, tests, functions, and custom syntax through extension points.
  • Compile templates to optimized Python code, with caching or ahead-of-time compilation.
  • Report template errors with line references to aid debugging.

Use Cases

  • Web developers can render dynamic HTML pages while keeping page structure separate from application code.
  • Teams maintaining sites with shared layouts can use inheritance and includes to avoid duplicating templates.
  • Developers generating documents or other text output can use template logic and reusable macros.
  • Applications that let users supply templates can use a sandboxed environment, with careful configuration and security review.
  • Python applications using asynchronous functions can render templates with Jinja's async support.

Getting Started

Install with pip:

pip install Jinja2

See the README and official documentation for usage and configuration details.

Considerations

Jinja provides template capabilities, not a complete web application framework. Autoescaping and sandboxing are useful protections, but applications must select suitable settings and should not treat them as a substitute for security review. The project is actively maintained and uses the BSD-3-Clause license.

Found this useful?

Share it with someone who would like jinja.