Algorithms
The backend implements 111 NetworkX algorithms plus constructors and generators for rustworkx-backed graphs. Anything outside this list stays on NetworkX when the input is still an ordinary NetworkX graph.
| Area | Functions |
|---|---|
| Centrality | betweenness_centrality, closeness_centrality, degree_centrality, edge_betweenness_centrality, eigenvector_centrality, group_betweenness_centrality, group_closeness_centrality, group_degree_centrality, hits, in_degree_centrality, katz_centrality, katz_centrality_numpy, out_degree_centrality |
| Link analysis | pagerank |
| Shortest paths | shortest_path, shortest_path_length, dijkstra_path, dijkstra_path_length, bellman_ford_path, bellman_ford_path_length, bidirectional_shortest_path, has_path, all_shortest_paths |
| Single source | single_source_dijkstra, single_source_dijkstra_path, single_source_dijkstra_path_length, single_source_bellman_ford, single_source_bellman_ford_path, single_source_bellman_ford_path_length, single_source_shortest_path, single_source_shortest_path_length, single_source_all_shortest_paths, single_target_shortest_path, single_target_shortest_path_length |
| All pairs | all_pairs_dijkstra, all_pairs_dijkstra_path, all_pairs_dijkstra_path_length, all_pairs_bellman_ford_path, all_pairs_bellman_ford_path_length, all_pairs_shortest_path, all_pairs_shortest_path_length, floyd_warshall, floyd_warshall_numpy, floyd_warshall_predecessor_and_distance, average_shortest_path_length |
| Heuristic search | astar_path, astar_path_length |
| Negative cycles | negative_edge_cycle, find_negative_cycle |
| DAG | is_directed_acyclic_graph, topological_sort, topological_generations, ancestors, descendants, descendants_at_distance, dag_longest_path, dag_longest_path_length, transitive_reduction, immediate_dominators, dominance_frontiers |
| Traversal | dfs_edges, bfs_layers |
| Distance measures | eccentricity, diameter, radius, center, periphery |
| Connectivity | is_connected, is_weakly_connected, is_strongly_connected, is_semiconnected, connected_components, weakly_connected_components, strongly_connected_components, number_connected_components, number_weakly_connected_components, number_strongly_connected_components, node_connected_component, articulation_points, bridges, biconnected_components, condensation, stoer_wagner |
| Cycles and cores | simple_cycles, cycle_basis, find_cycle, chain_decomposition, core_number |
| Structure | is_bipartite, bipartite.color, is_planar, isolates, number_of_isolates, transitivity |
| Matching and coloring | max_weight_matching, is_matching, is_maximal_matching, greedy_color |
| Trees | minimum_spanning_tree, minimum_spanning_edges, steiner_tree, metric_closure |
| Operators | complement, cartesian_product, tensor_product, line_graph |
| Simple paths | all_simple_paths |
| Isomorphism | is_isomorphic, vf2pp_is_isomorphic, vf2pp_isomorphism, vf2pp_all_isomorphisms |
| Construction | Graph, DiGraph, MultiGraph, MultiDiGraph, empty_graph, from_edgelist |
| Generators | path_graph, cycle_graph, star_graph, complete_graph, barbell_graph, lollipop_graph, binomial_tree, full_rary_tree, karate_club_graph, grid_2d_graph, hexagonal_lattice_graph |
| Random generators | gnp_random_graph, fast_gnp_random_graph, gnm_random_graph, dense_gnm_random_graph, random_regular_graph, stochastic_block_model, random_geometric_graph, barabasi_albert_graph, bipartite.random_graph |
Automatic-dispatch policy
Explicit backend="rustworkx" calls can reach every
implementation above. Automatic backend priority declines 24 functions
for which conversion or result remapping is usually slower than NetworkX:
- Early exit favors NetworkX:
has_path,bidirectional_shortest_path,descendants_at_distance,is_bipartite,find_cycle,find_negative_cycle,is_maximal_matching. - Python result construction dominates:
complement,all_pairs_shortest_path,all_shortest_paths,dijkstra_path,bellman_ford_path, thesingle_source_*andsingle_target_*path variants — the paths kernels materialize a path for every visited node, which is quadratic on high-diameter graphs. - The kernel is cheaper than remapping: degree centrality variants,
cycle_basis, weak connectivity, andsingle_source_dijkstra.
Single source-target forms of shortest_path are declined
automatically whether weighted or not: NetworkX answers a pair with a
bidirectional search that visits a fraction of the graph. The
goal-stopped length kernels have no such handicap, so weighted
single-pair shortest_path_length,
dijkstra_path_length, and
bellman_ford_path_length keep dispatching — measured
1.2–9× faster across path, dense, and road-network shapes
(benches/bench_single_pair.py).
Generators have no size cutoff: there is no conversion cost to
amortize, and the dispatcher never consults should_run
for them. Random generators with an explicit seed fall
back to NetworkX's sampler by default; see
seeded random generators.
The eccentricity family computes rustworkx's all-pairs distance
matrix, which is quadratic in memory. Automatic dispatch declines it
past ~4096 nodes (a ~134 MB matrix);
backend="rustworkx" runs anyway, accepting the memory
cost. A single-node eccentricity request computes
per-source lengths instead and has no such gate.
Compatibility limits
The backend rejects argument shapes it cannot honor:
MultiGraphandMultiDiGraphinputs follow NetworkX's parallel-edge semantics: shortest paths take the lightest parallel edge, PageRank and HITS sum parallel weights, betweenness, bridges and articulation points collapse bundles, and spanning trees,find_cycleandline_graphreport edge keys. The functions NetworkX itself refuses on multigraphs (core_number,cycle_basis,chain_decomposition,stoer_wagner,max_weight_matching,is_maximal_matching,eigenvector_centrality,katz_centrality,katz_centrality_numpy,transitivity) fall through, as docomplement,cartesian_product,tensor_productandvf2pp_all_isomorphisms, whose multigraph results NetworkX keys by edge identity the rustworkx kernels drop.- No callable weight functions.
- No
cutoffon shortest-path functions. - Betweenness is unweighted and has no
k=sampling; closeness accepts a stringdistance, callables fall through. - Isomorphism is structural;
node_matchandedge_matchfall through. greedy_colorimplementslargest_first,saturation_largest_first/DSATUR, andindependent_set; other strategies fall through.max_weight_matchingrequires integer edge weights.- A* requires a consistent heuristic. Disable the check with
nx.config.backends.rustworkx.astar_heuristic_check = Falseonly when you already know it is consistent. - The native generators (
path_graph,cycle_graph, …) fall through for a multigraphcreate_using;empty_graphandfrom_edgelistbuild a rustworkx-backed multigraph for one. - Random generators take no
create_using;random_geometric_graphsamples its own positions (explicitposfalls through);barabasi_albert_graphtakes noinitial_graph;grid_2d_graphhandles undirected, non-periodic grids;bipartite.random_graphis undirected withp < 1.
Valid differences
When an answer is not unique, rustworkx may return a different valid ordering or structure. This applies to topological order, longest DAG paths, cycle bases, chain decompositions, greedy colorings, isomorphism mappings, the order inside a BFS layer, some predecessor maps, negative-cycle starting nodes, and minimum spanning forests with tied weights. PageRank, HITS, Katz, and eigenvector centrality may differ slightly through floating-point ordering.
Random generators sample with rustworkx's RNG when
nx.config.backends.rustworkx.native_seeded_generators is
enabled, so a seeded call draws a different — equally valid
— graph than NetworkX's for the same seed. The same seed then
reproduces the same graph for a pinned rustworkx version. Deterministic
generators always match NetworkX exactly.
Graph-returning algorithms return real NetworkX graphs; generators
return rustworkx-backed graphs. Backend metadata
publishes per-function caveats, so help(nx.function_name)
shows the relevant constraints after installation.