netseg Documentation (Python)

netseg is a Python package for measuring segregation and structural polarization in social networks.

This package extends and complements the original netseg R package (Bojanowski & Corten, 2014; Bojanowski, 2025), which introduced the unified framework for measuring network segregation. The Python port and additional polarization measures were developed, with new features subsequently integrated into both packages.

It was developed to address several key gaps in the current Python ecosystem:

  • A Unified Framework: While analyzing network segregation and polarization is common, the myriad of existing measures makes cross-network comparisons exceedingly difficult. netseg provides a centralized toolkit for standardizing these measurements.

  • Extensively Documented: netseg is extensively documented. From various case by case usage examples to the advanced null-model selection, it offers a clear guide for your research.

  • Advanced Null-Model Comparison: Many existing approaches rely on purely random graphs to quantify excess polarization or segregation, a notoriously low baseline. netseg allows you to use customized network ensembles as null models, enabling robust, comparative segregation analysis.

  • Extensions and Improved Optimization netseg offers extensions for already existing measures, calculating the structural polarization and segregation in directed and undirected networks with multiple groups. netseg is build on igraph and NumPy , it offers near bare-metal speed with NumPy’s vectorization and igraph’s C backend.

Installation

You can install netseg from PyPI with

pip install netseg

or you can directly build from the source with (following will avoid assets, datasets and examples.)

git clone --filter=blob:none --sparse https://codeberg.org/OnurB/netseg.git
cd netseg
git sparse-checkout set src
pip install .

Support and Contact

If you come across any issues, please visit the repository page https://codeberg.org/OnurB/netseg. Suggestions & Discussions: bal_onur@phd.ceu.edu

netseg R package is maintained at https://mbojan.github.io/netseg/.