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, sequence diagrams, state diagrams, and class diagrams, with editable shapes and glued connectors. Flowchart subgraphs become native Visio containers with member relationships, including nested subgraphs and internal connectors. Flowcharts, state diagrams, and class diagrams 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, state diagrams, and class diagrams. Try examples/sequence.mmd:

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

State diagrams preserve initial/final symbols, choices, fork/join bars, labeled transitions and self-loops, multiline descriptions, notes, and nested or concurrent states. Composite states become native Visio containers, and transitions remain glued to editable shapes. Try examples/state.mmd:

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

Class diagrams preserve class names, stereotypes, attribute/method compartments, visibility, generics, static and abstract members, notes, and nested namespaces. UML relationship ends distinguish inheritance, realization, composition, aggregation, association, dependency, and lollipop interfaces. Relationship labels and multiplicities stay editable; endpoint labels follow their glued connectors. Try examples/class.mmd:

mermaid-render examples/class.mmd -o class.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.

MCP server

Install optional MCP support:

uv tool install --upgrade 'mermaid-render[mcp]'

Add the stdio server to your MCP client's configuration:

{
  "mcpServers": {
    "mermaid-render": {
      "command": "mermaid-render-mcp"
    }
  }
}

The server provides one tool, render_mermaid. Supply either Mermaid source or an input_path ending in .mmd/.mermaid, plus an output_path:

{
  "source": "flowchart LR; A[Input] -->|Process| B[Output]",
  "output_path": "/absolute/path/diagram.svg"
}

The output extension selects SVG, PNG, PDF, or VSDX. Without an extension, the server appends .svg; an explicit format overrides the default and must match any supplied extension. The result contains the absolute output_path, format, and mime_type. Existing output is replaced only after rendering succeeds. Use absolute paths: relative paths resolve from the server's working directory.

Optional arguments are theme, title, background, scale, and visio_connectors, with the same defaults as the Python API. Runtime setup is automatic. For offline use, install a bundled wheel with its mcp extra and the MCP dependencies available in your environment.

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

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

uv tool install ./mermaid_render-0.11.0-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, state diagrams, and class diagrams) 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 three platform-specific wheels: Linux x86-64, Windows x86-64, and macOS Apple Silicon. 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, sequence-diagram, state-diagram, and class-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.13.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.13.1
File Size Uploaded Provenance
mermaid_render-0.13.1.tar.gz 66.6 kB Without provenance Details

Built distribution (wheel)

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

Total release size: 113.5 kB

Release files / mermaid_render-0.13.1.tar.gz

Download URL mermaid_render-0.13.1.tar.gz
Size 66.6 kB
Tags Source
SHA-256 checksum
How to use checksums
e97e270d563d1e119e048acf322e742e5a40234ad045abb3e62d4a705540ba75
BLAKE2b-256 checksum
How to use checksums
35108255aba96e6771a7e17e71e5c52fdfe5cf1452b802600a8982b2b7471ee6
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.13.1-py3-none-any.whl

Download URL mermaid_render-0.13.1-py3-none-any.whl
Size 46.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
500650e23657df0f4997b0c18ff52f6c744f5114964090f60fa38c8a51225809
BLAKE2b-256 checksum
How to use checksums
b0b4cd34a131ff350c19161676aafb180e74f76088067b465b94e00e520f134b
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}

Security for mermaid-render 0.13.1

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.

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