nx-rustworkx
A NetworkX 3.x backend that runs
selected graph algorithms through
rustworkx. Keep
import networkx as nx, keep your original node IDs, and let
NetworkX dispatch the work.
- 111 NetworkX algorithms are implemented.
- Measured cutoffs avoid dispatch when conversion would cost more than it saves.
- Unsupported calls stay on NetworkX when the input is an
nx.Graph. - A rustworkx-backed graph object avoids repeated conversion for supported workloads.
| Workload | NetworkX | nx-rustworkx | Speedup |
|---|---|---|---|
| City street network (OSMnx MultiDiGraph), weighted closeness centrality | 358 s | 2.6 s | 136× |
| Same network, betweenness centrality | 115 s | 1.5 s | 78× |
| Same network, 200 point-to-point travel-time routes | 8.0 s | 2.3 s | 3.4× |
Best for CPU-heavy whole-graph algorithms on graphs from a few hundred nodes up; deliberately not for tiny graphs or one-off linear-time calls, which stay on NetworkX. Method and full numbers: benchmarks.
Beta. Graphs, digraphs, multigraphs and directed multigraphs dispatch; the graph objects do not support drawing or I/O.
| Release | 0.2.1 |
|---|---|
| Python | 3.10 or newer |
| NetworkX | 3.4 or newer |
| Supported algorithms | 111 |
| License | BSD-3-Clause |
Quick start
pip install nx-rustworkx
Set rustworkx as a preferred backend:
NETWORKX_BACKEND_PRIORITY=rustworkx python your_script.py
Or configure it after importing NetworkX:
import networkx as nx
G = nx.erdos_renyi_graph(2_000, 0.01, seed=1)
nx.config.backend_priority = ["rustworkx"]
scores = nx.betweenness_centrality(G)
NetworkX sees a normal nx.Graph. For large enough supported
calls, nx-rustworkx converts it, runs the rustworkx kernel, and remaps
the answer. Small or unsupported calls remain on NetworkX.
Choose a mode
- Automatic dispatch
- Best default. NetworkX asks the backend whether each call is worth running.
- Explicit backend
- Use
backend="rustworkx"on one call to try the kernel directly. - Native backend graph
- Build a
RustworkxGraphonce when repeated conversion is the bottleneck.
Continue with usage and configuration, or see the full algorithm list and caveats.