Skip to content

DuckDB Extension

MiniJinja

Render Jinja-style templates from DuckDB SQL with MiniJinja. Pass JSON context to generate text, HTML, configuration, or SQL strings.

50,279
extension loads · last 90 days
On this page
Sample data for the examples

Each browser example starts with these sample tables; sample files are shared across examples on this page. Run this setup first when trying the examples in your own DuckDB session.

-- Fixtures for minijinja cookbook / technical-details examples.
-- Small, deterministic, idempotent (CREATE OR REPLACE).

-- "Generate HTML email per row" (cookbook) and "What you can do with one
-- query" (technical-details).
CREATE OR REPLACE TABLE users (
    email         TEXT,
    name          TEXT,
    unread_count  INTEGER
);
INSERT INTO users VALUES
    ('[email protected]', 'Alice', 3),
    ('[email protected]',   'Bob',   0),
    ('[email protected]', 'Carol', 12);

-- "Generate config files / IaC" (cookbook).
CREATE OR REPLACE TABLE virtual_hosts (
    hostname  TEXT,
    upstream  TEXT
);
INSERT INTO virtual_hosts VALUES
    ('app.example.com', '10.0.0.10:8080'),
    ('api.example.com', '10.0.0.20:9000');

Turn query results into formatted text

MiniJinja is a template engine using Jinja-style expressions, conditions, loops, and filters. This extension combines a template with JSON context inside DuckDB and returns the rendered text as a string.

Use it to generate a message, configuration fragment, or HTML snippet from each query row. Your SQL supplies the values and the template controls their presentation. Choose escaping appropriate to the output: HTML needs different treatment from plain text.

Example

Render a message from JSON context

The template inserts a name and loops through a short list. This example produces plain text.

Tested with DuckDB 1.5.6. Browser examples use Haybarn-Wasm 2.0.0-rc12.

SET allow_extension_repositories = 'allowed';
CREATE EXTENSION REPOSITORY IF NOT EXISTS query_farm
  WITH PREFIX 'https://duckdb-extensions.query.farm';
INSTALL minijinja FROM query_farm;
LOAD minijinja FROM query_farm;

SELECT minijinja_render_with_context(
  'Hello {{ name }}! Items: {{ items | join(", ") }}',
  '{"name":"Mina","items":["tea","coffee"]}',
  autoescape := false
) AS message;

Expected result

message
Hello Mina! Items: tea, coffee

Use HTML autoescaping when rendering HTML. Disabling it here is appropriate for plain text; rendered SQL is still text until you explicitly execute it.

Common tasks

Deep Dive

Technical Details

Reference

Extension Contents

Quick reference to all available functions and settings organized by category.

Render
minijinja_render() Object type: Scalar function Render a MiniJinja template without a JSON context.
minijinja_render_with_context() Object type: Scalar function Render a MiniJinja template with a JSON context, including contexts built from columns with json_object.

API Reference

Function Reference

Practical Examples

Cookbook

Real-world recipes and patterns for common use cases.

Platform Support

Compatibility

Extension availability may vary by platform and DuckDB version. Check below to ensure this extension supports your environment before installation.

Quick Facts

Release status Stable
Software License MIT
Pricing Free
Written In Rust
Source Available Yes
View on GitHub
Usage
50,279
loads · last 90 days

Platforms

DuckDB 2.0.0

  • Linux x86_64aarch64
  • Linux (musl) Not available
  • macOS Apple Silicon
  • Windows x86_64x86_64 (MinGW)
  • WASM Not available
Compiled binary sizes
Platform Architecture Size
Linux x86_64 5.64 MB
Linux aarch64 4.94 MB
macOS Apple Silicon 3.50 MB
Windows x86_64 10.80 MB
Windows x86_64 (MinGW) 19.75 MB

Compressed download sizes for the release shown above.

DuckDB & Haybarn

Release calendar
  • DuckDB v2.0.0 Query.Farm repository Supported
  • Haybarn v1.5.6 Built-in community repository Supported

Browser examples use Haybarn-Wasm 2.0.0-rc12.

Checked .

Learn and explore

Tutorials and articles

Writing about MiniJinja: how it works, what changed, and why.