A pure Python library designed to convert Mermaid flowcharts into SVG.
Project description
Flowmaid.py
Flowmaid.py is a pure Python library designed to convert Mermaid flowcharts into clean, styled SVG files. It serves as a lightweight, zero-dependency alternative to the JavaScript-based mermaid.js for flowchart rendering.
Features
- Zero Dependencies: Uses only the Python standard library.
- Single File: The entire library is contained in
Flowmaid.py. - Mermaid Syntax Support:
graphandflowchartheaders.- Directions:
TD(Top-Down) andLR(Left-Right). - Node Shapes: Rectangular
[], Rounded(), Diamond{}, Circle(()), Cylinder[()], and Rhomboid>]. - Edge Types: Normal
-->, Thick==>, Dotted-.->, and Link---. - Labeled Edges:
A -- label --> BorA -->|label| B.
- Advanced Styling:
stylecommand for node colors, borders, and widths.linkStylecommand for individual edge customization.
- Subgraphs: Support for
subgraphblocks with custom labels and visual grouping. - Layout & Rendering:
- BFS-based hierarchical ranking for stable positioning.
- Dynamic node sizing based on label length.
- Automatic text wrapping for long labels.
- Precise arrowheads that point exactly to node boundaries.
Installation
Simply copy Flowmaid.py into your project. No pip install required!
Usage
Command Line
You can generate an SVG directly from a Mermaid file:
python3 Flowmaid.py flowchart.mermaid > flowchart.svg
Python API
You can also use Flowmaid.py within your Python scripts:
from Flowmaid import Flowmaid
mermaid_code = """
graph TD
subgraph SG1[Main Process]
A[Start] --> B{Is it working?}
B -- Yes --> C[Great!]
B -- No --> D[Fix it]
end
C --> E[End]
D --> B
style A fill:#f9f,stroke:#333,stroke-width:4px
linkStyle 0 stroke:#ff3,stroke-width:4px
"""
mp = Flowmaid(mermaid_code)
svg_output = mp.generate_svg()
with open("output.svg", "w") as f:
f.write(svg_output)
Example Output
The library handles complex layouts and ensures that styles are correctly applied as inline SVG attributes for maximum compatibility across different viewers.
Future Plans
- Support for nested subgraphs.
- Multi-directional edges (
<-->). - Support for other Mermaid diagram types (Sequence, Gantt, etc.).
- Improved edge routing to minimize crossovers.
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 flowmaid-0.0.1.tar.gz.
File metadata
- Download URL: flowmaid-0.0.1.tar.gz
- Upload date:
- Size: 7.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9f44183e75b20ca647e45f518379478e6d0f0f84f16ef59ee1e917f643219cf4
|
|
| MD5 |
8ae394fdf6dce8d72d7af878b8bb96a4
|
|
| BLAKE2b-256 |
2b6676a0b539645601a47a0e9ba1cdda1eaa3ec6b39804079d0c2faf83c7ae11
|
File details
Details for the file flowmaid-0.0.1-py3-none-any.whl.
File metadata
- Download URL: flowmaid-0.0.1-py3-none-any.whl
- Upload date:
- Size: 13.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
70322eebea85d14e62755ee3bdf15cded285795d2e5fe7bfb4b333c8d2cd5286
|
|
| MD5 |
873e9e34677dc818babbb3cca77c0e98
|
|
| BLAKE2b-256 |
863028ec0b5e6cd7778be074204ce7b386f8ab1098b46d836610adeb084ebabb
|