Skip to main content

This package implements the Leiden algorithm in C++ and exposes it to python. It relies on (python-)igraph for it to function. Besides the relative flexibility of the implementation, it also scales well, and can be run on graphs of millions of nodes (as long as they can fit in memory). The core function is find_partition which finds the optimal partition using the Leiden algorithm [1], which is an extension of the Louvain algorithm [2] for a number of different methods. The methods currently implemented are (1) modularity [3], (2) Reichardt and Bornholdt’s model using the configuration null model and the Erdös-Rényi null model [4], (3) the Constant Potts model (CPM) [5], (4) Significance [6], and finally (5) Surprise [7]. In addition, it supports multiplex partition optimisation allowing community detection on for example negative links [8] or multiple time slices [9]. There is the possibility of only partially optimising a partition, so that some community assignments remain fixed [10]. It also provides some support for community detection on bipartite graphs. See the documentation for more information.

Leiden documentation status Leiden build status (GitHub Actions) DOI Anaconda (conda-forge)

Installation

In short: pip install leidenalg. All major platforms are supported on Python>=3.9, earlier versions of Python are no longer supported. Alternatively, you can install from Anaconda (channel conda-forge).

For Unix like systems it is possible to install from source. For Windows this is more complicated, and you are recommended to use the binary wheels. This Python interface depends on the C++ package libleidenalg which in turn depends on igraph. You will need to build these packages yourself before you are able to build this Python interface.

Make sure you have all necessary tools for compilation. In Ubuntu this can be installed using sudo apt-get install build-essential autoconf automake flex bison, please refer to the documentation for your specific system. Make sure that not only gcc is installed, but also g++, as the leidenalg package is programmed in C++. Note that there are build scripts included in the scripts/ directory. These are also used to build the binary wheels.

  1. Compile (and install) the C core of igraph (version >= 1.0.0). You can use the file build_igraph.sh (on Unix-like systems) or build_igraph.bat (on Windows) in the scripts/ directory to do this. For more details, see https://igraph.org/c/doc/igraph-Installation.html.

  2. Compile (and install) the C core of libleidenalg (version >= 0.12). You can use the file build_libleidenalg.sh (on Unix-like systems) or build_libleidenalg.bat (on Windows) in the scripts/ directory to do this. For more details, see https://github.com/vtraag/libleidenalg.

  3. Build the Python interface using python setup.py build and python setup.py install, or use pip install .

You can check if all went well by running a variety of tests using python -m unittest.

Troubleshooting

In case of any problems, best to start over with a clean environment. Make sure you remove the igraph and leidenalg package completely. Then, do a complete reinstall starting from pip install leidenalg. In case you installed from source, and built the C libraries of igraph and libleidenalg yourself, remove them completely and rebuild and reinstall them.

Usage

This is the Python interface for the C++ package libleidenalg. There are no plans at the moment for developing an R interface to the package. However, there have been various efforts to port the package to R. These typically do not offer all available functionality or have some other limitations, but nonetheless may be very useful. The available ports are:

Please refer to the documentation for more details on function calls and parameters.

This implementation is made for flexibility, but igraph nowadays also includes an implementation of the Leiden algorithm internally. That implementation is less flexible: the implementation only works on undirected graphs, and only CPM and modularity are supported. It is likely to be substantially faster though.

Just to get you started, below the essential parts. To start, make sure to import the packages:

>>> import leidenalg
>>> import igraph as ig

We’ll create a random graph for testing purposes:

>>> G = ig.Graph.Erdos_Renyi(100, 0.1);

For simply finding a partition use:

>>> part = leidenalg.find_partition(G, leidenalg.ModularityVertexPartition);

Contribute

Source code: https://github.com/vtraag/leidenalg

Issue tracking: https://github.com/vtraag/leidenalg/issues

See the documentation on Implementation for more details on how to contribute new methods.

References

Please cite the references appropriately in case they are used.

Licence

Copyright (C) 2020 V.A. Traag

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Metadata

