Skip to main content

A Python library for programmatically generating Draw.io charts.

Project description

CI GitHub License PyPI Version PyPI Downloads

drawpyo logo

Drawpyo is a Python library for programmatically generating Diagrams.net/Draw.io charts. It enables creating a diagram object, placing and styling objects, then writing the object to a file.

History/Justification

I love Draw.io! Compared to expensive and heavy commercial options like Visio and Miro, Draw.io's free and lightweight app allows wider and more universal distribution of diagrams. Because the files are stored in plaintext they can be versioned alongside code in a repository as documentation. The XML-based file format makes these diagrams semi-portable, and could easily be ported to other applications if Draw.io ever failed you. For these reason, I think it's one of the best options for documentation diagrams.

When I had a need to generate heirarchical tree diagrams of requirement structures I was surprised to find there wasn't even a single existing Python library for working with these files. I took the project home and spent a weekend building the initial functionality. I've been adding functionality, robustness, and documentation intermittently since.

Full Documentation

Available here!

https://merrimanind.github.io/drawpyo/

Basic Usage

The basic mode of interacting with drawpyo is to manually create, style, and place objects just like you would using the Draw.io UI. There are a number of ways to style objects and you can write your own functionality for automatically handling style or placement.

Make a new file

import drawpyo
file = drawpyo.File()
file.file_path = r"C:\drawpyo"
file.file_name = "Test Generated Edges.drawio"
# Add a page
page = drawpyo.Page(file=file)

Add an object

item = drawpyo.diagram.Object(page=page, value="new object")
item.position = (0, 0)

Create an object from the base style libraries available in the Draw.io UI

item_from_lib = drawpyo.diagram.object_from_library(
    page=page,
    library="general",
    obj_name="process",
    value="New Process",
    )

Style an object from a string

item_from_stylestr = drawpyo.diagram.Object(page=page)
item_from_stylestr.apply_style_string("rounded=1;whiteSpace=wrap;html=1;fillColor=#6a00ff;fontColor=#ffffff;strokeColor=#000000;gradientColor=#FF33FF;strokeWidth=4;")

Write the file

file.write()

Usage with Diagram Types

Drawpyo also provides higher-level functionality that goes beyond what the Draw.io app offers. These diagram types allow you to generate complete structures automatically, without manually placing every element.

This video demonstrates an exemplary automatic diagram layout process:

For more details, refer to the documentation.

Contributions

Contributions are welcome. See the contribution guidelines or join our Discord server for more information.

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

drawpyo-0.2.5.tar.gz (49.7 kB view details)

Uploaded Source

Built Distribution

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

drawpyo-0.2.5-py3-none-any.whl (59.2 kB view details)

Uploaded Python 3

File details

Details for the file drawpyo-0.2.5.tar.gz.

File metadata

  • Download URL: drawpyo-0.2.5.tar.gz
  • Upload date:
  • Size: 49.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for drawpyo-0.2.5.tar.gz
Algorithm Hash digest
SHA256 28087c5b7975335f88aa5ee289b29b10d634acc1415ae7816bd3629a193f6a8e
MD5 d759508c6a6ea9d7503bb82f8bb4b77b
BLAKE2b-256 f770a5308052c167fb718fb0b67b608fdda3ebff8516a8d2c6f1541dd963a475

See more details on using hashes here.

File details

Details for the file drawpyo-0.2.5-py3-none-any.whl.

File metadata

  • Download URL: drawpyo-0.2.5-py3-none-any.whl
  • Upload date:
  • Size: 59.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for drawpyo-0.2.5-py3-none-any.whl
Algorithm Hash digest
SHA256 9cab60ecf75963e83c144f8bb440d075f6c7887f9d6e735b8bd44d67d37274a3
MD5 314e803eef7c631481049d12c123c1cf
BLAKE2b-256 977c8027e842f290d074163b2b6356a432521c86217f56a3dcc1d41fe7bf9af3

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