Mermaid-Python

0.1 · abandoned · verified Thu Apr 16

mermaid-python is a Python package (version 0.1) for generating diagrams using Mermaid JS. It allows you to define Mermaid diagrams as strings and render them into standalone HTML files. The project has not seen updates since its initial release over three years ago (March 2021), meaning it may not support newer Mermaid JS features or address recent issues. It is effectively abandoned.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to define a Mermaid graph using a string and render it into a standalone HTML file. The `Mermaid` class takes the diagram definition, and `to_file()` saves it. You then open the HTML file in a browser to see the rendered diagram.

from mermaid import Mermaid

# Define your Mermaid diagram string
diagram_code = """
graph TD;
    A[Start] --> B{Process?};
    B -- Yes --> C[Do Something];
    C --> D[End];
    B -- No --> D;
"""

# Create a Mermaid object
graph = Mermaid(diagram_code)

# Render the diagram to an HTML file
output_filename = "my_mermaid_diagram.html"
graph.to_file(output_filename)

print(f"Diagram saved to {output_filename}")
# Open 'my_mermaid_diagram.html' in a web browser to view the diagram.

view raw JSON →