Render Mermaid diagrams from Python, no Node.js required
Project description
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mermaido-0.2.0.tar.gz.
File metadata
- Download URL: mermaido-0.2.0.tar.gz
- Upload date:
- Size: 17.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e0ae4baa5a60ed5a4597ff911410619a77afcc2df1121d0ac31250e955fd1a0a
|
|
| MD5 |
18115790ee065dfe68fbd8f30a38d971
|
|
| BLAKE2b-256 |
e3e3b38d683d38b5c52601f4647ac0a85123717d2a64860dd5f15f89603a29f4
|
Provenance
The following attestation bundles were made for mermaido-0.2.0.tar.gz:
Publisher:
publish.yml on stano45/mermaido
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mermaido-0.2.0.tar.gz -
Subject digest:
e0ae4baa5a60ed5a4597ff911410619a77afcc2df1121d0ac31250e955fd1a0a - Sigstore transparency entry: 976506926
- Sigstore integration time:
-
Permalink:
stano45/mermaido@8aecc2ea1457c7b79cfd558cf8a7964b216761dd -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/stano45
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@8aecc2ea1457c7b79cfd558cf8a7964b216761dd -
Trigger Event:
push
-
Statement type:
File details
Details for the file mermaido-0.2.0-py3-none-any.whl.
File metadata
- Download URL: mermaido-0.2.0-py3-none-any.whl
- Upload date:
- Size: 6.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
afb4fc063ca5db10159f63a49b46b14d0fa71b0b67ea206dda37b40102d86d9a
|
|
| MD5 |
a6c7446e36cd98a78b7983f6762725c6
|
|
| BLAKE2b-256 |
7dde11c85f2f17fd5aeb50048010333e85c88a625bf21a4e08aa1b175bf1b69b
|
Provenance
The following attestation bundles were made for mermaido-0.2.0-py3-none-any.whl:
Publisher:
publish.yml on stano45/mermaido
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mermaido-0.2.0-py3-none-any.whl -
Subject digest:
afb4fc063ca5db10159f63a49b46b14d0fa71b0b67ea206dda37b40102d86d9a - Sigstore transparency entry: 976506927
- Sigstore integration time:
-
Permalink:
stano45/mermaido@8aecc2ea1457c7b79cfd558cf8a7964b216761dd -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/stano45
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@8aecc2ea1457c7b79cfd558cf8a7964b216761dd -
Trigger Event:
push
-
Statement type: