Skip to main content

Interactive Graphviz visualization widget for Jupyter notebooks using anywidget.

Project description

graphviz-anywidget

PyPI version Python Version License

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

https://github.com/user-attachments/assets/8947dfd1-5d4a-43b9-b0c7-22cb52f72dc3

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, Jupyter Notebook, and VS Code

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

  1. Search: Use the search box to find nodes and edges

    • Supports exact match, substring, and regex search
    • Case-sensitive option available
  2. 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
  3. 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.

License

MIT

Credits

Built with:

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

graphviz_anywidget-0.6.0.tar.gz (693.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

graphviz_anywidget-0.6.0-py3-none-any.whl (695.3 kB view details)

Uploaded Python 3

File details

Details for the file graphviz_anywidget-0.6.0.tar.gz.

File metadata

  • Download URL: graphviz_anywidget-0.6.0.tar.gz
  • Upload date:
  • Size: 693.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for graphviz_anywidget-0.6.0.tar.gz
Algorithm Hash digest
SHA256 2247e12d8d8e139b6777104a9ffdb96759a4010d7cee601ea7d6220683238559
MD5 42845bf4490012991e36d0903de136f3
BLAKE2b-256 9a940a8e6fe48e8d74a450e608ef8f10e25c2849e82859e0ffc759f594498efc

See more details on using hashes here.

Provenance

The following attestation bundles were made for graphviz_anywidget-0.6.0.tar.gz:

Publisher: pythonpublish.yml on pipefunc/graphviz-anywidget

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file graphviz_anywidget-0.6.0-py3-none-any.whl.

File metadata

File hashes

Hashes for graphviz_anywidget-0.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b621df5e0a51e1fbe2f1cf677e61acd7d07f327150f039fb0987e6c7d91b3c66
MD5 9465ef8e29b7c51190b378b9827a4a17
BLAKE2b-256 a8f33f26868518c4ab0d3c7fdeddfdfcf5d9902ac25ee64f086fe451306c9a6b

See more details on using hashes here.

Provenance

The following attestation bundles were made for graphviz_anywidget-0.6.0-py3-none-any.whl:

Publisher: pythonpublish.yml on pipefunc/graphviz-anywidget

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page