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",
)
Import external shape libraries
Requires drawpyo 0.2.6 or later. This functionality is available on main but is not included in the 0.2.5 release.
You can import and use external Draw.io XML shape libraries (e.g., Azure, AWS, Google Cloud icons):
# Register an external library
drawpyo.register_mxlibrary(
"developer",
"https://raw.githubusercontent.com/jgraph/drawio-libs/refs/heads/main/libs/integration/developer.xml"
)
# Use shapes from the registered library
icon = drawpyo.diagram.object_from_library(
page=page,
library="developer",
obj_name="App Developing",
position=(100, 100)
)
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.
Metadata
Release files for drawpyo 0.2.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| drawpyo-0.2.6.tar.gz | 54.4 kB | With provenance | Details for drawpyo-0.2.6.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| drawpyo-0.2.6-py3-none-any.whl | Python 3 | none | any | Details for drawpyo-0.2.6-py3-none-any.whl |
Total release size: 118.5 kB
Release files / drawpyo-0.2.6.tar.gz
| Download URL | drawpyo-0.2.6.tar.gz |
|---|---|
| Size | 54.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a5a835cef1876d85e03f0e9a8b6be9c9130cd0c6a5b851f14d93050b14bfb269
|
|
BLAKE2b-256 checksum How to use checksums |
c988aefc6c40afa333e95e0dfca13b45d46ff039e8b42ba39f7a0339c605e621
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 22, 2026.
Transparency logRelease files / drawpyo-0.2.6-py3-none-any.whl
| Download URL | drawpyo-0.2.6-py3-none-any.whl |
|---|---|
| Size | 64.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
76e952d54363e4e321c7109b467cb05817075fe1252353ee24632e20c6feb13d
|
|
BLAKE2b-256 checksum How to use checksums |
9fb98726e5ad2d562c639d3234b4620278cc19ab6d7443ca73bedb39454c07ee
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 22, 2026.
Transparency logSecurity for drawpyo 0.2.6
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for drawpyo-0.2.6.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 22, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.