or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

analysis.mdclustering.mdcommunity.mddata-types.mdgraph-creation.mdgraph-structure.mdindex.mdio-formats.mdlayout.mdsequences.mdvisualization.md
tile.json

tessl/pypi-igraph

High performance graph data structures and algorithms for Python

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/igraph@0.11.x

To install, run

npx @tessl/cli install tessl/pypi-igraph@0.11.0

index.mddocs/

Python igraph

A comprehensive Python library for creating, manipulating, and analyzing graphs and networks. igraph provides powerful tools for graph theory, network analysis, community detection, and visualization with over 264 public API symbols covering everything from basic graph operations to advanced algorithms.

Package Information

  • Package Name: igraph
  • Language: Python
  • Installation: pip install igraph
  • Dependencies: Optional Cairo (pycairo/cairocffi), matplotlib, plotly for visualization

Core Imports

import igraph

Common patterns for specific functionality:

from igraph import Graph
import igraph as ig

For visualization:

from igraph import plot
from igraph.drawing import Palette

Basic Usage

import igraph as ig

# Create a simple graph
g = ig.Graph(edges=[(0, 1), (1, 2), (2, 0), (2, 3)], directed=False)

# Add vertex and edge attributes
g.vs["name"] = ["Alice", "Bob", "Carol", "Dave"] 
g.es["weight"] = [1, 2, 3, 1]

# Basic graph properties
print(f"Vertices: {g.vcount()}")  # 4
print(f"Edges: {g.ecount()}")    # 4
print(f"Directed: {g.is_directed()}")  # False

# Graph analysis
betweenness = g.betweenness()
clustering = g.community_leiden()
layout = g.layout_fruchterman_reingold()

# Visualization (requires Cairo or matplotlib)
ig.plot(g, vertex_label=g.vs["name"], 
        vertex_color=clustering.membership,
        layout=layout)

Architecture

The igraph library follows a layered architecture designed for flexibility and performance:

  • Core Graph Classes: Graph, Vertex, Edge form the foundation for all graph operations
  • Sequence Classes: VertexSeq, EdgeSeq provide efficient access to collections of vertices/edges
  • Analysis Layer: Comprehensive algorithms for centrality, community detection, pathfinding
  • Data Structures: Matrix, Layout, clustering objects for specialized operations
  • Visualization Layer: Multiple backends (Cairo, matplotlib, plotly) for graph drawing
  • I/O Layer: Support for numerous graph file formats and data interchange

This design enables igraph to serve as both a high-level tool for network analysis and a foundation for specialized graph applications, with seamless integration into the Python scientific ecosystem.

Capabilities

Graph Creation and Generation

Methods for creating graphs from various sources including edge lists, adjacency matrices, classic graph families, and random graph models.

class Graph:
    def __init__(n=0, edges=None, directed=False, **attrs): ...
    @classmethod
    def Full(cls, n, directed=False, loops=False): ...
    @classmethod
    def Ring(cls, n, directed=False, mutual=False, circular=True): ...
    @classmethod
    def Tree(cls, n, children=2, mode=TREE_UNDIRECTED): ...
    @classmethod  
    def Erdos_Renyi(cls, n, m=None, p=None, directed=False, loops=False): ...
    @classmethod
    def Barabasi(cls, n, m=1, directed=False): ...

Graph Creation

Graph Structure Manipulation

Core operations for adding, removing, and modifying vertices and edges, plus basic graph properties and transformations.

class Graph:
    def add_vertex(self, name=None, **attrs): ...
    def add_vertices(self, n, attrs=None): ...
    def add_edge(self, source, target, **attrs): ...
    def add_edges(self, edges, attrs=None): ...
    def delete_vertices(self, vertices): ...
    def delete_edges(self, edges): ...
    def vcount(self): ...
    def ecount(self): ...
    def is_directed(self): ...

Graph Structure

Graph Analysis

Comprehensive analysis algorithms including centrality measures, shortest paths, connectivity analysis, and structural properties.