Release files for leidenalg 0.12.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for leidenalg 0.12.0
File Size Uploaded
leidenalg-0.12.0.tar.gz 453.6 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for leidenalg 0.12.0
File
leidenalg-0.12.0-pp311-pypy311_pp73-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl PyPy 3.11 PyPy 3.11 7.3 Linux glibc 2.28+ x86-64, Linux glibc 2.27+ x86-64 Details
leidenalg-0.12.0-pp311-pypy311_pp73-manylinux_2_26_i686.manylinux_2_28_i686.whl PyPy 3.11 PyPy 3.11 7.3 Linux glibc 2.26+ x86-32, Linux glibc 2.28+ x86-32 Details
leidenalg-0.12.0-pp311-pypy311_pp73-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl PyPy 3.11 PyPy 3.11 7.3 Linux glibc 2.28+ ARM64, Linux glibc 2.26+ ARM64 Details
leidenalg-0.12.0-pp311-pypy311_pp73-macosx_11_0_arm64.whl PyPy 3.11 PyPy 3.11 7.3 macOS 11.0+ ARM64 Details
leidenalg-0.12.0-pp311-pypy311_pp73-macosx_10_15_x86_64.whl PyPy 3.11 PyPy 3.11 7.3 macOS 10.15+ x86-64 Details
leidenalg-0.12.0-cp38-abi3-win_amd64.whl CPython 3.8 abi3 Windows x86-64 Details
leidenalg-0.12.0-cp38-abi3-win32.whl CPython 3.8 abi3 Windows x86-32 Details
leidenalg-0.12.0-cp38-abi3-musllinux_1_2_x86_64.whl CPython 3.8 abi3 Linux musl 1.2+ x86-64 Details
leidenalg-0.12.0-cp38-abi3-musllinux_1_2_i686.whl CPython 3.8 abi3 Linux musl 1.2+ x86-32 Details
leidenalg-0.12.0-cp38-abi3-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl CPython 3.8 abi3 Linux glibc 2.27+ x86-64, Linux glibc 2.28+ x86-64 Details
leidenalg-0.12.0-cp38-abi3-manylinux_2_26_i686.manylinux_2_28_i686.whl CPython 3.8 abi3 Linux glibc 2.28+ x86-32, Linux glibc 2.26+ x86-32 Details
leidenalg-0.12.0-cp38-abi3-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl CPython 3.8 abi3 Linux glibc 2.26+ ARM64, Linux glibc 2.28+ ARM64 Details
leidenalg-0.12.0-cp38-abi3-macosx_11_0_arm64.whl CPython 3.8 abi3 macOS 11.0+ ARM64 Details
leidenalg-0.12.0-cp38-abi3-macosx_10_9_x86_64.whl CPython 3.8 abi3 macOS 10.9+ x86-64 Details

Total release size: 36.1 MB

Release files / leidenalg-0.12.0.tar.gz

Download URL leidenalg-0.12.0.tar.gz
Size 453.6 kB
Tags Source
SHA-256 checksum
How to use checksums
c81a45a2fb874fe71e903d43a869d0efeb7f907af70476c03f6945ef0e8f44c5
BLAKE2b-256 checksum
How to use checksums
82b745bae25ab59321a14902bec2f47e32b92e76f8b4b3887a13ee69a0b32c60
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.12

Release files / leidenalg-0.12.0-pp311-pypy311_pp73-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl

Download URL leidenalg-0.12.0-pp311-pypy311_pp73-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Size 2.6 MB
Tags Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64 PyPy 3.11 PyPy 3.11 7.3
SHA-256 checksum
How to use checksums
43176c9470648098f6b642a6e070a12e65ef347700059da9132fefdf98e70df9
BLAKE2b-256 checksum
How to use checksums
45c05b5afcd49d49b2b249e6326d991ab3e74d5603ef917bdd9f283a6cf9cfa9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.12

Release files / leidenalg-0.12.0-pp311-pypy311_pp73-manylinux_2_26_i686.manylinux_2_28_i686.whl

