Skip to main content

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.cli to 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

  1. Python Package: Install mermaidgui_py and its GUI dependencies using pip:

    pip install mermaidgui_py
    
  2. mermaid.cli (for image export): For mermaidgui_py's image export functionality, you need Node.js and mermaid.cli installed 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 -v in 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


Download files

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

Source Distribution

mermaidgui_py-0.0.1.tar.gz (6.5 kB view details)

Uploaded Source

Built Distribution

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

mermaidgui_py-0.0.1-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

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

Hashes for mermaidgui_py-0.0.1.tar.gz
Algorithm Hash digest
SHA256 715c249ba56a3adfa7b284933efe68c46da50c3dca49c12254a839655bd3b808
MD5 d878934b260bfd11d2dbfe5760600fd8
BLAKE2b-256 c6681e154fa1a661fc163503159eaafff3a73b0a7b8e99b3c4e05cd0e8e2a9d0

See more details on using hashes here.

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

Hashes for mermaidgui_py-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0229b316213aa650f0efb421686b243bd1a1d5ca6ce543cbc739ab8dc98bf606
MD5 5d744a0ddf4bb5762b6f76bb678bdcc3
BLAKE2b-256 2550a6861c5a0797f685f59f28377e390539a689b76a41929368b4b79690986d

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