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.
Metadata
Release files for flowmaid 0.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| flowmaid-0.0.1.tar.gz | 7.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| flowmaid-0.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 20.8 kB
Release files / flowmaid-0.0.1.tar.gz
| Download URL | flowmaid-0.0.1.tar.gz |
|---|---|
| Size | 7.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9f44183e75b20ca647e45f518379478e6d0f0f84f16ef59ee1e917f643219cf4
|
|
BLAKE2b-256 checksum How to use checksums |
2b6676a0b539645601a47a0e9ba1cdda1eaa3ec6b39804079d0c2faf83c7ae11
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.3
|
Release files / flowmaid-0.0.1-py3-none-any.whl
| Download URL | flowmaid-0.0.1-py3-none-any.whl |
|---|---|
| Size | 13.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
70322eebea85d14e62755ee3bdf15cded285795d2e5fe7bfb4b333c8d2cd5286
|
|
BLAKE2b-256 checksum How to use checksums |
863028ec0b5e6cd7778be074204ce7b386f8ab1098b46d836610adeb084ebabb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.3
|