A Python library for generating Draw.io diagrams programmatically
Project description
Draw.io Diagram Generator
A Python library for generating Draw.io diagrams programmatically. This library provides a simple and intuitive API to create complex diagrams that can be opened in Draw.io or any compatible diagram editor.
Features
- Component-based architecture: Create diagrams using reusable components
- Flexible layout system: Arrange components in rows, columns, and groups
- Rich styling options: Customize colors, shapes, and connections
- Icon support: Add icons and images to your diagrams
- Export to XML: Generate Draw.io compatible XML files
- Easy to use: Simple API for quick diagram creation
Installation
pip install drawio-diagram-generator
Quick Start
from drawio_diagram_generator import Box, Arrow, Group, Diagram
# Create components
user = Box("User", style="fillColor=#d5e8d4;strokeColor=#82b366;")
server = Box("Server", style="fillColor=#dae8fc;strokeColor=#6c8ebf;")
database = Box("Database", style="fillColor=#fff2cc;strokeColor=#d6b656;")
# Create connections
user_to_server = Arrow(user, server, "HTTP Request")
server_to_db = Arrow(server, database, "SQL Query")
# Group components
components = [user, server, database]
connections = [user_to_server, server_to_db]
# Create diagram
diagram = Diagram(Group("System Architecture", components + connections))
# Save to file
diagram.save("system_architecture.drawio")
Components
Basic Components
- Box: Rectangular components with text and optional icons
- IconBox: Image-only components
- Arrow: Directed connections between components
- Line: Simple line connections without arrows
Layout Components
- Row: Arrange components horizontally
- Column: Arrange components vertically
- Group: Container with title and customizable layout
Examples
Simple Flow Diagram
from drawio_diagram_generator import Box, Arrow, Group, Diagram
# Create flow components
start = Box("Start", style="ellipse;fillColor=#d5e8d4;strokeColor=#82b366;")
process = Box("Process", style="rounded=1;fillColor=#dae8fc;strokeColor=#6c8ebf;")
end = Box("End", style="ellipse;fillColor=#f8cecc;strokeColor=#b85450;")
# Create flow
flow = [
start,
Arrow(start, process),
process,
Arrow(process, end),
end
]
diagram = Diagram(Group("Simple Flow", flow))
diagram.save("simple_flow.drawio")
Network Architecture
from drawio_diagram_generator import Box, Arrow, Group, Diagram
# Network components
internet = Box("Internet", style="fillColor=#e1d5e7;strokeColor=#9673a6;")
firewall = Box("Firewall", style="fillColor=#f8cecc;strokeColor=#b85450;")
web_server = Box("Web Server", style="fillColor=#dae8fc;strokeColor=#6c8ebf;")
database = Box("Database", style="fillColor=#fff2cc;strokeColor=#d6b656;")
# Create network layout
network = Group("Network Architecture", [
internet,
Arrow(internet, firewall),
firewall,
Arrow(firewall, web_server),
web_server,
Arrow(web_server, database),
database
], layout="column", spacing=30)
diagram = Diagram(network)
diagram.save("network_architecture.drawio")
API Reference
Box
Box(label, width=80, height=80, style=None, image_url=None, image_only=False)
label: Text to display in the boxwidth,height: Dimensions of the boxstyle: Custom CSS-like style stringimage_url: URL or path to an icon/imageimage_only: If True, show only the image without text
Arrow
Arrow(source, target, label="", style=None, direction="LR", show_arrow=True)
source,target: Source and target componentslabel: Text label on the arrowstyle: Custom style stringdirection: Connection direction ("LR", "RL", "TB", "BT", etc.)show_arrow: Whether to show arrowhead
Group
Group(label, children, layout="column", align="center", spacing=50, padding=50, style_opts=None)
label: Title of the groupchildren: List of components in the grouplayout: Layout type ("column", "row")align: Alignment within the groupspacing: Space between componentspadding: Internal paddingstyle_opts: Style options for the group container
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details.
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 drawio-diagram-generator-1.0.1.tar.gz.
File metadata
- Download URL: drawio-diagram-generator-1.0.1.tar.gz
- Upload date:
- Size: 10.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0ea120a0612442e75c8b394980559ffa2fc755a9a64abfea6ea99582d2fc203b
|
|
| MD5 |
3b7a45240a8fdd2e3b26431817a5f082
|
|
| BLAKE2b-256 |
1683c855e9c81a94a25b4ae0ca3baada52a8596ab04eedecb55238f56c89731a
|
File details
Details for the file drawio_diagram_generator-1.0.1-py3-none-any.whl.
File metadata
- Download URL: drawio_diagram_generator-1.0.1-py3-none-any.whl
- Upload date:
- Size: 9.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
477a7d0ba2e58591d650260ece89c6012f448c1ff5efb07f2e30bb223a872b5a
|
|
| MD5 |
99f700eee99d8eda5201080883a55481
|
|
| BLAKE2b-256 |
1abcbaf46325353b381059dd7c582db9ba074d58b7f304d2f86229e6b4eb7623
|