Python interface to the Draw.io file format
|
|
2 years ago | |
|---|---|---|
| drawio2py | 2 years ago | |
| test | 2 years ago | |
| .gitignore | 2 years ago | |
| README.md | 2 years ago | |
| default.nix | 2 years ago | |
| flake.lock | 2 years ago | |
| flake.nix | 2 years ago | |
| overview.png | 2 years ago | |
| setup.py | 2 years ago |
Currently implemented transformations:
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
Only the Python 3 standard library. Developed with Python 3.10.
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.