Skip to content
Louvain Community Detection
Branch: master
Clone or download
Thomas Aynaud
Thomas Aynaud Update release readme
Latest commit 381b7db Dec 21, 2018


Louvain Community Detection


To build and install run from source:

python install

You can also install from pip with:

pip install python-louvain

The package name on pip is python-louvain but it is imported as community in python. You will find documentation about this module at


To use as a python library:

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

# Replace this with your networkx graph loading depending on your format !
G = nx.erdos_renyi_graph(30, 0.05)

#first compute the best partition
partition = community.best_partition(G)

size = float(len(set(partition.values())))
pos = nx.spring_layout(G)
count = 0.
for com in set(partition.values()) :
    count = count + 1.
    list_nodes = [nodes for nodes in partition.keys()
                                if partition[nodes] == com]
    nx.draw_networkx_nodes(G, pos, list_nodes, node_size = 20,
                                node_color = str(count / size))

nx.draw_networkx_edges(G, pos, alpha=0.5)

There is also a command line:

$ community <filename>

filename is a binary file as generated by the convert utility distributed with the C implementation at This is mostly for debugging purpose and I advise to use this module more as a library with your graph loading code than with this command.


You can find documentation at

To generate documentation run:

pip install numpydoc sphinx
cd docs


To run tests:

pip install nose
python test Documentation Status
You can’t perform that action at this time.