# Python template engine libraries

Python template engine libraries render HTML or text by filling a template with data. An engine either compiles templates that embed Python expressions or uses a restricted syntax such as Mustache or Liquid that keeps logic in the data. These libraries let web servers, code generators, and email tools build output from shared templates.

## Popularity

| Library | Monthly downloads | Stars | Last release | License |
| --- | --- | --- | --- | --- |
| [Jinja](#jinjatwo) | 721.2M | Not on GitHub | Mar 2025 | BSD-3-Clause |
| [Mako](#mako-library) | 237.1M | Not on GitHub | Sep 2026 | MIT |
| [Tornado](#tornado-templates) | 123.2M | 22.2K | Nov 2026 | Apache-2.0 |
| [Django](#django) | 52.2M | Not on GitHub | Nov 2026 | BSD-3-Clause |
| [Chevron](#chevron) | 14.0M | Not on GitHub | Jan 2021 | MIT |
| [bottle](#bottle) | 9.6M | Not on GitHub | Jun 2025 | MIT |
| [Pystache](#pystache) | 3.6M | Not on GitHub | Mar 2025 | MIT |
| [Python Liquid](#python-liquid) | 2.2M | Not on GitHub | Nov 2026 | MIT |

Downloads: PyPI, last thirty days. Stars and releases: GitHub. Amber: no release in over a year.

[Jinja](#jinjatwo) has the most monthly downloads in this comparison, at 721.2M.

## Capabilities

| Library | Native async rendering | Autoescape enabled by default |
| --- | --- | --- |
| [Jinja](#jinjatwo) | Yes | No |
| [Mako](#mako-library) | No | No |
| [Tornado](#tornado-templates) | No | Yes |
| [Django](#django) | No | Yes |
| [Chevron](#chevron) | No | Yes |
| [bottle](#bottle) | No | Yes |
| [Pystache](#pystache) | No | Yes |
| [Python Liquid](#python-liquid) | Yes | No |

## Libraries

### Jinja

[GitHub](https://github.com/pallets/jinja) · [PyPI](https://pypi.org/project/jinja2) · [Docs](https://jinja.palletsprojects.com/en/stable/api/)

Renders templates with an expressive syntax.

- Downloads / mo: 721.2M
- Last release: 3.1.6
- License: BSD-3-Clause
- Capabilities: [From the Jinja docs](https://jinja.palletsprojects.com/en/stable/api/)

```sh
python3.13 -m pip install jinja2==3.1.6
```

**Quickstart**

```python
from jinja2 import Environment

environment = Environment()
template = environment.from_string("Hello, {{ name }}!")
print(template.render(name="World"))
```

From [api.html](https://jinja.palletsprojects.com/en/stable/api/) · [Find projects using Jinja →](https://dashboard.exa.ai/playground/search?q=jinja2%20GitHub%20projects)

### Mako

[GitHub](https://github.com/sqlalchemy/mako) · [PyPI](https://pypi.org/project/mako) · [Docs](https://docs.makotemplates.org/en/latest/usage.html)

Provides a templating language.

- Downloads / mo: 237.1M
- Last release: 1.4.3
- License: MIT
- Capabilities: [From the Mako docs](https://docs.makotemplates.org/en/latest/usage.html)

```sh
python3.13 -m pip install mako==1.4.3
```

**sqlalchemy/alembic** (4.5K stars)

[sqlalchemy/alembic](https://github.com/sqlalchemy/alembic) 

```python
def template_to_file(
    template_file: str | os.PathLike[str],
    dest: str | os.PathLike[str],
    output_encoding: str,
    *,
    append_with_newlines: bool = False,
    **kw: Any,
) -> None:
    template = Template(filename=_preserving_path_as_str(template_file))
    try:
        output = template.render_unicode(**kw).encode(output_encoding)
    except:
        with tempfile.NamedTemporaryFile(suffix=".txt", delete=False) as ntf:
            ntf.write(
                exceptions.text_error_template()
                .render_unicode()
                .encode(output_encoding)
            )
            fname = ntf.name
        raise CommandError(
            "Template rendering failed; see %s for a "
            "template-oriented traceback." % fname
        )
    else:
        with open(dest, "ab" if append_with_newlines else "wb") as f:
            if append_with_newlines:
                f.write("\n\n".encode(output_encoding))
            f.write(output)
```

[alembic/util/pyfiles.py](https://github.com/sqlalchemy/alembic/blob/1bcba93ea0473c69b48e704f842ca96e9e5348f5/alembic/util/pyfiles.py) · [More projects using Mako →](https://dashboard.exa.ai/playground/search?q=mako%20GitHub%20projects)

**Quickstart**

```python
from mako.template import Template

template = Template("hello world!")
print(template.render())
```

From [usage.html](https://docs.makotemplates.org/en/latest/usage.html)

### Tornado

[GitHub](https://github.com/tornadoweb/tornado) · [PyPI](https://pypi.org/project/tornado) · [Docs](https://www.tornadoweb.org/en/stable/template.html)

Compiles templates to Python and generates output through a standalone module or web handlers.

- Downloads / mo: 123.2M
- Stars: 22.2K
- Last release: 6.6.1
- License: Apache-2.0
- Capabilities: [From the Tornado docs](https://www.tornadoweb.org/en/stable/template.html)

**Strengths**

- **Uses familiar Python expressions.** Use Python expressions directly in conditions, loops, and substitutions.
- **Escapes expression output.** Automatic escaping applies to expression output, rather than other directives.

**Watch out for**

- **Templates execute server-side Python.** Template authors can execute arbitrary code in the server process.
- **Rendered output is bytes.** Decode generated bytes when an integration expects text.

```sh
python3.13 -m pip install tornado==6.6.1
```

**Quickstart**

```python
from tornado.template import Template

template = Template("Hello {{ name }}!")
print(template.generate(name="World"))
```

From [template.html](https://www.tornadoweb.org/en/stable/template.html) · [Find projects using Tornado →](https://dashboard.exa.ai/playground/search?q=Python%20applications%20using%20tornado%20for%20reusable%20layouts%2C%20generated%20migration%20files%2C%20web%20views%20and%20cached%20document%20rendering&filters=%7B%22type%22%3A%20%22auto%22%2C%20%22numResults%22%3A%2010%2C%20%22includeDomains%22%3A%20%5B%22github.com%22%5D%7D)

### Django

[GitHub](https://github.com/django/django) · [PyPI](https://pypi.org/project/django) · [Docs](https://docs.djangoproject.com/en/6.1/ref/templates/api/)

Provides a high-level Python web framework.

- Downloads / mo: 52.2M
- Last release: 6.1.3
- License: BSD-3-Clause
- Capabilities: [From the Django docs](https://docs.djangoproject.com/en/6.1/ref/templates/api/)

```sh
python3.13 -m pip install django==6.1.3
```

**wagtail/wagtail** (20.7K stars)

[wagtail/wagtail](https://github.com/wagtail/wagtail) 

```python
def render_html(self, parent_context: MutableMapping[str, Any] = None) -> str:
    if parent_context is None:
        parent_context = Context()
    context_data = self.get_context_data(parent_context)
    if context_data is None:
        raise TypeError("Expected a dict from get_context_data, got None")

    template = get_template(self.template_name)
    return template.render(context_data)
```

[wagtail/admin/ui/components.py](https://github.com/wagtail/wagtail/blob/14b9b12ee4b689eaebf735edebd8828ea17d829a/wagtail/admin/ui/components.py) · [More projects using Django →](https://dashboard.exa.ai/playground/search?q=django%20GitHub%20projects)

**Quickstart**

```python
from django.template import Context, Engine

engine = Engine()
template = engine.from_string("Hello {{ name }}!")
print(template.render(Context({"name": "World"})))
```

From [index.html](https://docs.djangoproject.com/en/6.1/ref/templates/api/)

### Chevron

[GitHub](https://github.com/noahmorrison/chevron) · [PyPI](https://pypi.org/project/chevron) · [Docs](https://pypi.org/pypi/chevron/0.14.0/json)

Renders Mustache templates.

- Downloads / mo: 14.0M
- Last release: 0.14.0
- License: MIT
- Capabilities: [From the Chevron docs](https://pypi.org/pypi/chevron/0.14.0/json)

```sh
python3.13 -m pip install chevron==0.14.0
```

**microsoft/TinyTroupe** (7.7K stars)

[microsoft/TinyTroupe](https://github.com/microsoft/TinyTroupe) 

```python
def compose_initial_LLM_messages_with_templates(
    system_template_name: str,
    user_template_name: str = None,
    base_module_folder: str = None,
    rendering_configs: dict = {},
) -> list:
    """
    Composes the initial messages for the LLM model call, under the assumption that it always involves
    a system (overall task description) and an optional user message (specific task description).
    These messages are composed using the specified templates and rendering configurations.
    """

    # ../ to go to the base library folder, because that's the most natural reference point for the user
    if base_module_folder is None:
        sub_folder = "../prompts/"
    else:
        sub_folder = f"../{base_module_folder}/prompts/"

    base_template_folder = os.path.join(os.path.dirname(__file__), sub_folder)

    system_prompt_template_path = os.path.join(
        base_template_folder, f"{system_template_name}"
    )
    user_prompt_template_path = os.path.join(
        base_template_folder, f"{user_template_name}"
    )

    messages = []

    messages.append(
        {
            "role": "system",
            "content": chevron.render(
                open(
                    system_prompt_template_path, "r", encoding="utf-8", errors="replace"
                ).read(),
                rendering_configs,
            ),
        }
    )

    # optionally add a user message
    if user_template_name is not None:
        messages.append(
            {
                "role": "user",
                "content": chevron.render(
                    open(
                        user_prompt_template_path,
                        "r",
                        encoding="utf-8",
                        errors="replace",
                    ).read(),
                    rendering_configs,
                ),
            }
        )
    return messages
```

[tinytroupe/utils/llm.py](https://github.com/microsoft/TinyTroupe/blob/7ce8be378a37ee73f9745d6781452712318afa04/tinytroupe/utils/llm.py) · [More projects using Chevron →](https://dashboard.exa.ai/playground/search?q=chevron%20GitHub%20projects)

**Quickstart**

```python
import chevron

print(chevron.render("Hello, {{ mustache }}!", {"mustache": "World"}))
```

From [README.md](https://pypi.org/pypi/chevron/0.14.0/json)

### bottle

[GitHub](https://github.com/bottlepy/bottle) · [PyPI](https://pypi.org/project/bottle) · [Docs](https://bottlepy.org/docs/0.13/stpl.html)

Runs small web applications on WSGI.

- Downloads / mo: 9.6M
- Last release: 0.13.4
- License: MIT
- Capabilities: [From the bottle docs](https://bottlepy.org/docs/0.13/stpl.html)

```sh
python3.13 -m pip install bottle==0.13.4
```

**microsoft/aerial_wildlife_detection** (250 stars)

[microsoft/aerial_wildlife_detection](https://github.com/microsoft/aerial_wildlife_detection) 

```python
def _initBottle(self):

    @self.app.route('/version')
    def aide_version():
        return AIDE_VERSION


    @self.app.route('/favicon.ico')
    def favicon():
        return static_file('favicon.ico', root='modules/StaticFiles/static/img')

    with open(os.path.abspath(os.path.join('modules/StaticFiles/static/templates/about.html')), 'r', encoding='utf-8') as f:
        self.aboutPage = SimpleTemplate(f.read())

    with open(os.path.abspath(os.path.join('modules/StaticFiles/static/templates/privacy.html')), 'r', encoding='utf-8') as f:
        self.privacyPage = SimpleTemplate(f.read())

    @self.app.route('/about')
    @self.app.route('/<project>/about')
    def about(project=None):
        return self.aboutPage.render(version=AIDE_VERSION)


    @self.app.route('/privacy')
    @self.app.route('/<project>/privacy')
    def privacy(project=None):
        return self.privacyPage.render(version=AIDE_VERSION)


    @self.app.get('/getBackdrops')
    def get_backdrops():
        try:
            return {'info': json.load(open('modules/StaticFiles/static/img/backdrops/backdrops.json', 'r'))}
        except:
            abort(500)


    @self.app.route('/static/<module>/<filename:re:.*>')
    def send_static(module, filename):
        return static_file(filename, self.MODULE_ROUTINGS[module])

    #TODO: can be removed
    @self.app.route('/<project>/static/<module>/<filename:re:.*>')
    def send_static_proj(project, module, filename):
        return send_static(module, filename)
```

[modules/StaticFiles/app.py](https://github.com/microsoft/aerial_wildlife_detection/blob/e9c47993ce293fb234264ac94da158e9fce0d0fc/modules/StaticFiles/app.py) · [More projects using bottle →](https://dashboard.exa.ai/playground/search?q=bottle%20GitHub%20projects)

**Quickstart**

```python
from bottle import SimpleTemplate

template = SimpleTemplate("Hello {{name}}!")
print(template.render(name="World"))
```

From [stpl.html](https://bottlepy.org/docs/0.13/stpl.html)

### Pystache

[GitHub](https://github.com/PennyDreadfulMTG/pystache) · [PyPI](https://pypi.org/project/pystache) · [Docs](https://api.github.com/repos/PennyDreadfulMTG/pystache/contents/README.rst?ref=v0.6.8)

Renders Mustache templates in Python.

- Downloads / mo: 3.6M
- Last release: 0.6.8
- License: MIT
- Capabilities: [From the Pystache docs](https://api.github.com/repos/PennyDreadfulMTG/pystache/contents/README.rst?ref=v0.6.8)

```sh
python3.13 -m pip install pystache==0.6.8
```

**getredash/redash** (28.9K stars)

[getredash/redash](https://github.com/getredash/redash) 

```python
def mustache_render_escape(template, context=None, **kwargs):
    renderer = pystache.Renderer()
    return renderer.render(template, context, **kwargs)
```

[redash/utils/__init__.py](https://github.com/getredash/redash/blob/f561a53dc55eeb3f20615be951560dc78bb23f4c/redash/utils/__init__.py) · [More projects using Pystache →](https://dashboard.exa.ai/playground/search?q=pystache%20GitHub%20projects)

**Quickstart**

```python
import pystache

print(pystache.render("Hi {{person}}!", {"person": "Mom"}))
```

From [README.rst](https://api.github.com/repos/PennyDreadfulMTG/pystache/contents/README.rst?ref=v0.6.8)

### Python Liquid

[GitHub](https://github.com/jg-rp/liquid) · [PyPI](https://pypi.org/project/python-liquid) · [Docs](https://jg-rp.github.io/liquid/)

Renders Liquid templates in Python.

- Downloads / mo: 2.2M
- Last release: 3.0.0
- License: MIT
- Capabilities: [From the Python Liquid docs](https://jg-rp.github.io/liquid/)

```sh
python3.13 -m pip install python-liquid==3.0.0
```

**Quickstart**

```python
import liquid

print(liquid.render("Hello, {{ you }}!", {"you": "World"}))
```

From [index.html](https://jg-rp.github.io/liquid/) · [Find projects using Python Liquid →](https://dashboard.exa.ai/playground/search?q=python-liquid%20GitHub%20projects)

## FAQ

### Which Python template engine should I use?

[Jinja](#jinjatwo) suits most applications, with template inheritance, macros, async rendering, and a sandbox. [Mako](#mako-library) suits templates that embed Python expressions and code. [Chevron](#chevron) and [Pystache](#pystache) suit logic-less Mustache templates.

### What is Jinja?

[Jinja](#jinjatwo) is a standalone template engine with loaders, macros, inheritance, optional async rendering, and a separate sandbox. HTML autoescaping must be configured explicitly.

### Can a Jinja sandbox replace resource limits?

No. Resource limits are still needed to contain excessive CPU or memory usage.

### What is Mako?

[Mako](#mako-library) is a templating language with embedded Python expressions and inheritance. Alembic uses it to generate migration files.

### Does an asynchronous web handler make its renderer asynchronous?

No. Tornado template generation returns bytes synchronously, even inside an async handler. Jinja supplies a separate asynchronous render method.

## How this page was built

Data checked Nov 20, 2026.

Reproduce it with the Exa API:

```json
{
  "endpoint": "/search",
  "body": {
    "query": "Best Python template engines Jinja Mako Chameleon Tornado code examples",
    "numResults": 5
  }
}
```

Docs: https://exa.ai/docs/reference/search
