Skip to main content

mermaid-render

Render Mermaid diagrams to SVG, PNG, PDF, or editable, connected Visio VSDX on Linux, Windows, and macOS. Uses the official Mermaid.js renderer; no Node.js or Microsoft Visio installation is required. Python 3.10+ is supported.

Install from PyPI

Install the command-line tool with uv:

uv tool install mermaid-render

Mermaid.js and Chromium support files install automatically on the first render. To prepare them in advance, run mermaid-render setup.

Command-line usage

mermaid-render diagram.mmd                  # Creates diagram.svg
mermaid-render diagram.mmd -o diagram.png   # PNG at scale 2 (192 dpi)
mermaid-render diagram.mmd -o diagram.pdf
mermaid-render diagram.mmd -o diagram.vsdx

The output extension selects the format; use --format to select it explicitly. SVG is the default. The default theme is redux-color; use --theme to change it.

  • PNG: Defaults to twice the SVG's pixel dimensions. Use --scale 1 for 96 dpi, or --background transparent for a transparent background.
  • PDF: A single diagram-sized vector page. Scale applies only to PNG.
  • VSDX: Flowcharts and sequence diagrams, with editable shapes and glued connectors. Flowchart subgraphs become native Visio containers with member relationships, including nested subgraphs and internal connectors. Flowcharts default to right-angle connectors; choose --visio-connectors straight or --visio-connectors mermaid for direct lines or detailed Mermaid curves. Mermaid attachment positions, standard shape connection points, and rendered border widths are retained.

Sequence diagrams preserve participants and actors, lifelines, nested activations, message labels and numbering, notes, interaction frames, and participant creation/destruction. Each participant's artwork forms one movable group, with messages attached at their chronological positions. Messages use straight lines and simple rectangular self-loops; --visio-connectors applies to flowcharts. Try examples/sequence.mmd:

mermaid-render examples/sequence.mmd -o sequence.vsdx

Other Mermaid diagram types currently support SVG, PNG, and PDF output.

Python usage

Install into your project with uv add mermaid-render, or into an existing environment with uv pip install mermaid-render.

from mermaid_render import convert

source = """flowchart LR
    A[Input] --> B{Valid?}
    B -->|Yes| C[Process]
    B -->|No| D[Reject]
"""

convert(source, "diagram.svg")
convert(source, "diagram.png", background="transparent")  # scale=2 by default
convert(source, "diagram.pdf")
convert(source, "diagram.vsdx", visio_connectors="right-angle")
svg_bytes = convert(source)  # Without an output path, returns SVG bytes

convert returns bytes for every format and writes them when an output path is supplied. Use theme=, scale=, and background= to customize rendering.

Runtime support files

Support files persist in user application data, rather than a temporary cache:

OS Location
macOS ~/Library/Application Support/mermaid-render
Linux $XDG_DATA_HOME/mermaid-render, or ~/.local/share/mermaid-render
Windows %LOCALAPPDATA%\mermaid-render

The package checks version-matched user support files first, then bundled files. Setup copies bundled files into the support directory when needed, or downloads missing files. Existing valid files are reused. Paths are managed automatically.

On Linux, Chromium also needs system libraries. On a connected machine, install them with:

uvx --from playwright==1.63.0 playwright install-deps chromium

Install in an offline environment

Download a bundled wheel from GitHub Releases, matching the target operating system and architecture:

Platform Wheel filename suffix
Linux x86-64 linux_x86_64.whl
Windows x86-64 win_amd64.whl
macOS Apple Silicon macosx_*_arm64.whl
macOS Intel macosx_*_x86_64.whl

Transfer the wheel to the target machine and install it using its full filename, for example:

uv tool install ./mermaid_render-0.10.1-py3-none-macosx_13_0_arm64.whl
mermaid-render diagram.mmd -o diagram.vsdx

Bundled wheels include Mermaid.js and Chromium, so rendering requires no runtime downloads. Optional mermaid-render setup copies these assets into the user support directory.

Linux wheels are tested on Ubuntu 24.04 and require compatible system browser libraries to be present on the offline machine. They are not manylinux wheels. macOS wheels encode the minimum OS version required by their binaries; CI tests on macOS 15.

GitHub Releases also contain the lightweight PyPI wheel and source archive. Choose a platform-specific wheel for the bundled runtime.

Contribute

Clone the repository and use uv to install dependencies and run tests:

git clone https://github.com/himbeles/mermaid-render.git
cd mermaid-render
uv sync --locked
uv run pytest -q
uv run mermaid-render examples/example.mmd -o diagram.vsdx

Rendering and browser tests automatically prepare missing support files. On Linux, install browser system libraries first with uv run python -m playwright install-deps chromium.

The rendering API lives in src/mermaid_render/api.py; connected VSDX generation in semantic.py (flowcharts) and sequence.py; Mermaid semantics and artwork capture in the *_capture.js files and capture.js; runtime installation in assets.py. Add regression tests for rendering or connector changes. Visual checks in an independent VSDX viewer are useful alongside automated tests.

Build and release

Build lightweight PyPI distributions:

uv build --out-dir dist/pypi
uv run python scripts/check_lightweight_dist.py dist/pypi

Build and test a bundled wheel on its target OS/architecture:

uv run python scripts/build_platform_wheel.py --outdir dist/bundled
uv run python scripts/test_wheel_install.py dist/bundled/*.whl

GitHub Actions builds and tests lightweight distributions plus four platform-specific wheels. To release, update project.version in pyproject.toml, run uv lock, commit, and push a matching v<version> tag. The workflow publishes lightweight distributions to PyPI through Trusted Publishing and attaches all distributions to GitHub Releases. Main-branch pushes, pull requests, and manual runs build without publishing.

License

MIT; see LICENSE.

Originally adapted from Freddy Beltran's mermaid-to-visio project. SVG capture and low-level VSDX generation retain that heritage; connected flowchart and sequence-diagram export were developed further in mermaid-render.

Bundled Mermaid, Chromium, and Playwright retain their upstream licenses and notices.

Metadata

Release files for mermaid-render 0.10.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mermaid-render 0.10.1
File Size Uploaded
mermaid_render-0.10.1.tar.gz 54.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for mermaid-render 0.10.1
File Interpreter ABI Platform
mermaid_render-0.10.1-py3-none-any.whl Python 3 none any Details

Total release size: 94.1 kB

Release files / mermaid_render-0.10.1.tar.gz

Download URL mermaid_render-0.10.1.tar.gz
Size 54.0 kB
Tags Source
SHA-256 checksum
How to use checksums
53f4cd658e73ecd5f3bb59ca115d5b3618034c1f7ba5778bbf772f6ec7ee73af
BLAKE2b-256 checksum
How to use checksums
9ca9e400bb86f32a7371aa9039f1c927843249bc3ea0a0c633953a363c4607f9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.10.0 {"installer":{"name":"uv","version":"0.10.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / mermaid_render-0.10.1-py3-none-any.whl

Download URL mermaid_render-0.10.1-py3-none-any.whl
Size 40.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
aca4e1468ab5062f306130c7dce26b528b9006de32c4730a2138fd1afc84a336
BLAKE2b-256 checksum
How to use checksums
188511171f0035b9db95c0ce90d41caccacff13677419a23b92ca2afeca9805b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.10.0 {"installer":{"name":"uv","version":"0.10.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release history Release notifications | RSS feed

0.12.0

2 release files

0.11.0

2 release files

This release

0.10.1 This release

2 release files

0.10.0

2 release files

0.9.1

2 release files

0.9.0

2 release files

0.8.0

2 release files

0.7.2

2 release files

0.7.1

2 release files

0.7.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page