Skip to main content

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 c4
  • mermaid-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

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mmdr-0.3.0.tar.gz (42.8 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

mmdr-0.3.0-cp39-abi3-win_amd64.whl (8.4 MB view details)

Uploaded CPython 3.9+Windows x86-64

mmdr-0.3.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (8.2 MB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ x86-64

mmdr-0.3.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (7.6 MB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ ARM64

mmdr-0.3.0-cp39-abi3-macosx_11_0_arm64.whl (7.3 MB view details)

Uploaded CPython 3.9+macOS 11.0+ ARM64

mmdr-0.3.0-cp39-abi3-macosx_10_12_x86_64.whl (7.9 MB view details)

Uploaded CPython 3.9+macOS 10.12+ x86-64

File details

Details for the file mmdr-0.3.0.tar.gz.

File metadata

  • Download URL: mmdr-0.3.0.tar.gz
  • Upload date:
  • Size: 42.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for mmdr-0.3.0.tar.gz
Algorithm Hash digest
SHA256 3ba4b1df1e17eda4e7368ae2c73ca497f92e55427d5d81763a55bde2f45575b5
MD5 5a9c3380a80ab69eb8ae86bff632b71d
BLAKE2b-256 df6abf25083c9e7be29c2375cd36310ac4938cfa0bc0de63ff6adfb0e5c5692f

See more details on using hashes here.

File details

Details for the file mmdr-0.3.0-cp39-abi3-win_amd64.whl.

File metadata

  • Download URL: mmdr-0.3.0-cp39-abi3-win_amd64.whl
  • Upload date:
  • Size: 8.4 MB
  • Tags: CPython 3.9+, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for mmdr-0.3.0-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 5c987ee3809a9583c2f2e72f0a7d632bca43fb2cfa321420ef0bd5bfd8a8aaa0
MD5 c0f1f879b5a05f5572e650760e8af923
BLAKE2b-256 97814b7151db826730c0ae7a29c857baf6de5c6f3df4b24326813a31dc5df683

See more details on using hashes here.

File details

Details for the file mmdr-0.3.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for mmdr-0.3.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 47d715530d8b9ad3886aee9bd13284eec3ee72671f86bba85e661fc914d30753
MD5 9f4c108c7b8b8d1f92cf5dbb1039b870
BLAKE2b-256 6166960cdcf458a09bca124ff9f2752ff4fc81625cb87dfad729e0c5aed2d6c2

See more details on using hashes here.

File details

Details for the file mmdr-0.3.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for mmdr-0.3.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 2ad2e69e4db0635e50d0356844f9be336ffca0825a22ef0ffde4f34fafab9945
MD5 579de892d72da6df02c6b5d68d110bb5
BLAKE2b-256 649b59f973e8eae4c0eb429101763267359ab63831488e9700a9123c8b0703c9

See more details on using hashes here.

File details

Details for the file mmdr-0.3.0-cp39-abi3-macosx_11_0_arm64.whl.

File metadata

  • Download URL: mmdr-0.3.0-cp39-abi3-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 7.3 MB
  • Tags: CPython 3.9+, macOS 11.0+ ARM64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for mmdr-0.3.0-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5630a2c285152c47cc7b7728ceff2affbc340a2b976b2a5712fab35d3e992a0f
MD5 9d76b4b36c1cbe49bb82aee009b888d9
BLAKE2b-256 b94337d531b10cd30f3482db42ba58756e500b667f4cf807941c65b19a2129e0

See more details on using hashes here.

File details

Details for the file mmdr-0.3.0-cp39-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for mmdr-0.3.0-cp39-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 89c1444c880a99272ce9f17cc14a833b5f52521ac714ca05a3bbab52e7b17ac9
MD5 2cfff916f2c86b87303591872324c960
BLAKE2b-256 53dcad3550870b1744907119d3cf7b228c65682e984eb3fd9a7ed373de3e3678

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.3.0 This release

6 files

0.2.0

6 files

0.1.0

6 files

0.0.1

1 file

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page