Registry / data / rustworkx

rustworkx

JSON →
library0.18.1pypypi✓ verified 23d ago

Rustworkx is a general-purpose, high-performance graph library for Python, implemented in Rust. It provides efficient data structures and algorithms for working with graphs and complex networks, offering a fast alternative to other Python graph libraries, especially for performance-critical applications. The current version is 0.17.1, with a consistent release cadence that includes multiple minor/patch releases per year.

pip install rustworkx
INSTALL
IMPORT
SIG · RUSTWORKX
R
rustworkx
datapythonv0.18.1
Install
5.9s avg
Import
19ms
Disk
133MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.18.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.910 runs
installs and imports cleanly · install 0.0s · import 0.020s · 96.8MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 5.9s · import 0.017s · 93MB
133MB installed
● package 133MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

rustworkx
import rustworkx
The entire library's functionality is accessible via the top-level `rustworkx` module.
rx
import rustworkx as rx
Aliasing `rustworkx` to `rx` is a widely adopted convention for brevity.

This quickstart demonstrates creating a `PyGraph` (undirected graph), adding nodes and edges with associated data, and calculating the shortest path between two nodes using Dijkstra's algorithm. Node and edge data can be any Python object, and nodes are referenced by stable integer indices.

import rustworkx as rx # Create an undirected graph graph = rx.PyGraph() # Add nodes with data payloads (e.g., strings) a = graph.add_node("A") b = graph.add_node("B") c = graph.add_node("C") # Add edges with weights graph.add_edges_from([(a, b, 1.5), (a, c, 5.0), (b, c, 2.5)]) # Find the shortest path using Dijkstra's algorithm # Nodes are referenced by their integer indices path = rx.dijkstra_shortest_paths(graph, a, c, weight_fn=float) print(f"Shortest path from A to C: {path}") # Access node data using its index print(f"Node at index {a}: {graph[a]}")
Debug
Known issues
breakingThe library was renamed from `retworkx` to `rustworkx`. While `retworkx` may still work for older versions, the legacy name will no longer be supported starting from the `1.0.0` release.
fix
Update all import statements from `import retworkx` to `import rustworkx` and update package names in `requirements.txt` or `pyproject.toml`.
affects: <1.0.0
breakingThe minimum supported Rust version required for building `rustworkx` from source has been raised to `1.79` for versions `0.17.1` and later. Users installing pre-compiled binaries are not affected.
fix
If building from source, ensure your Rust toolchain is updated to version `1.79` or newer using `rustup update`.
affects: >=0.17.1
gotchaUnlike NetworkX, `rustworkx` uses stable integer indices for all nodes and edges. While arbitrary Python objects can be stored as node/edge payloads, all graph operations (adding/removing/accessing) must use these integer indices, not the payload objects directly.
fix
Adapt code to work with node/edge indices returned by `add_node()`/`add_edge()` methods. Access node data using the graph's mapping protocol (e.g., `graph[node_index]`). Use callback functions for algorithms that operate on node/edge data (e.g., `weight_fn`).
affects: all
gotchaMany `rustworkx` algorithm functions are explicitly typed (e.g., `rustworkx.graph_something` for `PyGraph` and `rustworkx.digraph_something` for `PyDiGraph`). Passing the wrong graph type will result in an error.
fix
Always use the correct explicitly typed function for `PyGraph` (undirected) or `PyDiGraph` (directed) instances. Check the API documentation for the correct function signature.
affects: all
gotchaWhen developing `rustworkx` from source, `pip install -e` (editable install) does not fully work as expected. Local changes to Rust code will not be reflected live in the Python environment without a full reinstallation.
fix
After making changes to the Rust codebase, rerun `pip install .` in the repository root to recompile and update the installed library. Avoid `pip install -e` for Rust code changes.
affects: all
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'rustworkx'
The rustworkx package has not been installed in the active Python environment or the environment is not correctly activated.
fix
pip install rustworkx
error: can't find cargo. Make sure cargo is on the PATH or set CARGO environment variable.
Rustworkx is implemented in Rust, and if a pre-built wheel is not available for your system, pip attempts to build it from source, requiring the Rust compiler (cargo) to be installed and accessible in your system's PATH.
fix
Install the Rust toolchain by following the instructions at https://rustup.rs/
AttributeError: 'PyDiGraph' object has no attribute 'add_node'
Users familiar with other graph libraries like NetworkX might attempt to use a method like `add_node()`, but rustworkx uses `add_nodes_from()` to add one or more nodes and `add_edges_from()` for edges.
fix
Use `graph.add_nodes_from([data1, data2])` to add nodes and `graph.add_edges_from([(u, v, weight), ...])` for edges.
TypeError: 'PyGraph' object is not subscriptable
Rustworkx graph objects do not support direct indexing with square brackets (e.g., `graph[0]`) to retrieve node data or properties.
fix
Use `graph.get_node_data(index)` to retrieve the payload of a node at a specific index.
Upgrade
Version history
0.18.1latest on PyPI · released Jul 30, 2026
Audit
Dependencies
matplotliboptionalOptional dependency for `rustworkx.visualization.mpl_draw` function.
pillowoptionalOptional dependency for `rustworkx.visualization.graphviz_drawer` function.
Agent activity
13 hits · last 30 days
node
8
OpenAI (training)
1
Resources
rustworkx — pip install rustworkx · libregistry