{"id":1875,"library":"rustworkx","title":"Rustworkx: A High-Performance Graph Library for Python","description":"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.","status":"active","version":"0.17.1","language":"en","source_language":"en","source_url":"https://github.com/Qiskit/rustworkx","tags":["networks","network","graph","graph theory","dag","high-performance","rust"],"install":[{"cmd":"pip install rustworkx","lang":"bash","label":"Install stable version"},{"cmd":"pip install 'rustworkx[all]'","lang":"bash","label":"Install with all optional dependencies (e.g., for visualization)"}],"dependencies":[{"reason":"Optional dependency for `rustworkx.visualization.mpl_draw` function.","package":"matplotlib","optional":true},{"reason":"Optional dependency for `rustworkx.visualization.graphviz_drawer` function.","package":"pillow","optional":true}],"imports":[{"note":"The entire library's functionality is accessible via the top-level `rustworkx` module.","symbol":"rustworkx","correct":"import rustworkx"},{"note":"Aliasing `rustworkx` to `rx` is a widely adopted convention for brevity.","symbol":"rx","correct":"import rustworkx as rx"}],"quickstart":{"code":"import rustworkx as rx\n\n# Create an undirected graph\ngraph = rx.PyGraph()\n\n# Add nodes with data payloads (e.g., strings)\na = graph.add_node(\"A\")\nb = graph.add_node(\"B\")\nc = graph.add_node(\"C\")\n\n# Add edges with weights\ngraph.add_edges_from([(a, b, 1.5), (a, c, 5.0), (b, c, 2.5)])\n\n# Find the shortest path using Dijkstra's algorithm\n# Nodes are referenced by their integer indices\npath = rx.dijkstra_shortest_paths(graph, a, c, weight_fn=float)\nprint(f\"Shortest path from A to C: {path}\")\n\n# Access node data using its index\nprint(f\"Node at index {a}: {graph[a]}\")","lang":"python","description":"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."},"warnings":[{"fix":"Update all import statements from `import retworkx` to `import rustworkx` and update package names in `requirements.txt` or `pyproject.toml`.","message":"The 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.","severity":"breaking","affected_versions":"<1.0.0"},{"fix":"If building from source, ensure your Rust toolchain is updated to version `1.79` or newer using `rustup update`.","message":"The 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.","severity":"breaking","affected_versions":">=0.17.1"},{"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`).","message":"Unlike 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.","severity":"gotcha","affected_versions":"all"},{"fix":"Always use the correct explicitly typed function for `PyGraph` (undirected) or `PyDiGraph` (directed) instances. Check the API documentation for the correct function signature.","message":"Many `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.","severity":"gotcha","affected_versions":"all"},{"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.","message":"When 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.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}