Render Mermaid diagrams to SVG, PNG or raw pixels from Python or the command line.
No browser, no Node.js, no Chromium — pip install mmdr is all you need.
mmdr is a Python package with the Mermaid rendering engines written in Rust and compiled into the wheel. The usual way to render Mermaid outside a browser is mermaid-cli (mmdc), which starts headless Chrome for every diagram. mmdr skips that: there is no JavaScript runtime to boot, so it starts fast and drops easily into scripts, CI jobs and notebooks.
Highlights
Nothing to install besides the wheel. The Rust engines are inside it; the only Python dependency is novasvg, which pip fetches for you.
Two backends in one package.merman (default) aims for parity with the official Mermaid library; mermaid-rs-renderer is the faster one. Pick per call with backend=.
Much faster than mermaid-cli in the mermaidx benchmark. Median per diagram: 22.9 ms (merman) and 16.2 ms (mermaid-rs-renderer) against 791 ms for .
Four output formats. SVG, PNG, raw RGBA pixels and NumPy arrays. No Pillow.
A CLI that feels like mmdc. Files or stdin/stdout, so it works in pipelines.
Jupyter-ready. A Diagram displays itself inline.
Installation
pip install mmdr
Command
Adds
pip install mmdr
Both backends, the CLI, SVG / PNG / raw output.
pip install mmdr[numpy]
NumPy, needed only by Diagram.numpy().
[!NOTE]
Upgrading from 0.3? Version 0.4 changed a few things: PNG and pixel output now go through novasvg (a required dependency), mmdr.svg_to_png() and mmdr.svg_to_raw() were removed, and mermaid-rs-renderer raises ValueError on invalid input instead of returning an error SVG. See the changelog.
Quick start
Python
mmdr.render() returns a Diagram. Rendering is lazy: nothing runs until you ask for an output, and the SVG is cached after the first call.
import mmdr
d = mmdr.render("""
flowchart TD
A[Start] --> B{Is it working?}
B -- Yes --> C[Great!]
B -- No --> D[Debug it]
D --> B
""")
svg = d.svg() # str
png = d.png(width=1200, background="#ffffff") # bytes, transparent if no background
raw, w, h = d.raw() # RGBA8888 bytes, width, height
arr = d.numpy() # (H, W, 4) uint8 array, needs numpy
d.save("diagram.svg") # format follows the extension
In a notebook, evaluating mmdr.render("sequenceDiagram\n Alice->>Bob: Hello!") as the last line of a cell shows the diagram inline.
for f in diagrams/*.mmd; do mmdr -i "$f" -o "${f%.mmd}.png" --background '#ffffff'; done
How it works
flowchart TB
src["Mermaid text"] --> be{"backend"}
be -->|"merman (default)"| svg["SVG string"]
be -->|"mermaid-rs-renderer"| svg
svg --> out1[".svg() / save to .svg"]
svg --> nova["novasvg (Python)"]
nova --> out2[".png() / save to .png"]
nova --> out3[".raw() / .numpy()"]
Invalid diagrams raise ValueError when the SVG is first needed.
Diagram support
Diagram type
merman
mermaid-rs-renderer
Benchmark samples mermaid-rs-renderer drew
flowchart / graph
✅
✅
7 of 7
sequenceDiagram
✅
⚠️
2 of 5
classDiagram
✅
⚠️
1 of 2
stateDiagram
✅
✅
3 of 3
erDiagram
✅
✅
2 of 2
requirementDiagram
✅
✅
1 of 1
gitGraph
✅
✅
1 of 1
mindmap
✅
✅
2 of 2
timeline
✅
✅
2 of 2
journey
✅
✅
1 of 1
gantt
✅
✅
2 of 2
pie
✅
✅
2 of 2
quadrantChart
✅
✅
1 of 1
xychart
✅
✅
1 of 1
sankey
✅
✅
1 of 1
block
✅
✅
1 of 1
architecture
✅
✅
1 of 1
kanban
✅
✅
1 of 1
C4
✅
✅
1 of 1
packet
✅
✅
1 of 1
radar
✅
✅
1 of 1
treemap
✅
✅
1 of 1
venn
✅
✅
1 of 1
ishikawa
✅
✅
1 of 1
wardley
✅
✅
1 of 1
ZenUML
✅
✅
3 of 3
ELK layout (flowchart-elk)
✅
✅
3 of 3
info
✅
❌
0 of 1
✅ drew every sample · ⚠️ rejected some samples · ❌ rejected the sample. The last column is from the mermaidx benchmark: 50 samples, merman drew all of them, mermaid-rs-renderer 45.
What mermaid-rs-renderer rejected, and raised ValueError for:
the bare info diagram;
three sequence diagrams: two use + / - activation shorthand (S->>+W), one uses a participant it could not resolve;
one class diagram with a <<abstract>> annotation.
A ✅ means an image came out, not that it is a correct one. We also ran one small diagram each of flowchart, sequence, class, state, ER, pie, gantt, timeline, mindmap, journey, gitGraph, xychart, quadrant, sankey, block, architecture, kanban, C4 and packet straight through mmdr 0.4.0, and both backends rendered all of them. Compare the pictures in the gallery before choosing mermaid-rs-renderer for a type.
The merman backend reports which Mermaid version it follows: run mmdr --info.
Benchmarks
The mermaidx benchmark renders the same 50 Mermaid diagrams with mermaid-cli and with each mermaidx backend. mermaidx uses mmdr as its engine for the rows below (rust:merman and rust:mermaid-rs-renderer).
Renderer
Median per diagram
Compared with mermaid-cli
Produced an image
First render in a process
mermaid-cli (mmdc)
791 ms
reference
50 of 50
1.94 s
mmdr merman
22.9 ms
35× faster
50 of 50
7.1 ms
mmdr mermaid-rs-renderer
16.2 ms
41× faster
45 of 50
13.8 ms
How to read it:
The clock covers Mermaid text to PNG bytes. mmdc is started once per diagram, so its time includes starting Node.js and Chrome; that is the cost of using it in a script, not its layout speed.
Medians are taken over the diagrams each renderer handled. The speed-up is the median of per-diagram ratios.
Producing an image does not mean producing a correct one. Compare the pictures in the gallery before choosing a backend.