README.md 1.2 KB

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.