Download URL leidenalg-0.12.0-pp311-pypy311_pp73-manylinux_2_26_i686.manylinux_2_28_i686.whl
Size 2.7 MB
Tags Linux glibc 2.26+ x86-32 Linux glibc 2.28+ x86-32 PyPy 3.11 PyPy 3.11 7.3
SHA-256 checksum
How to use checksums
b213229d8aa2708117642b478d5b51cae2cfeddf9d80aa98667fe7260119c3ee
BLAKE2b-256 checksum
How to use checksums
fe14f18249ee7f94f3c15066c4b2fb207236c0908ebea61252b5f10d131cffda
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.12

Release files / leidenalg-0.12.0-pp311-pypy311_pp73-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl

Download URL leidenalg-0.12.0-pp311-pypy311_pp73-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl
Size 2.4 MB
Tags Linux glibc 2.26+ ARM64 Linux glibc 2.28+ ARM64 PyPy 3.11 PyPy 3.11 7.3
SHA-256 checksum
How to use checksums
ecf067611776bf3acf33afcd1ecd8a381f67ab664c14e9530dd63eef0da646f8
BLAKE2b-256 checksum
How to use checksums
22f06839fb4a5de5892fbd47abaf6c9afe09d525eeabe6973e0bc1e731dd651c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.12

Release files / leidenalg-0.12.0-pp311-pypy311_pp73-macosx_11_0_arm64.whl

Download URL leidenalg-0.12.0-pp311-pypy311_pp73-macosx_11_0_arm64.whl
Size 1.9 MB
Tags PyPy 3.11 PyPy 3.11 7.3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
65466be8f6b14117cc285d4d785bedec8fc6792c48cf89a3df3551dba36fb782
BLAKE2b-256 checksum
How to use checksums
7bd382f79c7615a5787737c4d11443afbdbbfcd6f9d6e304f767966954dd83d4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.12

Release files / leidenalg-0.12.0-pp311-pypy311_pp73-macosx_10_15_x86_64.whl

Download URL leidenalg-0.12.0-pp311-pypy311_pp73-macosx_10_15_x86_64.whl
Size 2.3 MB
Tags PyPy 3.11 PyPy 3.11 7.3 macOS 10.15+ x86-64
SHA-256 checksum
How to use checksums
b48e26f746b3f3cee49d609f42b0eb4c3e80a174e16d13c6e371d9a555c93419
BLAKE2b-256 checksum
How to use checksums
d1c7a6433027c603b97cba5748a5f00ff10aaaefcfdea46a9fc0e3f0f733591a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.12

Release files / leidenalg-0.12.0-cp38-abi3-win_amd64.whl

Download URL leidenalg-0.12.0-cp38-abi3-win_amd64.whl
Size 2.0 MB
Tags CPython 3.8 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
f5d9529b44d5f6add0847d68fa6ced99f581357f6ca02b54c049eb3a2f45ff04
BLAKE2b-256 checksum
How to use checksums
ea770c8fb67729e83bddd43971cd4851f497a96810fca63f8029e3f008e82b1b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.12

Release files / leidenalg-0.12.0-cp38-abi3-win32.whl

Download URL leidenalg-0.12.0-cp38-abi3-win32.whl
Size 1.7 MB
Tags CPython 3.8 Windows x86-32 abi3
SHA-256 checksum
How to use checksums
283cd987623e2c5e7b11ed3f15b7805d597a934bf387a7e820d2f673001b635f
BLAKE2b-256 checksum
How to use checksums
d135f4f07ddac6718a11c70d858fd4afcc849ca84f485b5d7092bcf09492ec06
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.12

Release files / leidenalg-0.12.0-cp38-abi3-musllinux_1_2_x86_64.whl

Download URL leidenalg-0.12.0-cp38-abi3-musllinux_1_2_x86_64.whl
Size 3.8 MB
Tags CPython 3.8 Linux musl 1.2+ x86-64 abi3
SHA-256 checksum
How to use checksums
63b49f5716c7cb155f3a3e25505bcc33f3c8c62105734fc152bc07518e63e9ab
BLAKE2b-256 checksum
How to use checksums
05e52f3322376fddd6b85790eaddcd314c9402bf81e984b35870acb4cfcbd0e1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.12

