skillfed

segregation

Analytics for spatial and non-spatial segregation in Python.

segregation v2.5.5 150.7K downloads/30d#10,956 on PyPI121
Permissive license BSD 3-Clause Active released

What it is and what it does

Segregation is a PySAL package for quantifying and analyzing patterns of urban segregation using demographic data. It implements a large suite of segregation indices—ranging from classic measures like dissimilarity and isolation to modern spatial variants—and wraps them as classes that accept a pandas or geopandas DataFrame, a group-of-interest column, and a total-population column to produce point estimates. Beyond calculation, the package provides statistical inference (testing whether estimates are significant or comparing two estimates) and decomposition (breaking differences into spatial-structure and demographic-structure components).

The package is built on a stack of geospatial and scientific Python libraries: geopandas for geometry handling, scikit-learn and scipy for statistical methods, numba for numerical acceleration, and joblib for parallelization. It targets researchers and practitioners analyzing residential patterns, income distribution, or other demographic segregation in urban areas. Spatial indices can use PySAL weights matrices, Euclidean distances, or topological relationships, giving users fine control over how distance and adjacency are defined.

Use it for:

  • Calculate dissimilarity or isolation indices to measure how evenly a demographic group is distributed across neighborhoods.
  • Compare segregation levels between two cities or time periods using inference tests to determine statistical significance.
  • Decompose changes in segregation into components driven by shifts in spatial structure versus demographic composition.
  • Compute local segregation indices to identify neighborhoods with high or low segregation relative to the city overall.
  • Analyze segregation using multiscalar definitions or distance-decay models to understand patterns at different geographic scales.

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

Calculates over 40 segregation indices—both aspatial and spatial—to measure patterns of urban segregation, and tests their statistical significance and decomposes differences into spatial and demographic components.

Yes. The package is actively maintained, has no known vulnerabilities, and fills a specialized but well-defined niche in spatial demographic analysis. Low install friction and a permissive license make adoption straightforward. Install it if you need to compute segregation indices or test segregation hypotheses; skip it if your work does not involve demographic or residential segregation measurement.

Install

segregation on PyPI

pip

pip install segregation

uv

uv add segregation

poetry

poetry add segregation

Installing segregation

Before you install

Low friction installation with a pure-Python wheel. Active maintenance—last commit 2026-08-07, released 2026-06-18. Requires Python 3.12 or later. Pulls in 13 runtime dependencies including geopandas, scikit-learn, and scipy, which may add setup time in constrained environments.

License in practice

BSD 3-Clause permissive license allows commercial and private use with minimal restrictions; you must retain the license and copyright notice.

Quickstart

pip install segregation

from segregation.aspatial import Dissim
import pandas as pd

df = pd.DataFrame({"group_pop": ["values"], "total_pop": ["values"]})
index = Dissim(df, "group_pop", "total_pop")
print(index.statistic)

Requires Python 3.12 or later. For spatial indices, input must be a geopandas.GeoDataFrame with a geometry column.

Verify before relying

  • Whether all 40+ segregation measures are equally well-maintained and documented.
  • Performance characteristics when working with large datasets or many spatial weights matrices.
  • Whether the package supports integration with external spatial network objects beyond PySAL weights.

Package facts

License BSD 3-Clause (permissive)
Python support supports the current Python release (>=3.12)
Install friction low — pure-Python wheel
Runtime dependencies 13 — geopandas, joblib, libpysal, mapclassify, matplotlib, numba, numpy, pandas, pyproj, scikit-learn, scipy, seaborn, tqdm
Maintenance actively maintained — 57 days since the last release
Last repo commit
First released
Downloads 150,740/month — #10,956 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: segregation-2.5.5-py3-none-any.whl

Keywords: segregation, spatial analysis, demographics, population

Intended Audience :: Science/ResearchLicense :: OSI Approved :: BSD LicenseOperating System :: OS IndependentProgramming Language :: Python :: 3Topic :: Scientific/Engineering :: GIS

Tags

segregation indices calculationurban segregation analysisspatial segregation measuresdemographic segregation metricsdissimilarity index computationsegregation inference testingspatial demographics analysis
spatial-analysisdemographicssegregation-indices

More GIS packages