class Graph:
    def betweenness(self, vertices=None, directed=True, weights=None): ...
    def closeness(self, vertices=None, mode=ALL, weights=None): ...
    def pagerank(self, vertices=None, directed=True, weights=None): ...
    def shortest_paths(self, source=None, target=None, weights=None): ...
    def diameter(self, directed=True, weights=None): ...
    def is_connected(self, mode=WEAK): ...

Analysis

Community Detection

Advanced community detection algorithms for identifying groups and clusters within networks.

class Graph:
    def community_leiden(self, weights=None, resolution=1.0, **kwargs): ...
    def community_multilevel(self, weights=None, resolution=1.0): ...
    def community_infomap(self, edge_weights=None, vertex_weights=None): ...
    def community_walktrap(self, weights=None, steps=4): ...
    def community_edge_betweenness(self, weights=None, directed=True): ...
    def community_fastgreedy(self, weights=None): ...
    def community_label_propagation(self, weights=None, initial=None, fixed=None): ...
    def community_leading_eigenvector(self, clusters=None, weights=None): ...
    def community_spinglass(self, weights=None, spins=25, **kwargs): ...
    def community_optimal_modularity(self): ...

Community Detection

Layout Algorithms

Graph layout and positioning algorithms for visualization and spatial analysis.

class Graph:
    def layout_fruchterman_reingold(self, weights=None, dim=2, **kwargs): ...
    def layout_kamada_kawai(self, weights=None, dim=2, **kwargs): ...
    def layout_drl(self, weights=None, dim=2, **kwargs): ...
    def layout_circle(self, order=None): ...
    def layout_grid(self, width=0, dim=2): ...
    def layout_sugiyama(self, layers=None, weights=None, **kwargs): ...
    def layout_fruchterman_reingold_3d(self, **kwargs): ...
    def layout_kamada_kawai_3d(self, **kwargs): ...
    def layout_random_3d(self, **kwargs): ...
    def layout_grid_3d(self, **kwargs): ...
    def layout_sphere(self): ...

Layout

Visualization and Drawing

Multi-backend visualization system supporting Cairo, matplotlib, and plotly for creating publication-quality graph visualizations.

def plot(obj, target=None, bbox=(0,0,600,600), **kwds): ...

class Plot:
    def __init__(self, bbox=(0,0,600,600), palette=None): ...
    def save(self, fname=None): ...

class Palette:
    def get(self, index): ...

Visualization

File I/O and Formats

Comprehensive support for reading and writing graphs in various formats including GraphML, GML, Pajek, DIMACS, and more.

class Graph:
    @classmethod
    def Read(cls, filename, format=None, **kwargs): ...
    def write(self, filename, format=None, **kwargs): ...
    def to_networkx(self): ...
    @classmethod
    def from_networkx(cls, graph): ...

I/O and Formats

Clustering Objects

Specialized classes for representing and manipulating clustering results from community detection algorithms.

class Clustering:
    def size(self, idx): ...
    def sizes(self): ...
    def compare_to(self, other, method="vi"): ...

class VertexClustering(Clustering):
    @classmethod
    def FromAttribute(cls, graph, attribute): ...
    def modularity(self): ...
    def crossing(self): ...

Clustering

Vertex and Edge Sequences

Efficient sequence classes for accessing and manipulating collections of vertices and edges with filtering and attribute operations.

class VertexSeq:
    def select(self, *args, **kwargs): ...
    def find(self, *args, **kwargs): ...
    def attributes(self): ...

class EdgeSeq: 
    def select(self, *args, **kwargs): ...
    def find(self, *args, **kwargs): ...
    def attributes(self): ...

Sequences

Core Data Types

Essential data structures including matrices, layouts, and utility classes that support graph operations and analysis.

class Matrix:
    @classmethod
    def Fill(cls, value, shape): ...
    @classmethod
    def Zero(cls, shape): ...
    @classmethod
    def Identity(cls, shape): ...

class Layout:
    def mirror(self, dim): ...
    def rotate(self, angle, dim1=0, dim2=1): ...
    def scale(self, *args): ...

Data Types