Convert graphviz (dot) files to draw.io / lucid (mxGraph) format. Beautiful and editable graphs in your favorite editor.
Project description
graphviz2drawio
Convert graphviz (dot) files to draw.io / lucid (mxGraph) format. Beautiful and editable graphs in your favorite editor.
Installation
macOS
graphviz2drawio can be installed with Homebrew:
brew install graphviz2drawio
Linux
It is recommended to use uv or
pipx to install and run the CLI tool in an
isolated environment. If you wish to use the library, you can install with
pip instead.
Note that the graphviz library is required before installing this package.
With uv
Ubuntu / Debian
sudo apt update
sudo apt install graphviz graphviz-dev
uv tool install graphviz2drawio
# To update: uv tool upgrade graphviz2drawio
Fedora
sudo dnf install graphviz graphviz-devel
uv tool install graphviz2drawio
# To update: uv tool upgrade graphviz2drawio
With pipx
Ubuntu / Debian
sudo apt update
sudo apt install pipx graphviz graphviz-dev
pipx install graphviz2drawio
# To update: pipx upgrade graphviz2drawio
Fedora
sudo dnf install pipx graphviz graphviz-devel
pipx ensurepath
pipx install graphviz2drawio
# To update: pipx upgrade graphviz2drawio
Anaconda
conda install conda-forge::graphviz2drawio
Usage
Run the conversion app on your graphviz file. For example, the command below will create converted files example1.xml and example2.xml.
graphviz2drawio example1.dot example2.dot
Alternatively, you can specify the output file (but only if there is a single input file)
graphviz2drawio example.dot -o /path/to/somewhere/new_name.xml
Output can also be sent to stdout by using the --stdout flag.
Graphs can be piped in from stdin and sent to stdout (default) or to a file with -o ....
Library Usage
from graphviz2drawio import graphviz2drawio
graph_to_convert = ...
xml = graphviz2drawio.convert(graph_to_convert)
print(xml)
where graph_to_convert can be any of a file path, file handle, string of dot language, or PyGraphviz.AGraph object
Troubleshooting
dot / Graphviz not found
graphviz2drawio uses PyGraphviz, which is a
binding around the system Graphviz installation — installing the Python
package alone is not enough. If you see an ImportError for pygraphviz, or a
runtime error about a missing dot executable, install Graphviz with your
package manager first (see Installation), then confirm it is on
your PATH:
dot -V
pygraphviz fails to build during installation
pygraphviz compiles a C extension against the Graphviz development headers, so
those headers must be present before you install with uv, pip, or pipx.
On Debian / Ubuntu install graphviz-dev (or libgraphviz-dev); on Fedora
install graphviz-devel.
On macOS (Apple Silicon) the Homebrew prefix /opt/homebrew is not on the
default compiler search path, so the build can fail with a clang error about a
missing graphviz/cgraph.h. Point the compiler at the Homebrew paths:
brew install graphviz
CFLAGS="-I$(brew --prefix graphviz)/include" \
LDFLAGS="-L$(brew --prefix graphviz)/lib" \
pip install --no-cache-dir --force-reinstall pygraphviz
UnableToParseGraphError
This is raised when Graphviz returns no SVG for your graph, which usually means the layout program could not lay the graph out (a missing layout engine or an invalid graph). Confirm Graphviz can render the file directly:
dot -Tsvg yourgraph.dot -o output.svg
If that command also fails, the problem is in your graph or your Graphviz installation rather than in graphviz2drawio.
Layout program not available
The -p / --program flag (default dot) selects a Graphviz layout engine. If
you pass neato, circo, twopi, fdp, etc., that binary must be installed —
most are bundled with Graphviz, but minimal installs may omit some. Verify with:
neato -V
UnicodeDecodeError on input files
graphviz2drawio reads files using your locale encoding by default and
automatically retries as UTF-8 when that fails (a common case on non-UTF-8
Windows systems such as gbk / cp1252, see
#105). If decoding
still fails, pass the file's actual encoding explicitly:
graphviz2drawio --encoding utf-8 yourgraph.dot
Unsupported Python version
graphviz2drawio requires Python 3.11 or newer. Check your interpreter with
python --version, and prefer uv or
pipx for the CLI so it runs in its own
isolated, compatible environment.
Other conversion errors
Errors such as MissingTitleError, MissingTextError, or
CouldNotParsePathError mean Graphviz produced SVG that the parser did not
expect for your particular graph. Please
open an issue and include
your diagram along with your Python and graphviz2drawio versions:
python --version
graphviz2drawio --version
Built With
- PyGraphviz - Python interface to Graphviz
- svg.path - SVG path objects and parser
Contributing
Pull requests and issue reports are welcome. For major changes, please open an issue first to discuss what you would like to change.
To see architectural and process diagrams please visit the deepwiki page
Thanks to all the people who have contributed to this project!
Development Setup
uv is used for packaging and dependency management.
git clone git@github.com:hbmartin/graphviz2drawio.git
cd graphviz2drawio
uv sync
# Replace with the actual path to your dot files
uv run python -m graphviz2drawio test/directed/hello.gv.txt
On macOS (Apple Silicon), pygraphviz compiles a C extension against Graphviz,
and Homebrew's /opt/homebrew is not on the default compiler search path. If
uv sync fails to build pygraphviz (clang error about missing
graphviz/cgraph.h), install Graphviz and rebuild that package with the
Homebrew paths:
brew install graphviz
CFLAGS="-I$(brew --prefix graphviz)/include" \
LDFLAGS="-L$(brew --prefix graphviz)/lib" \
uv sync --reinstall-package pygraphviz
Spec tests
Spec XMLs are stored separately for macOS and Linux because graph layout depends
on platform font metrics. The spec test runner automatically compares against
specs/mac/ on macOS and specs/linux/ on Linux. Each XML spec also has a
matching draw.io-rendered PNG reference, and the test runner compares generated
PNGs pixel by pixel.
The scripts invoke python3 directly, so run the native (macOS) variants
through uv run so they resolve to the project venv. The spec_env.sh variants
run inside Docker and already have the venv on PATH. Native spec testing and
generation also require the draw.io CLI, for example from
brew install --cask drawio on macOS.
uv run ./scripts/test_specs.sh test/ tmp_out/
./scripts/spec_env.sh ./scripts/test_specs.sh test/ tmp_out/
uv run ./scripts/generate_specs.sh test/ specs/mac/
./scripts/spec_env.sh ./scripts/generate_specs.sh test/ specs/linux/
Large or slow spec fixtures can be skipped by setting SPEC_TEST_EXCLUDES to
comma- or whitespace-separated paths/globs. Patterns match paths relative to the
platform spec directory, and basenames also work for convenience.
SPEC_TEST_EXCLUDES="twopi/twopi2.xml" uv run ./scripts/test_specs.sh test/ tmp_out/
SPEC_TEST_EXCLUDES="twopi2.xml,networkmap_*.xml" ./scripts/spec_env.sh ./scripts/test_specs.sh test/ tmp_out/
Roadmap
- Support compatible arrows
- Support multiple edges
- Support edges with links
Legal
© Harold Martin - released under GPLv3
diagrams.net is a trademark and draw.io is a registered trademark of JGraph Limited.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file graphviz2drawio-1.2.0.tar.gz.
File metadata
- Download URL: graphviz2drawio-1.2.0.tar.gz
- Upload date:
- Size: 46.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
75a4775dd975c932ff7e2bfa49cc5ec6c8f1dffe77a3b5b56d40ae3850af692b
|
|
| MD5 |
5ac3fadde3d01831a915c796381d75df
|
|
| BLAKE2b-256 |
ac5ec83be8d5beed742079976c2b2bd75f3505166e0ef5aa2ffe67cbced0a94a
|
Provenance
The following attestation bundles were made for graphviz2drawio-1.2.0.tar.gz:
Publisher:
publish.yml on hbmartin/graphviz2drawio
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
graphviz2drawio-1.2.0.tar.gz -
Subject digest:
75a4775dd975c932ff7e2bfa49cc5ec6c8f1dffe77a3b5b56d40ae3850af692b - Sigstore transparency entry: 2129681473
- Sigstore integration time:
-
Permalink:
hbmartin/graphviz2drawio@e989b6921882fc3da9358592d6cd7c16c54fc959 -
Branch / Tag:
refs/tags/v1.2.0 - Owner: https://github.com/hbmartin
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@e989b6921882fc3da9358592d6cd7c16c54fc959 -
Trigger Event:
release
-
Statement type:
File details
Details for the file graphviz2drawio-1.2.0-py3-none-any.whl.
File metadata
- Download URL: graphviz2drawio-1.2.0-py3-none-any.whl
- Upload date:
- Size: 52.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
09e6d2277043c497b64a008286e7948392e5b79d72ffe54219ef8b709592591a
|
|
| MD5 |
559134118e081a0e5b7b0759470ae9c6
|
|
| BLAKE2b-256 |
78324d681b91bffd60e84c068c7f4ebe1fceb77905e9f9625f232018591be9b6
|
Provenance
The following attestation bundles were made for graphviz2drawio-1.2.0-py3-none-any.whl:
Publisher:
publish.yml on hbmartin/graphviz2drawio
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
graphviz2drawio-1.2.0-py3-none-any.whl -
Subject digest:
09e6d2277043c497b64a008286e7948392e5b79d72ffe54219ef8b709592591a - Sigstore transparency entry: 2129682080
- Sigstore integration time:
-
Permalink:
hbmartin/graphviz2drawio@e989b6921882fc3da9358592d6cd7c16c54fc959 -
Branch / Tag:
refs/tags/v1.2.0 - Owner: https://github.com/hbmartin
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@e989b6921882fc3da9358592d6cd7c16c54fc959 -
Trigger Event:
release
-
Statement type: