What is graph-tool?
Graph-tool is an efficient Python module for manipulation and statistical analysis of graphs (a.k.a. networks). Contrary to most other Python modules with similar functionality, the core data structures and algorithms are implemented in C++, making extensive use of template metaprogramming, based heavily on the Boost Graph Library. This confers it a level of performance that is comparable (both in memory usage and computation time) to that of a pure C/C++ library.
Graph-tool is mature software that has been on the cutting edge of network science for more than 20 years. It is fully documented, and is released as Free Software under the LGPLv3 license.
It is fast!
The core algorithms and data structures are written in C++, so they often run orders of magnitude faster than Python-only alternatives, making graph-tool especially suited for large networks. See a performance comparison.
Parallel
Many algorithms, as well as graph construction and random graph sampling, run in parallel with OpenMP on multi-core machines. The C++ code also releases the GIL, so Python threads can run it concurrently.
Fully documented
All over 600 functions are documented, with examples, in the online documentation and its cookbooks.
Powerful visualization
Static and interactive drawing with its own layout algorithms. See the drawing tutorial.
After installation, you should start with the quick start guide!
You should then take a look at the various cookbooks, and explore all the examples in the various submodules.
For commonly asked questions, read the FAQ.
Unique features
These are some of the functionalities of graph-tool which are currently not available in most other comparable packages:
Comprehensive framework for inferential community detection, built upon statistically principled approaches that avoid overfitting and are interpretable. (See here as well as [1] for why you should avoid off-the-shelf methods available in other software packages.)
Support for network reconstruction from dynamics.
Support for uncertainty quantification in network data.
Support for OpenMP shared memory parallelism throughout the library: not only in many algorithms, but also when building, copying and filtering graphs, and when sampling random graphs from stochastic block models.
High-quality network visualization, both static and interactive, with 29 layout algorithms, and supporting animations and matplotlib integration.
Filtered graphs, i.e. graphs where nodes and edges are temporarily masked. These are first class citizens in the library, and are accepted by every function. Due to the use of C++ template metaprogramming, this functionality comes at no performance cost when filtering is not being used.
Efficient and fully documented binary format for network files.
Integration with the Netzschleuder network data repository, enabling easy loading of network data.
Support for writing custom C++ extensions.
See the changelog.
Quick installation:
conda create --name gt -c conda-forge graph-tool
conda activate gtmkdir my-project
cd my-project
pixi init
pixi add graph-toolport install py-graph-toolbrew install graph-toolpacman -S python-graph-toolapt-get install python3-graph-tool(see the instructions for installing the bleeding edge version from the upstream repository.)
emerge graph-tooldnf install python3-graph-tooldocker pull tiagopeixoto/graph-toolSee here for more detailed installation instructions.
For a quick test run without installing on your machine, you can run graph-tool under colab.
Quick demos:

import graph_tool.all as gt
import matplotlib.cm
gt.seed_rng(47)
g = gt.collection.ns["foodweb_ulanowicz/baywet"]
sargs = dict(rec=[g.ep.weight],
rec_types=["real-exponential"])
state = \
gt.minimize_nested_blockmodel_dl(g,
base_state=gt.WeightedBlockState,
base_state_args=sargs)
state.draw(edge_color=gt.prop_to_size(g.ep.weight,
power=1,
log=True),
ecmap=(matplotlib.cm.inferno, .6),
eorder=g.ep.weight,
edge_pen_width=gt.prop_to_size(g.ep.weight,
1, 4,
power=1,
log=True),
edge_gradient=[]);

import graph_tool.all as gt
import matplotlib.cm
g = gt.collection.data["polblogs"]
g = gt.extract_largest_component(g)
pr = gt.pagerank(g)
gt.graph_draw(g, pos=g.vp["pos"],
vertex_fill_color=pr,
vertex_size=gt.prop_to_size(pr,
mi=5,
ma=15),
vorder=pr,
vcmap=matplotlib.cm.gist_heat,
bg_color=[1,1,1,1]);

