Need help with python-louvain?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

674 Stars 166 Forks Other 103 Commits 23 Opened issues


Louvain Community Detection

Services available


Need anything else?

Contributors list

Louvain Community Detection

.. image:: :target:

.. image:: :target: :alt: Documentation Status


To build and install from source, run

.. code-block:: shell

python install

You can also install from pip with

.. code-block:: shell

pip install python-louvain

The package name on pip is :code:

but it is imported as :code:
in python. More documentation for this module can be found at 


To use as a Python library

.. code-block:: python

import community as community_louvain
import as cm
import matplotlib.pyplot as plt
import networkx as nx

load the karate club graph

G = nx.karate_club_graph()

compute the best partition

partition = community_louvain.best_partition(G)

draw the graph

pos = nx.spring_layout(G)

color the nodes according to their partition

cmap = cm.get_cmap('viridis', max(partition.values()) + 1) nx.draw_networkx_nodes(G, pos, partition.keys(), node_size=40, cmap=cmap, node_color=list(partition.values())) nx.draw_networkx_edges(G, pos, alpha=0.5)

It can also be run on the command line

.. code-block:: bash

 $ community 

where :code:

is a binary file as generated by the convert utility distributed with the C implementation at 
_ However as this is mostly for debugging purposes its use should be avoided. Instead importing this library for use in Python is recommended.


You can find documentation at 

To generate documentation, run

.. code-block:: shell

 pip install numpydoc sphinx
 cd docs


To run tests, run

.. code-block:: shell

 pip install nose
 python test

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.