Release files / leidenalg-0.12.0-cp38-abi3-musllinux_1_2_i686.whl

Download URL leidenalg-0.12.0-cp38-abi3-musllinux_1_2_i686.whl
Size 4.1 MB
Tags CPython 3.8 Linux musl 1.2+ x86-32 abi3
SHA-256 checksum
How to use checksums
c6a6231d3db490ee3cc4004f214b0bb947dc3fabde75bd61d878bc3fb9685d06
BLAKE2b-256 checksum
How to use checksums
e10222597cf6d7ee093523ad5885a31499d698812db5744d98086383c3da08b5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.12

Release files / leidenalg-0.12.0-cp38-abi3-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl

Download URL leidenalg-0.12.0-cp38-abi3-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Size 2.7 MB
Tags CPython 3.8 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64 abi3
SHA-256 checksum
How to use checksums
fcbd89655243cc739d28ba23fe894587d8d7235124a9248ba375819585e70090
BLAKE2b-256 checksum
How to use checksums
f7bedba31e662c2ee028e20dd0308c1bc6e398dd7a1786fdd0821722537b4124
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.12

Release files / leidenalg-0.12.0-cp38-abi3-manylinux_2_26_i686.manylinux_2_28_i686.whl

Download URL leidenalg-0.12.0-cp38-abi3-manylinux_2_26_i686.manylinux_2_28_i686.whl
Size 2.8 MB
Tags CPython 3.8 Linux glibc 2.26+ x86-32 Linux glibc 2.28+ x86-32 abi3
SHA-256 checksum
How to use checksums
78df2e463f3ffffffda590e9b0d790107e59f722f095731b78a58803d1ca92e5
BLAKE2b-256 checksum
How to use checksums
5f45cf5eb36b4517bb85397760a6033628695e8b0723b45f10f487b07cec84df
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.12

Release files / leidenalg-0.12.0-cp38-abi3-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl

Download URL leidenalg-0.12.0-cp38-abi3-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl
Size 2.5 MB
Tags CPython 3.8 Linux glibc 2.26+ ARM64 Linux glibc 2.28+ ARM64 abi3
SHA-256 checksum
How to use checksums
5f6a97f698f13a588e1ae7344908cddee9f87d33acc226fc5c5b99752ebd71f8
BLAKE2b-256 checksum
How to use checksums
cf367480eef0473bd87f69826e0dfb6bb1c1ee0915fa6d31be445d0bfcbd3a1a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.12

Release files / leidenalg-0.12.0-cp38-abi3-macosx_11_0_arm64.whl

Download URL leidenalg-0.12.0-cp38-abi3-macosx_11_0_arm64.whl
Size 1.9 MB
Tags CPython 3.8 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
2e0e1c2321c2e06a7f4f8a73ca15fcd54e0139a62afb448933c42badcfab8adc
BLAKE2b-256 checksum
How to use checksums
72f6d15c889c7c65dbc41c84fe83243c203b083f70cef62ed0acc630098b2012
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.12

Release files / leidenalg-0.12.0-cp38-abi3-macosx_10_9_x86_64.whl

Download URL leidenalg-0.12.0-cp38-abi3-macosx_10_9_x86_64.whl
Size 2.3 MB
Tags CPython 3.8 abi3 macOS 10.9+ x86-64
SHA-256 checksum
How to use checksums
96eec407f540d9ddb0c103dadc632d5519cfcdb39689fb21ae0ceeaa97bb2ec3
BLAKE2b-256 checksum
How to use checksums
537f0900c05ccbb27744f9dd11321dc2978e9f5ffe678db54f23eb94cf4e5951
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.12

Release history Release notifications | RSS feed

This release

0.12.0 This release

15 release files

0.9.1

52 release files

0.8.9

27 release files

0.8.8

27 release files

0.8.4

27 release files

0.8.3

26 release files

0.8.2

19 release files

0.8.1

21 release files

0.8.0

21 release files

0.7.0

3 release files

0.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page