Package pygraph

Package pygraph

python-graph

A library for working with graphs in Python.


Version: 1.6.1

Data structure classes are exposed at the top-level:

Helper classes are exposed one level beneath:

A quick introductory example:

>>> # Import the module and instantiate a graph object
>>> import graph
>>> gr = graph.graph()
>>> # Add nodes
>>> gr.add_nodes(['X','Y','Z'])
>>> gr.add_nodes(['A','B','C'])
>>> # Add edges
>>> 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')
>>> # Depth first search rooted on node X
>>> st, pre, post = gr.depth_first_search(root='X')
>>> # Print the spanning tree
>>> print st
{'A': 'B', 'C': 'A', 'B': 'Y', 'Y': 'X', 'X': None, 'Z': 'X'}

Submodules

Variables
  __package__ = 'pygraph'