Interactive Graphviz visualization widget for Jupyter notebooks using anywidget.
Project description
graphviz-anywidget
Interactive Graphviz visualization widget for Jupyter notebooks using anywidget. Graphviz is provided via WASM (hpcc-js-wasm) and the rendering is done using graphvizsvg and d3-graphviz, inspired by the VS Code extension Graphviz Interactive Preview.
https://github.com/user-attachments/assets/74cf39c5-2d64-4c98-b3ee-cf7308753da6
Features
- 🎨 Interactive SVG visualization of Graphviz DOT graphs
- 🔍 Search functionality with regex support
- 🎯 Node and edge highlighting
- ↔️ Directional graph traversal
- 🔄 Zoom reset functionality
- 📱 Responsive design
- 🎨 Smooth animations and transitions
- 💻 Works in JupyterLab and Jupyter Notebook
Installation
pip install graphviz-anywidget
or with uv:
uv add graphviz-anywidget
Usage
from graphviz_anywidget import graphviz_widget
# Create a widget with a DOT string
dot_source = """
digraph {
a -> b;
b -> c;
c -> a;
}
"""
widget = graphviz_widget(dot_source)
widget
Features
-
Search: Use the search box to find nodes and edges
- Supports exact match, substring, and regex search
- Case-sensitive option available
-
Direction Selection: Choose how to traverse the graph
- Bidirectional: Show connections in both directions
- Downstream: Show only outgoing connections
- Upstream: Show only incoming connections
- Single: Show only the selected node
-
Zoom Reset: Reset the graph to its original position and scale
API
graphviz_widget
def graphviz_widget(dot_source: str = "digraph { a -> b; }") -> widgets.VBox:
"""Create an interactive Graphviz widget.
Parameters
----------
dot_source
The DOT string representing the graph
Returns
-------
widgets.VBox
The widget containing the graph and controls
"""
Dependencies
- anywidget
- ipywidgets
- graphvizsvg (npm package)
- d3-graphviz (npm package)
- hpcc-js-wasm (npm package)
Development
We recommend using uv for development. It will automatically manage virtual environments and dependencies for you.
uv run jupyter lab example.ipynb
Alternatively, create and manage your own virtual environment:
python -m venv .venv
source .venv/bin/activate
pip install -e ".[dev]"
jupyter lab example.ipynb
The widget front-end code bundles it's JavaScript dependencies. After setting up Python, make sure to install these dependencies locally:
npm install
While developing, you can run the following in a separate terminal to automatically rebuild JavaScript as you make changes:
npm run dev
Open example.ipynb
in JupyterLab, VS Code, or your favorite editor
to start developing. Changes made in js/
will be reflected
in the notebook.
Implementation Notes
- The WASM binary is embedded in the JavaScript bundle as base64
- We override the fetch API to intercept WASM file requests
- Web Worker mode is disabled to ensure consistent WASM loading
- This approach works in any Jupyter environment without needing a separate file server
License
MIT
Credits
Built with:
- anywidget
- graphvizsvg
- d3-graphviz
- The WASM binary comes from @hpcc-js/wasm (via
d3-graphviz
) - Inspired by the VS Code extension Graphviz Interactive Preview.
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
File details
Details for the file graphviz_anywidget-0.2.0.tar.gz
.
File metadata
- Download URL: graphviz_anywidget-0.2.0.tar.gz
- Upload date:
- Size: 686.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6072a444e2120ee160dd7a5f7a167da00a96463ad54f943c5a9b38cbf7cd59cf |
|
MD5 | 8d56fc2653cde39a3d392f92965ab182 |
|
BLAKE2b-256 | 072b61d60711be16aef9f51b36096b1ea898d982e73658bb49a7937a52b5f3a0 |
Provenance
The following attestation bundles were made for graphviz_anywidget-0.2.0.tar.gz
:
Publisher:
pythonpublish.yml
on pipefunc/graphviz-anywidget
-
Statement type:
https://in-toto.io/Statement/v1
- Predicate type:
https://docs.pypi.org/attestations/publish/v1
- Subject name:
graphviz_anywidget-0.2.0.tar.gz
- Subject digest:
6072a444e2120ee160dd7a5f7a167da00a96463ad54f943c5a9b38cbf7cd59cf
- Sigstore transparency entry: 150887486
- Sigstore integration time:
- Predicate type:
File details
Details for the file graphviz_anywidget-0.2.0-py3-none-any.whl
.
File metadata
- Download URL: graphviz_anywidget-0.2.0-py3-none-any.whl
- Upload date:
- Size: 688.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | aec67ac4ec86324edfc1ef0cd12af64addfa4a2f047536f7961fb8b1d95500a4 |
|
MD5 | 46a9e92bc16525650dbbba98d36f9ae8 |
|
BLAKE2b-256 | 7ce7a02a93978f7c68fcc1d46cb295522f4152ceac4d59cbc9cea5a6fbb6145c |
Provenance
The following attestation bundles were made for graphviz_anywidget-0.2.0-py3-none-any.whl
:
Publisher:
pythonpublish.yml
on pipefunc/graphviz-anywidget
-
Statement type:
https://in-toto.io/Statement/v1
- Predicate type:
https://docs.pypi.org/attestations/publish/v1
- Subject name:
graphviz_anywidget-0.2.0-py3-none-any.whl
- Subject digest:
aec67ac4ec86324edfc1ef0cd12af64addfa4a2f047536f7961fb8b1d95500a4
- Sigstore transparency entry: 150887490
- Sigstore integration time:
- Predicate type: