A library for working with graphs in Python.
Version:
1.5.0
Data structure classes are exposed at the top-level:
-
The graph class is exposed as
graph.graph()
.
-
The digraph class is exposed as
graph.digraph()
.
-
The hypergraph class is exposed as
graph.hypergraph()
.
Helper classes are exposed one level beneath:
A quick introductory example:
>>>
>>> import graph
>>> gr = graph.graph()
>>>
>>> gr.add_nodes(['X','Y','Z'])
>>> gr.add_nodes(['A','B','C'])
>>>
>>> gr.add_edge('X','Y')
>>> gr.add_edge('X','Z')
>>> gr.add_edge('A','B')
>>> gr.add_edge('A','C')
>>> gr.add_edge('Y','B')
>>>
>>> st, pre, post = gr.depth_first_search(root='X')
>>>
>>> print st
{'A': 'B', 'C': 'A', 'B': 'Y', 'Y': 'X', 'X': None, 'Z': 'X'}