Boost Graph Library - Python Bindings

[Home] [Example Usage] [Documentation] [Download] [Contact]
BGL-Python bindings are no longer being maintained
While I've enjoyed working on and working with BGL-Python, I find that I no longer have time to maintain or support this library. If you are interested in working on BGL-Python further, please contact me. The Subversion version of BGL-Python is vastly improved over 0.9: I may still be able to compile one last releasse of this project.

News

Overview

The Boost Graph Library Python bindings (which we refer to as "BGL-Python") expose the functionality of the Boost Graph Library and Parallel Boost Graph Library as a Python package, allowing one to perform computation-intensive tasks on graphs (or networks) from within an easy-to-use scripting language.

Goals

The goal of the BGL-Python bindings is to create a set of bindings for the majority of the BGL in Python that:

Data Structures and Algorithms

BGL-Python contains many of the data structures and algorithms found in the C++ (Parallel) Boost Graph Library, including:

Example Usage

The following simple program loads a GraphViz file, computes the minimum spanning tree of the graph, annotates the graph to illustrate the minimum spanning tree, and emits the result as a GraphViz file.

import boost.graph as bgl

# Load a graph from the GraphViz file 'mst.dot'
graph = bgl.Graph.read_graphviz('mst.dot')

# Convert the weight into floating-point values
weight = graph.convert_property_map(graph.edge_properties['weight'],
                                    'float')

# Compute the minimum spanning tree of the graph
mst_edges = bgl.kruskal_minimum_spanning_tree(graph, weight)

# Compute the weight of the minimum spanning tree 
print 'MST weight =',sum([weight[e] for e in mst_edges])

# Put the weights into the label. Make MST edges solid while all other
# edges remain dashed.
label = graph.edge_property_map('string')
style = graph.edge_property_map('string')
for e in graph.edges:
    label[e] = str(weight[e])
    if e in mst_edges:
        style[e] = 'solid'
    else:
        style[e] = 'dashed'

# Associate the label and style property maps with the graph for output
graph.edge_properties['label'] = label
graph.edge_properties['style'] = style

# Write out the graph in GraphViz DOT format
graph.write_graphviz('mst-out.dot')

Download

There are several ways to get the BGL-Python bindings:

Contact

Douglas Gregor maintains the Python bindings for the Boost Graph Library and Parallel Boost Graph Library. Questions may be sent directly to Doug at or posted to one of the Boost mailing lists. Please put [Graph] into the subject line of your message.


Maintained by: Douglas Gregor, Indiana University ()
Last modified: Tue Nov 22 12:13:38 EST 2005