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 library (exact baseline is defined by the merman crate, currently 0.9), 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 (pip install mmdr[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.
Rasterizing an existing SVG
mmdr only renders Mermaid. If you already have an SVG string from another source, use novasvg (already installed with mmdr) directly:
import novasvg
doc = novasvg.Document.load_from_data(open("diagram.svg").read())
png = doc.render_to_bitmap(1200, -1, novasvg.Color("white")).to_png()
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 — see LICENSE.
Acknowledgements
mmdr is a Python wrapper around two Rust Mermaid renderers —
mermaid-rs-renderer by 1jehuang and
merman — and uses
novasvg for rasterization.
Metadata
Release files for mmdr 0.4.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 | Provenance | Actions |
|---|---|---|---|---|
| mmdr-0.4.0.tar.gz | 40.0 kB | Without provenance | Details for mmdr-0.4.0.tar.gz |
Built distributions (wheels)
| File | Actions Reset | |||
|---|---|---|---|---|
| mmdr-0.4.0-cp39-abi3-win_amd64.whl | CPython 3.9 | abi3 | Windows x86-64 | Details for mmdr-0.4.0-cp39-abi3-win_amd64.whl |
| mmdr-0.4.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl | CPython 3.9 | abi3 | Linux glibc 2.17+ x86-64 | Details for mmdr-0.4.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
| mmdr-0.4.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl | CPython 3.9 | abi3 | Linux glibc 2.17+ ARM64 | Details for mmdr-0.4.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl |
| mmdr-0.4.0-cp39-abi3-macosx_11_0_arm64.whl | CPython 3.9 | abi3 | macOS 11.0+ ARM64 | Details for mmdr-0.4.0-cp39-abi3-macosx_11_0_arm64.whl |
| mmdr-0.4.0-cp39-abi3-macosx_10_12_x86_64.whl | CPython 3.9 | abi3 | macOS 10.12+ x86-64 | Details for mmdr-0.4.0-cp39-abi3-macosx_10_12_x86_64.whl |
Total release size: 57.1 MB
Release files / mmdr-0.4.0.tar.gz
| Download URL | mmdr-0.4.0.tar.gz |
|---|---|
| Size | 40.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
523e49eb0ec7159316325257378b610ee8b42a076ba424cd6dbb9d2f9cbc93d5
|
|
BLAKE2b-256 checksum How to use checksums |
d60dcd82bcfb95ef13d7e1210d745f5d640cb1b4965bdb23977b23edb5c252cf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / mmdr-0.4.0-cp39-abi3-win_amd64.whl
| Download URL | mmdr-0.4.0-cp39-abi3-win_amd64.whl |
|---|---|
| Size | 12.3 MB |
| Tags | CPython 3.9 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
0eda939bc46a74c1e2340dc22689e7c620816dad8eecb657356e0b7538d83123
|
|
BLAKE2b-256 checksum How to use checksums |
65b5a79047870036bd688f44f7e7a13cc3fc2e80ba097c906cf51e39f6831ffa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / mmdr-0.4.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | mmdr-0.4.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 11.9 MB |
| Tags | CPython 3.9 Linux glibc 2.17+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
2d5d00625b4ea7b183f0d9172b956e1db10970ad11980b792f6705c06951f828
|
|
BLAKE2b-256 checksum How to use checksums |
aaaa8925a7215110a23d5d8c5640b9603aa7cbd89f69fa037c69e623a7ab230d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / mmdr-0.4.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
| Download URL | mmdr-0.4.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl |
|---|---|
| Size | 10.9 MB |
| Tags | CPython 3.9 Linux glibc 2.17+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
143163d5ee053dbefc0360af6f4e557ee8156ff6af217d848c658f1f15a57ed3
|
|
BLAKE2b-256 checksum How to use checksums |
da706db9e18c9cb0dbc4788783b81d50f72b975246028fba110b980dae6e77c6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / mmdr-0.4.0-cp39-abi3-macosx_11_0_arm64.whl
| Download URL | mmdr-0.4.0-cp39-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 10.6 MB |
| Tags | CPython 3.9 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
1cf3ea22f70b2c7049b2af2ba5d2d83de9f74e48dfcd0a0614e6d2ab94d8f95b
|
|
BLAKE2b-256 checksum How to use checksums |
ef7bc0ea1a6c673234a7fa49aa6824d69631035b694bad46555e7f323107bd60
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / mmdr-0.4.0-cp39-abi3-macosx_10_12_x86_64.whl
| Download URL | mmdr-0.4.0-cp39-abi3-macosx_10_12_x86_64.whl |
|---|---|
| Size | 11.4 MB |
| Tags | CPython 3.9 abi3 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
03845e515a1f9d6cbbe71c38da8b64cf88581d306fa5f0ac5dcdde6c134b91f5
|
|
BLAKE2b-256 checksum How to use checksums |
1cdc1ff0a5480b4e39dcb57cca3b2066cdc40d7c802cc3a68d9fa8a501f9cb5a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Security for mmdr 0.4.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.