import networkx as nx
G = nx.DiGraph()
G.add_edge('A', 'B')
G.add_edge('B', 'C')
G.add_edge('C', 'D')
G.add_edge('C', 'A')
nx.simple_cycles(G)
How can I find circular relations in a graph with Python and Networkx?