Interactive graph visualization for Python notebooks using anywidget
Project description
anywidget-graph
Interactive graph visualization for Python notebooks.
Works with Marimo, Jupyter, VS Code, Colab, anywhere anywidget runs.
Features
- Universal: One widget, every notebook environment
- Backend-agnostic: Grafeo, Neo4j, NetworkX, pandas, or raw dicts
- Interactive: Pan, zoom, click, expand neighbors, select paths
- Customizable: Colors, sizes, shapes, layouts
- Performant: Virtualized rendering for large graphs
- Exportable: PNG, SVG, JSON
Installation
uv add anywidget-graph
Quick Start
from anywidget_graph import Graph
graph = Graph.from_dict({
"nodes": [
{"id": "alice", "label": "Alice", "group": "person"},
{"id": "bob", "label": "Bob", "group": "person"},
{"id": "paper", "label": "Graph Theory", "group": "document"},
],
"edges": [
{"source": "alice", "target": "bob", "label": "knows"},
{"source": "alice", "target": "paper", "label": "authored"},
]
})
graph
Data Sources
Dictionary
from anywidget_graph import Graph
graph = Graph.from_dict({
"nodes": [{"id": "a"}, {"id": "b"}],
"edges": [{"source": "a", "target": "b"}]
})
Grafeo
from grafeo import GrafeoDB
from anywidget_graph import Graph
db = GrafeoDB()
db.execute("INSERT (:Person {name: 'Alice'})-[:KNOWS]->(:Person {name: 'Bob'})")
result = db.execute("MATCH (a)-[r]->(b) RETURN a, r, b")
graph = Graph.from_grafeo(result)
Neo4j
from neo4j import GraphDatabase
from anywidget_graph import Graph
driver = GraphDatabase.driver("bolt://localhost:7687", auth=("neo4j", "password"))
with driver.session() as session:
result = session.run("MATCH (a)-[r]->(b) RETURN a, r, b LIMIT 100")
graph = Graph.from_neo4j(result)
NetworkX
import networkx as nx
from anywidget_graph import Graph
G = nx.karate_club_graph()
graph = Graph.from_networkx(G)
pandas
import pandas as pd
from anywidget_graph import Graph
edges = pd.DataFrame({
"source": ["alice", "alice", "bob"],
"target": ["bob", "carol", "carol"],
"weight": [1.0, 0.5, 0.8]
})
graph = Graph.from_pandas(edges)
Interactivity
Events
graph = Graph.from_dict(data)
@graph.on_node_click
def handle_node(node_id, node_data):
print(f"Clicked: {node_id}")
@graph.on_edge_click
def handle_edge(edge_id, edge_data):
print(f"Edge: {edge_data['label']}")
Selection
graph.selected_nodes # Get current selection
graph.select(["alice"]) # Select nodes
graph.clear_selection() # Clear
Expansion
graph.expand("alice") # Show neighbors
graph.collapse("alice") # Hide neighbors
Styling
By Group
graph = Graph.from_dict(
data,
node_styles={
"person": {"color": "#4CAF50", "size": 30},
"document": {"color": "#2196F3", "shape": "square"},
}
)
By Property
graph = Graph.from_dict(
data,
node_color="group", # Color by field
node_size=lambda n: n["score"] * 10, # Size by function
edge_width="weight", # Width by field
)
Layouts
Graph.from_dict(data, layout="force") # Default
Graph.from_dict(data, layout="hierarchical")
Graph.from_dict(data, layout="circular")
Graph.from_dict(data, layout="grid")
Options
graph = Graph.from_dict(
data,
width=800,
height=600,
directed=True,
labels=True,
edge_labels=False,
physics=True,
zoom=(0.1, 4),
)
Large Graphs
For 1000+ nodes:
graph = Graph.from_dict(
data,
virtualize=True,
cluster=True,
)
Export
graph.to_png("graph.png")
graph.to_svg("graph.svg")
graph.to_json("graph.json")
Environment Support
| Environment | Supported |
|---|---|
| Marimo | ✅ |
| JupyterLab | ✅ |
| Jupyter Notebook | ✅ |
| VS Code | ✅ |
| Google Colab | ✅ |
| Databricks | ✅ |
Related
- anywidget, custom Jupyter widgets made easy
- Grafeo, embeddable graph database
- grafeo-web, Grafeo in the browser
License
Apache-2.0
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 anywidget_graph-0.2.5.tar.gz.
File metadata
- Download URL: anywidget_graph-0.2.5.tar.gz
- Upload date:
- Size: 125.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a19bf2de9f9ddfd8720ad45aae39327bf193d79b7f6a9b574e930c263e5bef10
|
|
| MD5 |
8e2759db68ff875d5f267446006d45af
|
|
| BLAKE2b-256 |
7191f46d9e104b6807a4c50d16f9f491a8f6a29a161fe21e053963e5bea3419a
|
Provenance
The following attestation bundles were made for anywidget_graph-0.2.5.tar.gz:
Publisher:
pypi.yml on GrafeoDB/anywidget-graph
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
anywidget_graph-0.2.5.tar.gz -
Subject digest:
a19bf2de9f9ddfd8720ad45aae39327bf193d79b7f6a9b574e930c263e5bef10 - Sigstore transparency entry: 943850608
- Sigstore integration time:
-
Permalink:
GrafeoDB/anywidget-graph@a715b2d88c6c3d3c31190014f07692faff7859f8 -
Branch / Tag:
refs/tags/v0.2.5 - Owner: https://github.com/GrafeoDB
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi.yml@a715b2d88c6c3d3c31190014f07692faff7859f8 -
Trigger Event:
release
-
Statement type:
File details
Details for the file anywidget_graph-0.2.5-py3-none-any.whl.
File metadata
- Download URL: anywidget_graph-0.2.5-py3-none-any.whl
- Upload date:
- Size: 52.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0ac3c2a3ae5b612d10730a3e98ccacf15e1193c01a7a5d88eeaba692a9a51960
|
|
| MD5 |
b61021e4bbd0b6012a63be558557ec34
|
|
| BLAKE2b-256 |
28167a980c9bba7dc96b618bd21f5a6f6e8fd2dfc770d936816b8148392f55df
|
Provenance
The following attestation bundles were made for anywidget_graph-0.2.5-py3-none-any.whl:
Publisher:
pypi.yml on GrafeoDB/anywidget-graph
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
anywidget_graph-0.2.5-py3-none-any.whl -
Subject digest:
0ac3c2a3ae5b612d10730a3e98ccacf15e1193c01a7a5d88eeaba692a9a51960 - Sigstore transparency entry: 943850611
- Sigstore integration time:
-
Permalink:
GrafeoDB/anywidget-graph@a715b2d88c6c3d3c31190014f07692faff7859f8 -
Branch / Tag:
refs/tags/v0.2.5 - Owner: https://github.com/GrafeoDB
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi.yml@a715b2d88c6c3d3c31190014f07692faff7859f8 -
Trigger Event:
release
-
Statement type: