96 releases (42 stable)

new 2.10.2 May 6, 2025
2.9.0 Mar 31, 2025
2.5.0 Nov 10, 2024
2.1.1 Jul 31, 2024
0.8.2 Nov 8, 2021

#1 in Template engine

Download history 78813/week @ 2025-01-16 85771/week @ 2025-01-23 88937/week @ 2025-01-30 104014/week @ 2025-02-06 95013/week @ 2025-02-13 115015/week @ 2025-02-20 115099/week @ 2025-02-27 126394/week @ 2025-03-06 133899/week @ 2025-03-13 115379/week @ 2025-03-20 111994/week @ 2025-03-27 118239/week @ 2025-04-03 114227/week @ 2025-04-10 130335/week @ 2025-04-17 133662/week @ 2025-04-24 115574/week @ 2025-05-01

517,681 downloads per month
Used in 255 crates (157 directly)

Apache-2.0

715KB
14K SLoC

MiniJinja: a powerful template engine for Rust with minimal dependencies

License Crates.io rustc 1.63.0 Documentation

MiniJinja is a powerful but minimal dependency template engine for Rust which is based on the syntax and behavior of the Jinja2 template engine for Python.

It's supports all serde types and only has it as a single required dependency. It supports a range of features from Jinja2 including inheritance, filters and more. The goal is that it should be possible to use some templates in Rust programs without the fear of pulling in complex dependencies for a small problem. Additionally it tries not to re-invent something but stay in line with prior art to leverage an already existing ecosystem of editor integrations.

$ cargo tree
minimal v0.1.0 (examples/minimal)
└── minijinja v2.10.2 (minijinja)
    └── serde v1.0.144

Additionally minijinja is also available as an (optionally pre-compiled) command line executable called minijinja-cli:

$ curl -sSfL https://github.com/mitsuhiko/minijinja/releases/latest/download/minijinja-cli-installer.sh | sh
$ echo "Hello {{ name }}" | minijinja-cli - -Dname=World
Hello World

You can play with MiniJinja online in the browser playground powered by a WASM build of MiniJinja.

Goals:

Example

Example Template:

{% extends "layout.html" %}
{% block body %}
  <p>Hello {{ name }}!</p>
{% endblock %}

Invoking from Rust:

use minijinja::{Environment, context};

fn main() {
    let mut env = Environment::new();
    env.add_template("hello.txt", "Hello {{ name }}!").unwrap();
    let template = env.get_template("hello.txt").unwrap();
    println!("{}", template.render(context! { name => "World" }).unwrap());
}

Getting Help

If you are stuck with MiniJinja, have suggestions or need help, you can use the GitHub Discussions.

Use Cases and Users

Here are some interesting Open Source users and use cases of MiniJinja. The examples link directly to where the engine is used so you can see how it's utilized:

Similar Projects

These are related template engines for Rust:

  • Askama: Jinja inspired, type-safe, requires template precompilation. Has significant divergence from Jinja syntax in parts.
  • Tera: Jinja inspired, dynamic, has divergences from Jinja.
  • Liquid: an implementation of Liquid templates for Rust. Liquid was inspired by Django from which Jinja took it's inspiration.
  • TinyTemplate: minimal footprint template engine with syntax that takes lose inspiration from Jinja and handlebars.

Sponsor

If you like the project and find it useful you can become a sponsor.

Dependencies

~0.1–7MB
~47K SLoC