Skip to content

Jinja2 background

Mozilla Nunjucks is heavily inspired by Jinja2—filters, inheritance, macro, for/if, and much of the expression syntax feel the same across Python, Nunjucks, and Runjucks. Runjucks keeps that language shape but implements lexing, parsing, and rendering in Rust, exposed to Node.js via N-API.

Why Runjucks if you already like Jinja2-style templates

Section titled “Why Runjucks if you already like Jinja2-style templates”
  • Familiar surface — Block inheritance (extends / block), includes, imports, macros, filters, and tests match what Jinja / Nunjucks users expect; see Template language.
  • Performance — CPU-heavy templates (large loops, many interpolations) benefit from a native core and parse caching; see Performance for practical tuning and a published vs Nunjucks snapshot versioned with the npm package.
  • Slices without a compat shim — Nunjucks often needs installJinjaCompat() for Pythonic slice syntax in expressions; Runjucks accepts array slices without that extra API. Other Jinja-only shims from Nunjucks are not mirrored as one switch—see Limitations.
TopicJinja2 (Python)Runjucks (Node)
RuntimePython objects and methods in contextJSON-shaped context over the FFI boundary; use addGlobal for callable injection
TypesRich Python types (date, custom classes, …)Values the engine sees are serde_json-style (null, bool, number, string, array, object)
Exact semanticsReference implementationAligned with Nunjucks 3.x behavior and tests; small divergences are documented in Limitations
Async / streamingTemplate and environment features varySynchronous render on the JS thread; no async tags

If you port Django / Flask / FastAPI templates to Node, expect to reshape context (plain objects, ISO date strings, explicit helpers) rather than passing arbitrary Python instances through.

The official Nunjucks templating reference remains a useful cross-check for syntax; the API page documents the full Nunjucks product (browser, precompile, async). Runjucks documents the Node sync subset in JavaScript API and Limitations.