Skip to main content

Graph Signal Processing in Python

Project description

The PyGSP is a Python package to ease Signal Processing on Graphs. The documentation is available on Read the Docs and development takes place on GitHub. A (mostly unmaintained) Matlab version exists.

doc pypi conda binder

zenodo license pyversions

ci coveralls github

The PyGSP facilitates a wide variety of operations on graphs, like computing their Fourier basis, filtering or interpolating signals, plotting graphs, signals, and filters. Its core is spectral graph theory, and many of the provided operations scale to very large graphs. The package includes a wide range of graphs, from point clouds like the Stanford bunny and the Swiss roll; to networks like the Minnesota road network; to models for generating random graphs like stochastic block models, sensor networks, Erdős–Rényi model, Barabási-Albert model; to simple graphs like the path, the ring, and the grid. Many filter banks are also provided, e.g. various wavelets like the Mexican hat, Meyer, Half Cosine; some low-pass filters like the heat kernel and the exponential window; and Gabor filters. Despite all the pre-defined models, you can easily use a custom graph by defining its adjacency matrix, and a custom filter bank by defining a set of functions in the spectral domain.

While NetworkX and graph-tool are tools to analyze the topology of graphs, the aim of the PyGSP is to analyze graph signals, also known as features or properties (i.e., not the graph itself). Those three tools are complementary and work well together with the provided import / export facility.

The following demonstrates how to instantiate a graph and a filter, the two main objects of the package.

>>> from pygsp import graphs, filters
>>> G = graphs.Logo()
>>> G.compute_fourier_basis()  # Fourier to plot the eigenvalues.
>>> # G.estimate_lmax() is otherwise sufficient.
>>> g = filters.Heat(G, scale=50)
>>> fig, ax = g.plot()

Let’s now create a graph signal: a set of three Kronecker deltas for that example. We can now look at one step of heat diffusion by filtering the deltas with the above defined filter. Note how the diffusion follows the local structure!

>>> import numpy as np
>>> DELTAS = [20, 30, 1090]
>>> s = np.zeros(G.N)
>>> s[DELTAS] = 1
>>> s = g.filter(s)
>>> fig, ax = G.plot(s, highlight=DELTAS)

You can try it online, look at the tutorials to learn how to use it, or look at the reference guide for an exhaustive documentation of the API. Enjoy!

Installation

The PyGSP is available on PyPI:

$ pip install pygsp

For faster installation with modern dependency resolution, use uv:

$ uv add pygsp

The PyGSP is available on conda-forge:

$ conda install -c conda-forge pygsp

The PyGSP is available in the Arch User Repository:

$ git clone https://aur.archlinux.org/python-pygsp.git
$ cd python-pygsp
$ makepkg -csi

Optional Dependencies

graph-tool (optional)

graph-tool is an optional dependency that enables import/export functionality with the graph-tool library. PyGSP works perfectly without it - it’s only needed if you want to use Graph.to_graphtool() or Graph.from_graphtool() methods.

Installation:

  • macOS (with Homebrew):

    $ brew install graph-tool
  • Ubuntu/Debian:

    $ sudo apt-get install python3-graph-tool
  • conda (recommended for cross-platform):

    $ conda install -c conda-forge graph-tool

Note: graph-tool cannot be installed via pip or uv due to its complex system dependencies. If not installed, related tests will be automatically skipped and the library will function normally without import/export capabilities to graph-tool format.

FLANN (optional)

FLANN (Fast Library for Approximate Nearest Neighbors) is an optional dependency that provides faster nearest neighbor searches for large datasets. PyGSP works without it, but FLANN can significantly speed up k-NN graph construction.

Installation:

  • macOS (with Homebrew):

    $ brew install flann
    $ export DYLD_LIBRARY_PATH="$(brew --prefix)/lib:${DYLD_LIBRARY_PATH}"
    # Optional: persist in your shell rc file (.zshrc, .bash_profile, etc.)
    $ echo 'export DYLD_LIBRARY_PATH="$(brew --prefix)/lib:${DYLD_LIBRARY_PATH}"' >> ~/.zshrc
  • Ubuntu/Debian:

    $ sudo apt-get install libflann-dev
  • conda (recommended for cross-platform):

    $ conda install -c conda-forge flann

After system installation, install the Python bindings:

$ uv add pyflann3
# or
$ pip install pyflann3

Note: pyflann3 requires the FLANN system library to be installed first. If not available, PyGSP will automatically fall back to scikit-learn’s NearestNeighbors (if available), then to SciPy’s KDTree implementation. This multi-level fallback ensures robust k-NN graph construction even when FLANN is not properly configured.

Contributing

See the guidelines for contributing in CONTRIBUTING.rst.

Development Setup

For development, we recommend using uv for fast and reliable dependency management:

  1. Clone the repository:

    $ git clone https://github.com/epfl-lts2/pygsp.git
    $ cd pygsp
  2. Set up development environment:

    $ uv venv
    $ source .venv/bin/activate  # On Windows: .venv\Scripts\activate
    $ uv pip install -e ".[dev]"
  3. Run tests:

    $ pytest
  4. Run linting:

    $ flake8 pygsp/
  5. Build documentation:

    $ cd doc && make html

The project uses pyproject.toml for modern Python packaging and includes all development dependencies like pytest, flake8, sphinx, matplotlib, and networkx.

Acknowledgments

The PyGSP was started in 2014 as an academic open-source project for research purpose at the EPFL LTS2 laboratory. This project has been partly funded by the Swiss National Science Foundation under grant 200021_154350 “Towards Signal Processing on Graphs”.

It is released under the terms of the BSD 3-Clause license.

If you are using the library for your research, for the sake of reproducibility, please cite the version you used as indexed by Zenodo. Or cite the generic concept as:

@misc{pygsp,
  title = {PyGSP: Graph Signal Processing in Python},
  author = {Defferrard, Micha\"el and Martin, Lionel and Pena, Rodrigo and Perraudin, Nathana\"el},
  doi = {10.5281/zenodo.1003157},
  url = {https://github.com/epfl-lts2/pygsp/},
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pygsp-0.6.0.tar.gz (1.8 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pygsp-0.6.0-py3-none-any.whl (1.9 MB view details)

Uploaded Python 3

File details

Details for the file pygsp-0.6.0.tar.gz.

File metadata

  • Download URL: pygsp-0.6.0.tar.gz
  • Upload date:
  • Size: 1.8 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.6

File hashes

Hashes for pygsp-0.6.0.tar.gz
Algorithm Hash digest
SHA256 5535256fa266a869d16599f1632610c46a3385d6f3b26278cdc7b37d919a7e7d
MD5 c0ad3e1ab81398f975c9c74e8e2f1b09
BLAKE2b-256 b0e5fbb524db635310da1b7f8c06c6fe6b7906a4cc6edcf029dc97a3554df8ae

See more details on using hashes here.

File details

Details for the file pygsp-0.6.0-py3-none-any.whl.

File metadata

  • Download URL: pygsp-0.6.0-py3-none-any.whl
  • Upload date:
  • Size: 1.9 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.6

File hashes

Hashes for pygsp-0.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 766191c6b6bac7aa931e18d7e39304946caebfe210fc114c6c9114999858e334
MD5 ffa49245d4b22584556752c05f29d1fc
BLAKE2b-256 007efbc54c33b268cbe2deb55766afb6ca3f0d5c1089f0cefa2708d1e2f051d6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page