A Python library to easily create and manage Mermaid diagrams programmatically, with strong GUI integration support.
Project description
mermaidgui_py
English Version
mermaidgui_py is an intuitive Python library designed to simplify the creation and programmatic management of Mermaid diagrams, with a strong focus on GUI integration. It provides a clean, object-oriented API to define various diagram types such as flowcharts, sequence diagrams, and class diagrams directly from your Python code. Additionally, it offers utility to convert these generated Mermaid codes into image files (PNG, JPG, SVG) using mermaid.cli.
Features
- Intuitive API: Construct Mermaid diagrams using Python objects and method chaining, abstracting the complex Mermaid syntax.
- Multiple Diagram Types: Supports major Mermaid diagram types including Flowcharts (both Top-Down and Left-Right), Sequence Diagrams, and Class Diagrams.
- Image Export: Convert any generated Mermaid code into image formats (PNG, JPG, SVG) effortlessly. (Requires
mermaid.clito be installed externally). - Strong GUI Integration Focus: Designed to be easily integrated into graphical user interfaces (GUIs) built with frameworks like PySide6, enabling developers to create intuitive visual diagram editing and generation tools.
Installation
-
Python Package: Install
mermaidgui_pyand its GUI dependencies using pip:pip install mermaidgui_py
-
mermaid.cli(for image export): Formermaidgui_py's image export functionality, you needNode.jsandmermaid.cliinstalled globally on your system.# First, ensure Node.js is installed (download from nodejs.org) npm install -g @mermaid-js/mermaid-cli
Verify installation by running
mmdc -vin your terminal.
Quick Usage
# Note: The internal package name remains 'pymermaid' for import statements
from pymermaid import Flowchart, SequenceDiagram, ClassDiagram
# Example 1: Create a simple Flowchart
flow = Flowchart(direction='LR') \
.node("A", "Start Process", shape='round') \
.link("A", "-->", "B", "Input Data") \
.node("B", "Process Data") \
.link("B", "--->", "C", "Data Processed") \
.node("C", "End")
print("--- Flowchart Code ---")
print(flow.generate())
# Save as image (requires mermaid.cli)
flow.to_image("flowchart_example.png")
# Example 2: Create a simple Sequence Diagram
seq = SequenceDiagram() \
.actor("User") \
.participant("System") \
.message("User", "->>", "System", "Request data") \
.activate("System") \
.message("System", "-->>", "User", "Data response") \
.deactivate("System")
print("\n--- Sequence Diagram Code ---")
print(seq.generate())
seq.to_image("sequence_example.png")
# Example 3: Create a simple Class Diagram
cls = ClassDiagram() \
.class_("Animal") \
.attribute("-age: int") \
.method("+eat()") \
.class_("Dog", stereotype="<<abstract>>") \
.attribute("+breed: string") \
.method("+bark()") \
.relationship("Dog", "--|>", "Animal")
print("\n--- Class Diagram Code ---")
print(cls.generate())
cls.to_image("class_example.png")
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 mermaidgui_py-0.0.1.tar.gz.
File metadata
- Download URL: mermaidgui_py-0.0.1.tar.gz
- Upload date:
- Size: 6.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
715c249ba56a3adfa7b284933efe68c46da50c3dca49c12254a839655bd3b808
|
|
| MD5 |
d878934b260bfd11d2dbfe5760600fd8
|
|
| BLAKE2b-256 |
c6681e154fa1a661fc163503159eaafff3a73b0a7b8e99b3c4e05cd0e8e2a9d0
|
File details
Details for the file mermaidgui_py-0.0.1-py3-none-any.whl.
File metadata
- Download URL: mermaidgui_py-0.0.1-py3-none-any.whl
- Upload date:
- Size: 7.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0229b316213aa650f0efb421686b243bd1a1d5ca6ce543cbc739ab8dc98bf606
|
|
| MD5 |
5d744a0ddf4bb5762b6f76bb678bdcc3
|
|
| BLAKE2b-256 |
2550a6861c5a0797f685f59f28377e390539a689b76a41929368b4b79690986d
|