import graph_tool.all as gt
g = gt.collection.data["polblogs"]
g = gt.GraphView(g, directed=False)
gt.remove_parallel_edges(g)
g = gt.extract_largest_component(g)
s = g.vp.value.t(lambda x: 2 * x - 1)
state = gt.IsingGlauberState(g, s=s, beta=.1)
state.iterate_async(niter=1000 * g.num_vertices())
gt.graph_draw(g, g.vp.pos,
vertex_fill_color=state.s,
bg_color=[1,1,1,1]);

import graph_tool.all as gt
from numpy.random import random
from scipy.linalg import norm
points = random((500, 2)) * 4
g, pos = gt.triangulation(points, type="delaunay")
weight = g.new_edge_property("double")
for e in g.edges():
weight[e] = norm(pos[e.source()].a -
pos[e.target()].a)
b = gt.betweenness(g, weight=weight)
gt.graph_draw(g, pos=pos, vertex_fill_color=b[0],
edge_pen_width=b[1].t(lambda x: x*120),
bg_color=[1,1,1,1]);

import graph_tool.all as gt
g = gt.collection.data["polblogs"]
g = gt.extract_largest_component(g, prune=True)
state = gt.minimize_blockmodel_dl(g)
u = gt.generate_sbm(state.b.a,
gt.adjacency(state.get_bg(),
state.get_ers()).T,
g.degree_property_map("out").a,
g.degree_property_map("in").a,
directed=True)
gt.graph_draw(u, g.vp.pos, bg_color=[1,1,1,1]);
Features at a glance
Version 4.0 is a major release that adds hundreds of new functions: the new structure module (which replaces topology) with algorithms for cliques, coloring, matchings and covers, chordal graphs, d-separation, graph polynomials and isomorphism; dozens of new random graph models; new centralities, connectivity and flow algorithms; the map equation, hierarchical random graphs and semi-supervised vertex classification for inference; magnetic and directed Laplacians; 22 new layout algorithms; new file formats; and parallelism in many more places. See the changelog for details.
More than 600 documented functions and classes, covering:
Graph data structure: directed and undirected graphs, vertex, edge and graph property maps of any type, graph views and filtering at no cost, and fast array-based iteration.
Input and output: the
gtbinary format, GraphML, GML, Graphviz DOT, GEXF, Pajek, JSON (node-link, Cytoscape, tree and adjacency), Matrix Market, graph6, sparse6 and digraph6, METIS, DIMACS (edge and maximum flow), LEDA, UCINET DL, LGL and NCOL, GraphDB, edge lists, adjacency lists, CSV and network text, as well as pickling, and direct loading from Netzschleuder (seeload_graph()for the complete list).Graph structure: shortest paths and distances, connected components, k-core and truss decompositions, cuts and expansion, spanning trees, DAGs, cliques, matchings, independent sets and covers, coloring, chordal graphs and treewidth, planarity, isomorphism and subgraph isomorphism, and Tutte and chromatic polynomials.
Centrality: PageRank, betweenness, closeness, eigenvector, Katz, HITS, current-flow, group and load centralities, communicability, structural holes, trophic levels and more.
Clustering and motifs: local and global clustering coefficients, motif counting and significance, triad and dyad census, and bipartite measures.
Network flows: maximum flow, minimum cuts, minimum-cost flow, Gomory-Hu trees, vertex and edge connectivity, and k-components.
Statistics and correlations: degree and property histograms, distance histograms, assortativity, degree correlations and rich-club coefficients.
Spectral analysis: adjacency, Laplacian, incidence, transition, non-backtracking, magnetic and directed Laplacian matrices, as sparse matrices or matrix-free operators, as well as spectral embedding and clustering.
Random graph generation: stochastic block models, configuration models, growing and geometric models, random trees, bipartite graphs, graph transformations and set operations, and named deterministic graphs.
Statistical inference: stochastic block model variants for community detection, network reconstruction, the map equation, hierarchical random graphs, and partition comparison.
Dynamical processes: epidemic models (SI, SIS, SIR, SIRS), Ising, Potts, voter, Kuramoto and Lotka-Volterra models, and belief propagation.
Visualization: 29 layout algorithms, static output to PNG, PDF, SVG and PostScript via cairo, interactive windows via GTK, animations, matplotlib integration, and an interface to graphviz (see the drawing tutorial).