Skip to main content

Pure Python Mermaid diagram renderer

Project description

merm

Pure Python Mermaid diagram renderer. Converts Mermaid markup to SVG with zero JavaScript dependencies.

Install

pip install merm

Usage

Command line

# File to file (SVG)
merm diagram.mmd -o diagram.svg

# PNG output
merm diagram.mmd -o diagram.png

# Pipe
echo 'graph LR
    A --> B --> C' | merm > diagram.svg

# With a theme
merm diagram.mmd --theme dark -o diagram.svg

# With uvx (no install needed)
uvx merm diagram.mmd -o diagram.svg

Python API

from merm import render_diagram, render_to_file, render_to_png

# Render to SVG string
svg = render_diagram("""
flowchart TD
    A[Start] --> B{Decision}
    B -->|Yes| C[OK]
    B -->|No| D[End]
""")

# Render directly to file (format auto-detected from extension)
render_to_file("flowchart TD\n    A --> B", "diagram.svg")
render_to_file("flowchart TD\n    A --> B", "diagram.png")

# Render to PNG bytes
png_bytes = render_to_png("flowchart TD\n    A --> B")

# With a theme
svg = render_diagram("flowchart TD\n    A --> B", theme="dark")

Supported diagram types

All examples below are rendered by merm. Browse all 131 rendered examples in docs/examples/.

Flowchart

flowchart LR
    A[Hard] -->|Text| B(Round)
    B --> C{Decision}
    C -->|One| D[Result 1]
    C -->|Two| E[Result 2]
Flowchart

Sequence diagram

sequenceDiagram
    Alice->>John: Hello John, how are you?
    loop HealthCheck
        John->>John: Fight against hypochondria
    end
    Note right of John: Rational thoughts!
    John-->>Alice: Great!
    John->>Bob: How about you?
    Bob-->>John: Jolly good!
Sequence diagram

Class diagram

classDiagram
    Class01 <|-- AveryLongClass : Cool
    Class09 --> C2 : Where am I?
    Class09 --* C3
    Class09 --|> Class07
    Class07 : equals()
    Class07 : Object[] elementData
    Class01 : size()
    Class01 : int chimp
    Class01 : int gorilla
    class Class10 {
        int id
        size()
    }
Class diagram

State diagram

stateDiagram-v2
    [*] --> Still
    Still --> [*]
    Still --> Moving
    Moving --> Still
    Moving --> Crash
    Crash --> [*]
State diagram

Entity relationship diagram

erDiagram
    CUSTOMER ||--o{ ORDER : places
    ORDER ||--|{ LINE-ITEM : contains
    CUSTOMER }|..|{ DELIVERY-ADDRESS : uses
ER diagram

Gantt chart

gantt
    section Section
    Completed :done, des1, 2014-01-06, 2014-01-08
    Active :active, des2, 2014-01-07, 3d
    Parallel 1 : des3, after des1, 1d
    Parallel 2 : des4, after des1, 1d
    Parallel 3 : des5, after des3, 1d
    Parallel 4 : des6, after des4, 1d
Gantt chart

Pie chart

pie
    "Dogs" : 386
    "Cats" : 85.9
    "Rats" : 15
Pie chart

Git graph

gitGraph
    commit
    commit
    branch develop
    checkout develop
    commit
    commit
    checkout main
    merge develop
    commit
    commit
Git graph

Mindmap

mindmap
  root((Central Topic))
    Origins
      Long history
      Popularized by Tony Buzan
    Research
      On effectiveness
      On features
    Tools
      Pen and paper
      Mermaid
Mindmap

Flowchart with Font Awesome icons

flowchart TD
    A[fa:fa-tree Christmas Tree] --> B[fa:fa-gift Presents]
    A --> C[fa:fa-star Star on Top]
    B --> D[fa:fa-car Drive to Grandma]
    C --> E[fa:fa-lightbulb Lights]
    D --> F[fa:fa-home Grandma's House]
    E --> F
Christmas tree flowchart

Features

  • Pure Python — no Node.js, no browser, no Puppeteer
  • ~200x faster than mermaid-cli (mmdc)
  • SVG and PNG output
  • 4 built-in themes: default, dark, forest, neutral
  • Theme directives: %%{init: {'theme': 'dark'}}%%
  • 9 diagram types: flowchart, sequence, class, state, ER, gantt, pie, mindmap, gitgraph
  • All flowchart shapes and edge types
  • Subgraph nesting and styling
  • Edge labels and arrow markers
  • Font Awesome icons
  • CLI tool with stdin/stdout piping

Performance

Benchmarked against mermaid-cli (mmdc) across 28 scenarios:

merm mmdc
Average render time ~1 ms ~200 ms
Dependencies 0 Node.js + Puppeteer
Startup overhead None ~500 ms

License

WTFPL

Project details


Download files

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

Source Distribution

merm-0.1.3.tar.gz (812.5 kB view details)

Uploaded Source

Built Distribution

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

merm-0.1.3-py3-none-any.whl (157.9 kB view details)

Uploaded Python 3

File details

Details for the file merm-0.1.3.tar.gz.

File metadata

  • Download URL: merm-0.1.3.tar.gz
  • Upload date:
  • Size: 812.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Hatch/1.16.5 cpython/3.13.12 HTTPX/0.28.1

File hashes

Hashes for merm-0.1.3.tar.gz
Algorithm Hash digest
SHA256 2b9403ac6fd2ccf8962f4127fa1b1d614988b6d591a36d8126a75e5c833aa3f8
MD5 8ba76c0ff17579136fecc0755a45b5f3
BLAKE2b-256 b15e0a2b9a667665093fa4d0640b508c55a7c61d873e2cedcf3a51169e4d2c54

See more details on using hashes here.

File details

Details for the file merm-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: merm-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 157.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Hatch/1.16.5 cpython/3.13.12 HTTPX/0.28.1

File hashes

Hashes for merm-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 0ce4f7240795a212bef864fc1c8f6827af95f984f3943e3bd6837853bdaaf9fa
MD5 d822927cf7f7913bf22a6b4dc386a933
BLAKE2b-256 2acc28a93b1caf8b9c885ef4c700645b596fd4296a773b2636a6f30d4715d22d

See more details on using hashes here.

Supported by

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