Python interface to the Draw.io file format

Léo Laffeach 87264cc1dc adding a try to avoid zlib.error when parsing a library which is not compressed 2 years ago
drawio2py 87264cc1dc adding a try to avoid zlib.error when parsing a library which is not compressed 2 years ago
test cb15bbfcfe A round-trip of parsing and generating XML now gives identical result (in drawio) for the edgeLabel.drawio file 2 years ago
.gitignore 6287ed2fe3 Playing with Nix flakes 2 years ago
README.md bfa8335a70 Add usage section to README 2 years ago
default.nix 8f24f9d877 Oops 2 years ago
flake.lock 2da58ab828 Update nixpkgs 2 years ago
flake.nix 6287ed2fe3 Playing with Nix flakes 2 years ago
overview.png 5e6c24bbb7 Move OML generation stuff to drawio2oml repo (this repo ONLY implements the Py <-> Draw.io interface) 2 years ago
setup.py 4b991e8319 Forgot to add file 2 years ago

README.md

Python interface for .drawio file format

Currently implemented transformations:

Overview

As shown in the figure above, the transformation between .drawio files and a Python in-memory datastructure is bidirectional (but not incremental!).

Note: The generation of OML has been moved to this repo:

https://msdl.uantwerpen.be/git/jexelmans/drawio2oml

Dependencies

Only the Python 3 standard library. Developed with Python 3.10.

Using

Parsing a diagram is as simple as the following snippet:

from drawio2py import parser
from drawio2py.abstract_syntax import DrawIOFile

abstract_syntax: DrawIOFile = parser.Parser.parse("diagram.drawio")

Once in the Python memory structure the diagram can be traversed like a tree. The annotated class type DrawIOFile and its structure can be explored in the abstract syntax file. You can even output the corresponding, uncompressed, diagram:

from drawio2py import generator
from pathlib import Path

with Path("diagram.drawio").open(mode="wb") as output_file:
    generator.generate(abstract_syntax, output_file)

Here abstract_syntax refers to the previous snippet.