Mermaid Builder

0.0.3 · active · verified Wed Apr 15

Mermaid Builder is a Python library designed to programmatically generate MermaidJS markup, facilitating the creation of various diagrams like flowcharts and sequence diagrams from Python code. It allows developers to script the creation of MermaidJS definitions, which can then be rendered in compatible environments such as Markdown files, GitHub, or online Mermaid playgrounds. The library is in early development, with its current version being 0.0.3, indicating rapid iteration and ongoing feature additions.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to create a simple flowchart using `mermaid-builder`. It initializes a `Chart`, adds `Node` objects, defines links between them, and then renders the MermaidJS markdown string. The generated string can be pasted into a MermaidJS compatible viewer or Markdown file to visualize the diagram.

from mermaid_builder.flowchart import Chart, Node

# Create a new flowchart
chart = Chart("MyCompanyHierarchy", direction="TD") # Top Down direction

# Add nodes
node_a = Node("Company A")
node_b = Node("Company B")
node_c = Node("Company C")
node_d = Node("Company D")

chart.add_node(node_a)
chart.add_node(node_b)
chart.add_node(node_c)
chart.add_node(node_d)

# Define relationships
chart.link(node_a, node_b)
chart.link(node_a, node_c)
chart.link(node_b, node_d)

# Generate the MermaidJS markup
mermaid_markup = chart.render()
print(mermaid_markup)

# To view this diagram, paste the output into a MermaidJS editor (e.g., mermaid.live)
# or use in a Markdown file that supports Mermaid rendering (e.g., GitHub).

view raw JSON →