Retworkx API Reference¶
Graph Classes¶

A class for creating undirected graphs 

A class for creating directed graphs 

A class for creating direct acyclic graphs. 
Algorithm Functions¶
Shortest Paths¶
Find the shortest path from a node 

Compute the lengths of the shortest paths for a graph object using Dijkstra's algorithm. 

For each node in the graph, finds the shortest paths to all others. 

For each node in the graph, calculates the lengths of the shortest paths to all others. 

Get the distance matrix for a graph 

Find allpairs shortest path lengths using Floyd's algorithm 

Find allpairs shortest path lengths using Floyd's algorithm 

Compute the A* shortest path for a graph 

Compute the length of the kth shortest path 

Get the number of unweighted shortest paths from a source node 

Return the average shortest path length with unweighted edges. 
Centrality¶
Returns the betweenness centrality of each node in the graph. 
Traversal¶
Get an edge list of the tree edges from a depthfirst traversal 

Depthfirst traversal of a directed/undirected graph. 


Return successors in a breadthfirstsearch from a source node. 
Breadthfirst traversal of a directed/undirected graph. 

Dijkstra traversal of a graph. 


Return the topological sort of node indexes from the provided graph 
Get the lexicographical topological sorted nodes from the provided DAG 


Return the descendants of a node in a graph. 

Return the ancestors of a node in a graph. 

Collect runs that match a filter function 

Collect runs that match a filter function given edge colors 
A visitor object that is invoked at the eventpoints inside the 

A visitor object that is invoked at the eventpoints inside the 

A visitor object that is invoked at the eventpoints inside the 


Provides functionality to topologically sort a directed graph. 
DAG Algorithms¶

Find the longest path in a DAG 

Find the length of the longest path in a DAG 

Find the weighted longest path in a DAG 
Find the length of the weighted longest path in a DAG 


Check that the PyDiGraph or PyDAG doesn't have a cycle 

Return a list of layers 
Tree¶

Find the edges in the minimum spanning tree or forest of a graph using Kruskal's algorithm. 

Find the minimum spanning tree or forest of a graph using Kruskal's algorithm. 

Return an approximation to the minimum Steiner tree of a graph. 
Isomorphism¶
Determine if 2 graphs are isomorphic 

Determine if 2 graphs are subgraph isomorphic 

Determine if 2 graphs are isomorphic 

Return an iterator over all vf2 mappings between two graphs. 
Matching¶

Compute a maximumweighted matching for a 

Check if matching is valid for graph 

Check if a matching is a maximal (not maximum) matching for a graph 
Connectivity and Cycles¶

Find the number of connected components in an undirected graph. 

Find the connected components in an undirected graph 

Returns the set of nodes in the component of graph containing node. 

Check if the graph is connected. 

Compute the strongly connected components for a directed graph 
Find the number of weakly connected components in a directed graph 


Find the weakly connected components in a directed graph 

Check if the graph is weakly connected 

Return a list of cycles which form a basis for cycles of a given PyGraph 

Return the first cycle encountered during DFS of a given PyDiGraph, empty list is returned if no cycle is found 

Return the articulation points of an undirected graph. 

Return the biconnected components of an undirected graph. 

Returns the chain decomposition of a graph. 
Graph Operations¶
Compute the complement of a graph. 

Return a new graph by forming a union from two input graph objects 

Return a new graph by forming the cartesian product from two input graph objects 
Other Algorithm Functions¶
Return the adjacency matrix for a graph object 

Return all simple paths between 2 nodes in a PyGraph object 

Compute the transitivity of a graph. 

Return the core number for each node in the graph. 


Color a PyGraph using a largest_first strategy greedy graph coloring. 

Return the metric closure of a graph 
Generators¶

Generate an undirected cycle graph 
Generate a cycle graph 


Generate an undirected path graph 
Generate a directed path graph 


Generate an undirected star graph 
Generate a directed star graph 


Generate an undirected mesh graph where every node is connected to every other 
Generate a directed mesh graph where every node is connected to every other 


Generate an undirected grid graph. 
Generate a directed grid graph. The edges propagate towards right and 


Generate an undirected binomial tree of order n recursively. 
Generate an undirected binomial tree of order n recursively. 

Generate an undirected hexagonal lattice graph. 

Generate a directed hexagonal lattice graph. The edges propagate towards 

Generate an undirected heavy square graph. 

Generate an directed heavy square graph. 


Generate an undirected heavy hex graph. 
Generate a directed heavy hex graph. 

Generate an undirected lollipop graph where a mesh graph is connected to a path. 

Generate a generalized Petersen graph \(G(n, k)\) with \(2n\) nodes and \(3n\) edges. 

Generate an undirected barbell graph where two identical mesh graphs are connected by a path. 


Creates a full rary tree of n nodes. 
Random Graph Generator Functions¶

Return a \(G_{np}\) directed random graph, also known as an ErdősRényi graph or a binomial graph. 

Return a \(G_{np}\) random undirected graph, also known as an ErdősRényi graph or a binomial graph. 

Return a \(G_{nm}\) directed graph, also known as an ErdősRényi graph. 

Return a \(G_{nm}\) undirected graph, also known as an ErdősRényi graph. 

