393

I'm writing a python application that will make heavy use of a graph data structure. Nothing horribly complex, but I'm thinking some sort of graph/graph-algorithms library would help me out. I've googled around, but I don't find anything that particularly leaps out at me.

Anyone have any good recommendations?

0

8 Answers 8

276

There are two excellent choices:

NetworkX

and

igraph

I like NetworkX, but I read good things about igraph as well. I routinely use NetworkX with graphs with 1 million nodes with no problem (it's about double the overhead of a dict of size V + E)

If you want a feature comparison, see this from the Networkx-discuss list

Feature comparison thread

Sign up to request clarification or add additional context in comments.

8 Comments

In particular, what I like about Networkx.... it's mostly in python, easy to edit and understand the source code, and it feels mostly "pythonic".
I was wondering, have you used it with a* or similar algorithms?
I just evaluated both. networkx is installable via pip, whereas igraph is not. This makes igraph harder to use as dependencies in your setup.py files.
As an update for 2013, I'm going with networkx just b/c it has a github and looks most up to date of all the options in this answer and the others
igraph also has a github: github.com/igraph/python-igraph
|
122

I would like to plug my own graph python library: graph-tool.

It is very fast, since it is implemented in C++ with the Boost Graph Library, and it contains lots of algorithms and extensive documentation.

18 Comments

+1 For graph-tool. We've been using it in our lab. It is really fast compared to other python libraries. Besides, drawing and displaying graph is pretty awesome in graph-tool. Takes a lot of time to compile though!
stackoverflow.com/questions/606516/python-graph-library Hello, I wanna give graph-tool a try and I find the instruction to install it as in the above link. However I'm a windows user and of course I don't want to switch to Linux just to use this pack. Is it any way to use this library in Windows using pre-built, easy-to-install method? (Of course they offered the method to compile this library by myself but this seems to elaborate too much).
No windows support unfortunately :(
@TiagoPeixoto This looks so so promising but can't use it on windows. I am stuck with NetworkX, finding it too slow.
@ColonelPanic This is a FAQ, see graph-tool.skewed.de/download: "The short answer is that it can't be done, since graph-tool depends crucially on some (excellent) C++ libraries such as Boost, which are not installable via pip."
|
33

Have you looked at python-graph? I haven't used it myself, but the project page looks promising.

Comments

12

Also, you might want to take a look at NetworkX

Comments

8

Use the Boost Graph Library - Python Bindings.

2 Comments

Nice one dehmann, I went for that first (being a C++ programmer by trade and absolutely loving boost), but this scares me: BGL-Python bindings are no longer being maintained <a top of page>
Look at graph-tool instead, it's bgl based and active.
7

Take a look at this page on implementing graphs in python.

You could also take a look at pygraphlib on sourceforge.

Comments

2

I'm having the most luck with pydot. Some of the others are hard to install and configure on different platforms like Win 7.

http://code.google.com/p/pydot/

Comments

1

I second zweiterlinde's suggestion to use python-graph. I've used it as the basis of a graph-based research project that I'm working on. The library is well written, stable, and has a good interface. The authors are also quick to respond to inquiries and reports.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.