mmdr
Render Mermaid diagrams from Python or the command line — fast, native, no browser required.
Most Mermaid rendering tools work by spinning up a headless browser and running the official JavaScript library. This works, but it's slow to start, heavy to install, and awkward to embed in a pipeline. mmdr takes a different approach: the rendering engine is written in Rust and ships as a compiled Python extension. Install it with pip, import it, and start rendering — no Node.js, no Puppeteer, no Chrome, no JS runtime of any kind.
pip install mmdr
That's it. No system dependencies, no extra steps.
Output formats: SVG · PNG · raw RGBA pixels · NumPy array
Two backends, one package:
merman(default) — targets full parity with the official Mermaid @11.15.0 library, supports all diagram types including newer ones like kanban, architecture, and c4mermaid-rs-renderer— a lighter, faster alternative that covers the most common diagram types
CLI
mmdr ships with a command-line tool that works similarly to the official
mermaid-cli (mmdc), but
starts in milliseconds instead of seconds because there's no browser to boot.
Quick start
# render a file to SVG
mmdr -i diagram.mmd -o output.svg
# render to PNG
mmdr -i diagram.mmd -o output.png
# read from stdin, write to stdout — works great in pipelines
echo 'flowchart LR; A-->B-->C' | mmdr -i - -o -
# save the output to a file from a pipe
echo 'flowchart LR; A-->B-->C' | mmdr -i - -o diagram.svg
PNG options
mmdr -i diagram.mmd -o output.png \
--width 1200 \ # canvas width in pixels
--height 800 \ # canvas height in pixels
--background '#ffffff' # background color (transparent by default)
Backend and theme
# use the faster backend for simple diagrams
mmdr -i diagram.mmd -o output.svg --backend mermaid-rs-renderer
# classic Mermaid theme (mermaid-rs-renderer only)
mmdr -i diagram.mmd -o output.svg --backend mermaid-rs-renderer --theme classic
Batch rendering
# convert every .mmd file in a directory
for f in diagrams/*.mmd; do
mmdr -i "$f" -o "${f%.mmd}.svg"
done
# same, but PNG with a white background
for f in diagrams/*.mmd; do
mmdr -i "$f" -o "${f%.mmd}.png" --background '#ffffff'
done
Other commands
mmdr --info # render Mermaid's built-in info diagram and show its text
mmdr --version # print the mmdr version
mmdr -h # full list of options
Python API
Rendering
mmdr.render() accepts a Mermaid source string and returns a Diagram object.
The actual rendering is lazy — nothing runs until you ask for an output.
The SVG result is cached, so calling .svg() multiple times only renders once.
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
svg = d.svg() # str
# write to file
with open("output.svg", "w") as f:
f.write(svg)
PNG
# default: transparent background, size determined by the diagram
png = d.png()
# with explicit size and background
png = d.png(width=1200, height=800, background="#ffffff")
with open("output.png", "wb") as f:
f.write(png)
Save — auto-detect format
d.save("output.svg") # writes SVG
d.save("output.png") # writes PNG
d.save("output.png", width=1200, background="#ffffff") # PNG with options
Raw pixels
.raw() returns the pixel buffer directly from the renderer as
(bytes, width, height). The bytes are raw RGBA8888 data —
4 bytes per pixel, row-major, top-to-bottom.
No encoding, no copying through an image library.
raw, w, h = d.raw(background="#ffffff")
print(f"image is {w}×{h} pixels, {len(raw)} bytes")
NumPy
.numpy() returns an (H, W, 4) array with dtype uint8 and RGBA channel order.
It's built on .raw() — requires only numpy, no Pillow.
arr = d.numpy()
print(arr.shape) # e.g. (480, 640, 4)
print(arr.dtype) # uint8
# drop alpha → RGB
rgb = arr[:, :, :3]
# flip upside-down
import numpy as np
flipped = np.flipud(arr)
Jupyter / IPython
Diagram implements _repr_svg_(), so notebooks render it inline
without any extra code:
import mmdr
# just evaluating this in a cell displays the diagram
mmdr.render("sequenceDiagram\n Alice->>Bob: Hello!\n Bob-->>Alice: Hi!")
Backends
mmdr.backends()
# ['merman', 'mermaid-rs-renderer']
# merman is the default — pick it explicitly if you want to be clear
d = mmdr.render("flowchart LR; A-->B", backend="merman")
# mermaid-rs-renderer for simpler diagrams where speed matters
d = mmdr.render(
"flowchart LR; A-->B-->C",
backend="mermaid-rs-renderer",
theme="classic", # "modern" (default) or "classic"
node_spacing=60.0,
rank_spacing=80.0,
aspect_ratio=(16, 9),
)
The theme, node_spacing, rank_spacing, and aspect_ratio options only
apply to mermaid-rs-renderer. The merman backend uses its own layout engine
tuned for parity with the official library.
Low-level utilities
If you already have an SVG string from another source, you can rasterize it
directly without going through render():
from mmdr import svg_to_png, svg_to_raw
svg = open("diagram.svg").read()
png = svg_to_png(svg, width=1200, background="#ffffff")
raw, w, h = svg_to_raw(svg)
Supported diagram types
| Diagram type | merman | mermaid-rs-renderer |
|---|---|---|
| flowchart / graph | ✅ | ✅ |
| sequenceDiagram | ✅ | ✅ |
| classDiagram | ✅ | ✅ |
| stateDiagram | ✅ | ✅ |
| erDiagram | ✅ | ✅ |
| pie | ✅ | ✅ |
| gantt | ✅ | ✅ |
| timeline | ✅ | ✅ |
| mindmap | ✅ | ✅ |
| gitGraph | ✅ | ✅ |
| xychart | ✅ | ✅ |
| block diagram | ✅ | ❌ |
| architecture | ✅ | ❌ |
| kanban | ✅ | ❌ |
| c4diagram | ✅ | ❌ |
| sankey | ✅ | ❌ |
| packet | ✅ | ❌ |
License
MIT
Metadata
Release files for mmdr 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| mmdr-0.3.0.tar.gz | 42.8 kB | Details |
Built distributions (wheels)
| File | Reset | |||
|---|---|---|---|---|
| mmdr-0.3.0-cp39-abi3-win_amd64.whl | CPython 3.9 | abi3 | Windows x86-64 | Details |
| mmdr-0.3.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl | CPython 3.9 | abi3 | Linux glibc 2.17+ x86-64 | Details |
| mmdr-0.3.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl | CPython 3.9 | abi3 | Linux glibc 2.17+ ARM64 | Details |
| mmdr-0.3.0-cp39-abi3-macosx_11_0_arm64.whl | CPython 3.9 | abi3 | macOS 11.0+ ARM64 | Details |
| mmdr-0.3.0-cp39-abi3-macosx_10_12_x86_64.whl | CPython 3.9 | abi3 | macOS 10.12+ x86-64 | Details |
Total release size: 39.4 MB
Release files / mmdr-0.3.0.tar.gz
| Download URL | mmdr-0.3.0.tar.gz |
|---|---|
| Size | 42.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3ba4b1df1e17eda4e7368ae2c73ca497f92e55427d5d81763a55bde2f45575b5
|
|
BLAKE2b-256 checksum How to use checksums |
df6abf25083c9e7be29c2375cd36310ac4938cfa0bc0de63ff6adfb0e5c5692f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Release files / mmdr-0.3.0-cp39-abi3-win_amd64.whl
| Download URL | mmdr-0.3.0-cp39-abi3-win_amd64.whl |
|---|---|
| Size | 8.4 MB |
| Tags | CPython 3.9 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
5c987ee3809a9583c2f2e72f0a7d632bca43fb2cfa321420ef0bd5bfd8a8aaa0
|
|
BLAKE2b-256 checksum How to use checksums |
97814b7151db826730c0ae7a29c857baf6de5c6f3df4b24326813a31dc5df683
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Release files / mmdr-0.3.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | mmdr-0.3.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 8.2 MB |
| Tags | CPython 3.9 Linux glibc 2.17+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
47d715530d8b9ad3886aee9bd13284eec3ee72671f86bba85e661fc914d30753
|
|
BLAKE2b-256 checksum How to use checksums |
6166960cdcf458a09bca124ff9f2752ff4fc81625cb87dfad729e0c5aed2d6c2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Release files / mmdr-0.3.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
| Download URL | mmdr-0.3.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl |
|---|---|
| Size | 7.6 MB |
| Tags | CPython 3.9 Linux glibc 2.17+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
2ad2e69e4db0635e50d0356844f9be336ffca0825a22ef0ffde4f34fafab9945
|
|
BLAKE2b-256 checksum How to use checksums |
649b59f973e8eae4c0eb429101763267359ab63831488e9700a9123c8b0703c9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Release files / mmdr-0.3.0-cp39-abi3-macosx_11_0_arm64.whl
| Download URL | mmdr-0.3.0-cp39-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 7.3 MB |
| Tags | CPython 3.9 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
5630a2c285152c47cc7b7728ceff2affbc340a2b976b2a5712fab35d3e992a0f
|
|
BLAKE2b-256 checksum How to use checksums |
b94337d531b10cd30f3482db42ba58756e500b667f4cf807941c65b19a2129e0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Release files / mmdr-0.3.0-cp39-abi3-macosx_10_12_x86_64.whl
| Download URL | mmdr-0.3.0-cp39-abi3-macosx_10_12_x86_64.whl |
|---|---|
| Size | 7.9 MB |
| Tags | CPython 3.9 abi3 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
89c1444c880a99272ce9f17cc14a833b5f52521ac714ca05a3bbab52e7b17ac9
|
|
BLAKE2b-256 checksum How to use checksums |
53dcad3550870b1744907119d3cf7b228c65682e984eb3fd9a7ed373de3e3678
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|