Awesome
Mermaid-py
this package works as an interface for the famous mermaid-js library that uses scripts to create diagrams.
Description
mermaid-py is a dynamic Python library designed to serve as a seamless interface for the renowned Mermaid library. Built upon the powerful capabilities of Python, mermaid-py empowers developers and data enthusiasts to effortlessly create stunning diagrams, flowcharts, and visualizations directly within their Python environments.
Examples
first install the package using pip:
pip install mermaid-py
- using
Mermaid
andGraph
classes:
import mermaid as md
from mermaid.graph import Graph
sequence = Graph('Sequence-diagram',"""
stateDiagram-v2
[*] --> Still
Still --> [*]
Still --> Moving
Moving --> Still
Moving --> Crash
Crash --> [*]
""")
render = md.Mermaid(sequence)
render # !! note this only works in the notebook that rendered the html.
<p align="center">
<img src="https://github.com/user-attachments/assets/8476ec24-b41f-4a88-9c30-a2478a2c0fd8" alt="Example Flowchart"
style="width: 20%;">
</p>
- using
mermaidjs
magic function in a notebook firstimport mermaid as md
:
%%mermaidjs # with --img flag in case your notebook doesn't render HTML
flowchart LR
A-->B
B-->C
<p align="center">
<img src="https://github.com/ouhammmourachid/mermaid-py/assets/93659459/d4d1b993-a33d-4eb0-82ae-2ad39bf30e90" alt="Example Flowchart"
style="width: 20%;">
</p>
- using
FlowChart
etc ...
from mermaid import *
from mermaid.flowchart import *
diagram = Mermaid(Flowchart(...))
diagram
- more examples on mermaid and test-mermaid
Server
By default, the library uses the mermaid.ink service github for generating diagrams. The service can be run locally using docker, following instructions here.
The MERMAID_INK_SERVER
environment variable can be used to specify the server to use, for example.
List of Diagrames
-
FlowChart -
Sequence Diagram - Class Diagram
-
State Diagram -
Entity Relationship Diagram -
User Journey - Gantt
-
Pie Chart - Quadrant Chart
-
Requirement Diagram - Gitgraph (Git) Diagram
- C4 Diagram 🦺⚠️
-
Mindmaps - Timeline
- Zenuml
- Sankey
- XYChart 🔥
- Block Diagram 🔥
- Packet 🔥
- Kanban 🔥
- Architecture 🔥
License
This project is licensed under the MIT License.
Contact
If you have any questions or want to get in touch, you can reach out to me at rachidouhammou21@gmail.com.