Returns a random geometric graph in the unit cube of dimensions dim. 
Layout Functions¶
Generate a random layout 

Position nodes using FruchtermanReingold forcedirected algorithm. 

Generate a bipartite layout of the graph 

Generate a circular layout of the graph 

Generate a shell layout of the graph 

Generate a spiral layout of the graph 
Converters¶

Convert a networkx graph object into a retworkx graph object. 
API functions for PyDigraph¶
These functions are algorithm functions that are type specific for
PyDiGraph
or PyDAG
objects. Universal
functions from Retworkx API that work for both graph types internally call
the functions from the explicitly typed based on the data type.

Determine if 2 directed graphs are isomorphic 
Determine if 2 directed graphs are subgraph  isomorphic 


Return an iterator over all vf2 mappings between two 

Get the distance matrix for a directed graph 

Find allpairs shortest path lengths using Floyd's algorithm 

Find allpairs shortest path lengths using Floyd's algorithm 

Return the adjacency matrix for a PyDiGraph object 
Return all simple paths between 2 nodes in a PyDiGraph object 


Compute the A* shortest path for a PyDiGraph 
Find the shortest path from a node 

For each node in the graph, finds the shortest paths to all others in a 

Compute the lengths of the shortest paths for a PyDiGraph object using Dijkstra's algorithm 

For each node in the graph, calculates the lengths of the shortest paths to all others in a 

Compute the length of the kth shortest path 


Get an edge list of the tree edges from a depthfirst traversal 

Depthfirst traversal of a directed graph. 

Return the first cycle encountered during DFS of a given PyDiGraph, empty list is returned if no cycle is found 

Compute the transitivity of a directed graph. 

Return the core number for each node in the directed graph. 

Compute the complement of a directed graph. 

Return a new PyDiGraph by forming a union from two input PyDiGraph objects 

Return a new PyDiGraph by forming the cartesian product from two input PyDiGraph objects 
Generate a random layout 


Generate a bipartite layout of the graph 

Generate a circular layout of the graph 

Generate a shell layout of the graph 

Generate a spiral layout of the graph 

Position nodes using FruchtermanReingold forcedirected algorithm. 
Get the number of unweighted shortest paths from a source node 


Compute the betweenness centrality of all nodes in a PyDiGraph. 

Return the average shortest path length for a 

Breadthfirst traversal of a directed graph. 

Dijkstra traversal of a directed graph. 
API functions for PyGraph¶
These functions are algorithm functions that are type specific for
PyGraph
objects. Universal functions from Retworkx API that
work for both graph types internally call the functions from the explicitly
typed API based on the data type.

Determine if 2 undirected graphs are isomorphic 

Determine if 2 undirected graphs are subgraph  isomorphic 

Return an iterator over all vf2 mappings between two 

Get the distance matrix for an undirected graph 

Find allpairs shortest path lengths using Floyd's algorithm 

Find allpairs shortest path lengths using Floyd's algorithm 

Return the adjacency matrix for a PyGraph class 
Return all simple paths between 2 nodes in a PyGraph object 


Compute the A* shortest path for a PyGraph 
Find the shortest path from a node 

Compute the lengths of the shortest paths for a PyGraph object using Dijkstra's algorithm 

For each node in the graph, finds the shortest paths to all others in a 

Compute the length of the kth shortest path 

For each node in the graph, calculates the lengths of the shortest paths to all others in a 


Get an edge list of the tree edges from a depthfirst traversal 

Depthfirst traversal of an undirected graph. 

Compute the transitivity of an undirected graph. 

Return the core number for each node in the graph. 

Compute the complement of an undirected graph. 

Return a new PyGraph by forming a union from two input PyGraph objects 

Return a new PyGraph by forming the cartesian product from two input PyGraph objects 
Generate a random layout 


Generate a bipartite layout of the graph 

Generate a circular layout of the graph 

Generate a shell layout of the graph 

Generate a spiral layout of the graph 

Position nodes using FruchtermanReingold forcedirected algorithm. 
Get the number of unweighted shortest paths from a source node 


Compute the betweenness centrality of all nodes in a PyGraph. 
Return the average shortest path length for a 


Breadthfirst traversal of an undirected graph. 

Dijkstra traversal of an undirected graph. 
Exceptions¶
Stop graph traversal 

Prune part of the search tree while traversing a graph. 
Custom Return Types¶
A custom class for the return from 

A custom class for the return of node indices 

A custom class for the return of edge indices 

A custom class for the return of edge lists 

A custom class for the return of edge lists with weights 

A class representing a mapping of edge indices to a tuple of node indices and weight/data payload 

A custom class for the return of paths to target nodes 

A custom class for the return of path lengths to target nodes 

A class representing a mapping of node indices to 2D positions 

A custom class for the return of paths to target nodes from all nodes 

A custom class for the return of path lengths to target nodes from all nodes 

A custom class for the return of centralities at target nodes 

A custom class for the return of a list of list of edges. 

A class representing a mapping of node indices to node indices 

A class representing a mapping of tuple of node indices to node indices. 

A class representing a mapping of edge endpoints to biconnected component number that the edge belongs. 