Retworkx API Reference¶
Graph Classes¶

A class for creating undirected graphs 

A class for creating directed graphs 

A class for creating direct acyclic graphs. 
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 
Random Circuit 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}\) of a directed graph 

Return a \(G_{nm}\) of an undirected graph 
Algorithm Functions¶
Specific Graph Type Methods¶

Return successors in a breadthfirstsearch from a source node. 

Find the longest path in a DAG 

Find the length of the longest path in a DAG 
Find the number of weakly connected components in a DAG. 


Find the weakly connected components in a directed graph 

Check if the graph is weakly connected 

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

Determine if 2 directed graphs are isomorphic 

Determine if 2 undirected graphs are isomorphic 

Return the topological sort of node indexes from the provided graph 

Return the descendants of a node in a graph. 

Return the ancestors of a node in a graph. 
Get the lexicographical topological sorted nodes from the provided DAG 


Get the distance matrix for an undirected graph 

Get the distance matrix for a directed graph 

Return the shortest path lengths between ever pair of nodes that has a path connecting them 

Find allpairs shortest path lengths using Floyd’s algorithm 
Find allpairs shortest path lengths using Floyd’s algorithm 


Collect runs that match a filter function 

Return a list of layers 

Return the adjacency matrix for a PyDiGraph object 

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

Return all simple paths between 2 nodes in a PyDiGraph object 


Compute the A* shortest path for a PyGraph 

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

Find the shortest path from a node 

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

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

Compute the length of the kth shortest path 

Compute the length of the kth shortest path 


Color a PyGraph using a largest_first strategy greedy graph coloring. 

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

Compute the strongly connected components for a directed graph 

Get edge list in depth first order 

Get edge list in depth first order 

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

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

Check if matching is valid for graph 

Check if a matching is a maximal (not maximum) matching for a graph 

Compute a maximumweighted matching for a 

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. 

Compute the transitivity of an undirected graph. 

Compute the transitivity of a directed graph. 

Return the core number for each node in the graph. 

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

Compute the complement of a graph. 

Compute the complement of a graph. 
Universal Functions¶
These functions are algorithm functions that wrap per graph object
type functions in the algorithms API but can be run with a
PyGraph
, PyDiGraph
, or
PyDAG
object.
Compute the complement of a graph. 

Get the distance matrix for a graph 

Find allpairs shortest path lengths using Floyd’s algorithm 

Return the adjacency matrix for a graph object 

Return all simple paths between 2 nodes in a PyGraph object 

Compute the A* shortest path for a graph 

Find the shortest path from a node 

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

Compute the length of the kth shortest path 

Get edge list in depth first order 

Determine if 2 graphs are isomorphic 

Determine if 2 graphs are isomorphic 

Compute the transitivity of a graph. 

Return the core number for each node in the graph. 
Exceptions¶
Return Iterator 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 lists 

A custom class for the return of edge lists with weights 