Skip to main content

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 box
  • width, height: Dimensions of the box
  • style: Custom CSS-like style string
  • image_url: URL or path to an icon/image
  • image_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 components
  • label: Text label on the arrow
  • style: Custom style string
  • direction: 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 group
  • children: List of components in the group
  • layout: Layout type ("column", "row")
  • align: Alignment within the group
  • spacing: Space between components
  • padding: Internal padding
  • style_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


Download files

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

Source Distribution

drawio-diagram-generator-1.0.0.tar.gz (10.5 kB view details)

Uploaded Source

Built Distribution

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

drawio_diagram_generator-1.0.0-py3-none-any.whl (9.2 kB view details)

Uploaded Python 3

File details

Details for the file drawio-diagram-generator-1.0.0.tar.gz.

File metadata

  • Download URL: drawio-diagram-generator-1.0.0.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

Hashes for drawio-diagram-generator-1.0.0.tar.gz
Algorithm Hash digest
SHA256 15f7389f42a4ecc02d0538c47ee605114097b0c903c92f3f304c8d26113938fd
MD5 f3c21feea3e147533777d768d51a9bd4
BLAKE2b-256 e55acf923446845fdb84aa2d4fcba1a03644fea078d9db5cb1d0a0805d8c7083

See more details on using hashes here.

File details

Details for the file drawio_diagram_generator-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for drawio_diagram_generator-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2e23211f81cf07979febab93109332781c9946a4a9868afbe7fe254098ac444e
MD5 9becc7258de7d1710e011cb78790d336
BLAKE2b-256 804f77d417131df644e2f14e50a56fa0c7b85994c10536ad92b34e6d4d573e52

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