mermaido
Render Mermaid diagrams from Python, no Node.js required.
mermaido bundles Node.js via nodejs-bin and wraps mermaid-cli so you can generate diagrams without managing any JavaScript tooling yourself.
Install
pip install mermaido
mermaido install
or with uv:
uv add mermaido
uv run mermaido install
The mermaido install step downloads mermaid-cli and Chromium (~200 MB) into a local cache. You only need to run it once.
Python API
Render to a file
The output format is determined by the file extension (.png, .svg, or .pdf):
import mermaido
mermaido.render("graph TD; A-->B;", "output.png")
mermaido.render("graph TD; A-->B;", "output.svg")
mermaido.render("graph TD; A-->B;", "output.pdf")
Render to a string
svg = mermaido.render_to_string("graph TD; A-->B;") # str
png = mermaido.render_to_string("graph TD; A-->B;", fmt="png") # bytes
pdf = mermaido.render_to_string("graph TD; A-->B;", fmt="pdf") # bytes
Themes
Four built-in themes: default, forest, dark, neutral.
mermaido.render(diagram, "dark.png", theme="dark")
mermaido.render(diagram, "forest.svg", theme="forest")
Background colour
Any CSS colour value. Use "transparent" for no background:
mermaido.render(diagram, "out.png", background_color="transparent")
mermaido.render(diagram, "out.png", background_color="#1a1a2e")
Dimensions and scale
mermaido.render(diagram, "out.png", width=1920, height=1080)
mermaido.render(diagram, "retina.png", scale=2)
Mermaid config file
Pass a JSON config file with Mermaid configuration options:
mermaido.render(diagram, "out.png", config_file="mermaid-config.json")
Custom CSS
mermaido.render(diagram, "out.png", css_file="custom.css")
PDF fit
Scale the PDF to fit the chart:
mermaido.render(diagram, "out.pdf", pdf_fit=True)
All options at a glance
Both render() and render_to_string() accept these keyword arguments:
| Parameter | Type | Default | Description |
|---|---|---|---|
theme |
str |
mmdc default ("default") |
"default", "forest", "dark", or "neutral" |
background_color |
str |
mmdc default ("white") |
Any CSS colour value |
width |
int |
mmdc default (800) |
Page width in pixels |
height |
int |
mmdc default (600) |
Page height in pixels |
scale |
int |
mmdc default (1) |
Puppeteer device scale factor |
config_file |
str | Path |
None |
Path to a Mermaid JSON config file |
css_file |
str | Path |
None |
Path to a custom CSS file |
pdf_fit |
bool |
False |
Scale PDF to fit the chart |
Error handling
Invalid diagrams raise MermaidoError instead of exposing raw subprocess internals:
try:
mermaido.render("graph TDf; oops;", "out.png")
except mermaido.MermaidoError as e:
print(e)
CLI
mermaido is a drop-in replacement for mmdc:
mermaido -i diagram.mmd -o output.svg
mermaido -i diagram.mmd -o output.png -t dark -b transparent
mermaido -i diagram.mmd -o output.pdf -f
mermaido --help
Configuration
| Environment variable | Default | Description |
|---|---|---|
MERMAIDO_MMDC_VERSION |
11.4.2 |
mermaid-cli version to install |
How it works
pip install mermaidoinstalls the Python package and a bundled Node.js binary (vianodejs-bin).mermaido installuses that bundled Node.js tonpm installmermaid-cli and Chromium into a cache directory (~/.cache/mermaidoon Linux, platform-appropriate elsewhere).mermaido.render()or themermaidoCLI invokesmmdcfrom that cache.
No system-wide Node.js or npm installation is needed.
License
MIT
Metadata
Release files for mermaido 0.2.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 | |
|---|---|---|---|
| mermaido-0.2.0.tar.gz | 17.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| mermaido-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 23.3 kB
Release files / mermaido-0.2.0.tar.gz
| Download URL | mermaido-0.2.0.tar.gz |
|---|---|
| Size | 17.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e0ae4baa5a60ed5a4597ff911410619a77afcc2df1121d0ac31250e955fd1a0a
|
|
BLAKE2b-256 checksum How to use checksums |
e3e3b38d683d38b5c52601f4647ac0a85123717d2a64860dd5f15f89603a29f4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Feb 22, 2026.
Transparency logRelease files / mermaido-0.2.0-py3-none-any.whl
| Download URL | mermaido-0.2.0-py3-none-any.whl |
|---|---|
| Size | 6.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
afb4fc063ca5db10159f63a49b46b14d0fa71b0b67ea206dda37b40102d86d9a
|
|
BLAKE2b-256 checksum How to use checksums |
7dde11c85f2f17fd5aeb50048010333e85c88a625bf21a4e08aa1b175bf1b69b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Feb 22, 2026.
Transparency log