MiniJinja is a powerful but minimal dependency template engine for Rust compatible with Jinja/Jinja2
See the code[!IMPORTANT] The
mainbranch contains development for MiniJinja 3. MiniJinja 2 maintenance and releases continue on theminijinja-2branch. Pull requests for changes that apply to MiniJinja 2 should target that branch. Changes are merged forward fromminijinja-2intomain, never in the other direction.
MiniJinja is a powerful but minimal dependency template engine which is based on the syntax and behavior of the Jinja2 template engine for Python.
It's implemented in Rust and Go and is also available via WASM for JavaScript, as a Python extension module, and as a command line utility.
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. The default build of MiniJinja is entirely
free of dependencies, though some users might want to enable the serde
dependency to enable the optional serde support.
$ cargo tree
minimal v0.1.0 (examples/minimal)
└── minijinja v3.0.0-alpha.1 (minijinja)
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:
serde compatible typesExample 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());
}
If you are stuck with MiniJinja, have suggestions or need help, you can use the
GitHub Discussions.
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:
AI Chat Templating:
Data and Processing:
HTML Generation:
Code Generation:
SQL Generation:
These are related template engines for Rust:
If you like the project and find it useful you can become a sponsor.
This codebase mostly predates LLM based code generation but some recent features have been built with support of AI. For the AI contribution rules see AI Disclosure Rules.
(top 30 of 85)
Rust
64.9%
Go
30.2%
C
1.8%
Python
1.7%
MiniJinja is a powerful but minimal dependency template engine for Rust compatible with Jinja/Jinja2
See the code[!IMPORTANT] The
mainbranch contains development for MiniJinja 3. MiniJinja 2 maintenance and releases continue on theminijinja-2branch. Pull requests for changes that apply to MiniJinja 2 should target that branch. Changes are merged forward fromminijinja-2intomain, never in the other direction.
MiniJinja is a powerful but minimal dependency template engine which is based on the syntax and behavior of the Jinja2 template engine for Python.
It's implemented in Rust and Go and is also available via WASM for JavaScript, as a Python extension module, and as a command line utility.
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. The default build of MiniJinja is entirely
free of dependencies, though some users might want to enable the serde
dependency to enable the optional serde support.
$ cargo tree
minimal v0.1.0 (examples/minimal)
└── minijinja v3.0.0-alpha.1 (minijinja)
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:
serde compatible typesExample 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());
}
If you are stuck with MiniJinja, have suggestions or need help, you can use the
GitHub Discussions.
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:
AI Chat Templating:
Data and Processing:
HTML Generation:
Code Generation:
SQL Generation:
These are related template engines for Rust:
If you like the project and find it useful you can become a sponsor.
This codebase mostly predates LLM based code generation but some recent features have been built with support of AI. For the AI contribution rules see AI Disclosure Rules.
(top 30 of 85)
Rust
64.9%
Go
30.2%
C
1.8%
Python
1.7%