Python Graph Library [closed]
Asked Answered
S

8

391

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?

Shear answered 3/3, 2009 at 14:12 Comment(0)
C
273

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

Cerargyrite answered 3/3, 2009 at 15:33 Comment(8)
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".Cerargyrite
I was wondering, have you used it with a* or similar algorithms?Matchboard
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.Coast
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 othersUpton
@GreggLind I am using Networkx but I can see in my profiler that getting edges from large graph consumes a lot of time. Are there any guidelines or some documentation for better performance? It would be really helpful.Cessation
igraph also has a github: github.com/igraph/python-igraphBurschenschaft
igraph can be installed via pip: pip install python-igraphBurschenschaft
I recently used NetworkX for a project, I had lines in a text file that referenced other lines, etc and I need to be able to detect circular references and walk the graph in a 'directed' fashion. NetworkX worked PERFECTLY for this. It was fast and easy to use. It has the "is acyclic graph" function to test if the graph isn't circular. Cheers!Repeated
U
120

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.

Unrounded answered 24/11, 2010 at 17:24 Comment(18)
+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!Dawnedawson
I think it would better to give readers a link for comparing the performance of those graph libraries: graph-tool.skewed.de/performanceGarnishee
https://mcmap.net/q/86741/-python-graph-library-closed 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).Verdie
@Tiago Peixoto: I am keen to try and use the graph-tool library, I have one question, How can I use it with pyQt, basically I am in need of a pyton graph library that allows me to create interactive graphs on a Qt Qgraphicsscene/Qgraphicsview. I noticed that graph-tool can create static graphs, pngs etc using cairo, do you know if its possible to use your library with QgraphicsScene? if so how? Many thanksCampanulate
@Campanulate I'm afraid not. Graph-tool uses GTK+/cairo, and hence cannot be easily integrated with Qt. However it does include a ready-to-use GTK+ widget for drawing interactive graphs.Unrounded
No windows support unfortunately :(Intend
@TiagoPeixoto This looks so so promising but can't use it on windows. I am stuck with NetworkX, finding it too slow.Cessation
So embarrassing that such a well-praised tool has no port for Windows user... I find there are too much hassle to build and install on Windows (not to mention there's very high chance that the build will fail).Verdie
Looks great from the documentation. Why doesn't pip install graph-tool work?Request
@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."Unrounded
I would love to use it but the GPL license does not allow me to use it :(Leblanc
@TiagoPeixoto Hi, I would be delighted if you could help out with this post, very much in unknown territories here :( #37945401Privileged
@EdisonGustavoMuenz of course the GPL license allows you to use it... You can even make modifications and distribute those!Unrounded
@TiagoPeixoto how does it compares against snap.stanford.edu/ringo in terms of speed ? They seem promising for speed and multicore processingIbidem
@TiagoPeixoto Can we import planar graphs from shapefiles in graph-tool? I couldn't find anything in the documents so I guess no, but I thought it might be worth it asking the developers.Fianna
@DuccioA Appending to this comment is not the proper way to ask such questions. Please use the mailing list instead: graph-tool.skewed.de/mailingUnrounded
Not really available on Windows (unless you want to use Google Colab which is not user friendly), and its primary emphasis is network science rather than graph theory. I would call it mostly a network science library, but the flows additions are nice (they are much more commonly used in operations research/graph theory, than in NetSci), wished min-cost-max-flow algos were implemented. Sometimes the visualizations are lovely, as Cairo can do a prettier job, but sometimes (like in igraph) it's too much effort to try to make nodes not overlap in the case of a large graph.Solemn
This is incorrect. As described in the documentation, it's possible to use graph-tool on windows using the WSL: git.skewed.de/count0/graph-tool/-/wikis/…Unrounded
M
33

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

Monti answered 3/3, 2009 at 14:17 Comment(0)
P
12

Also, you might want to take a look at NetworkX

Pandect answered 3/3, 2009 at 15:21 Comment(0)
K
8

Use the Boost Graph Library - Python Bindings.

Kurtz answered 3/3, 2009 at 14:22 Comment(2)
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>Shear
Look at graph-tool instead, it's bgl based and active.Pillow
O
7

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

You could also take a look at pygraphlib on sourceforge.

Orthodoxy answered 3/3, 2009 at 14:16 Comment(0)
E
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/

Ellamaeellan answered 20/1, 2012 at 19:57 Comment(0)
W
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.

Wooley answered 23/5, 2012 at 21:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.