segregation
Analytics for spatial and non-spatial segregation in Python.
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 segregationuv
uv add segregationpoetry
poetry add segregationInstalling 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
Tags
More GIS packages
Shapely provides Python tools for creating,…
permissive · top 1,000 on PyPI
pyprojpyproj provides a Python interface to PROJ,…
permissive · top 1,000 on PyPI
geopandasGeoPandas extends pandas DataFrames to handle…
permissive · top 1,000 on PyPI
geopygeopy is a Python client for geocoding and…
permissive · top 5,000 on PyPI
pyogrioPyogrio provides fast, bulk-oriented read and…
permissive · top 5,000 on PyPI
h3h3 provides Python bindings to Uber's H3…
permissive · top 5,000 on PyPI
pysalPySAL is a meta-package that bundles 29 spatial…
permissive · top 15,000 on PyPI
inequalityInequality provides methods for measuring…
permissive · top 15,000 on PyPI
krippendorffComputes Krippendorff's alpha, a statistical…
copyleft · top 15,000 on PyPI
accessCalculates spatial accessibility metrics to…
permissive · top 15,000 on PyPI
esdaesda computes global and local spatial…
permissive · top 15,000 on PyPI
spatial-accessComputes travel times and spatial access…
permissive · top 15,000 on PyPI
momepyMomepy quantifies urban form through…
permissive · top 15,000 on PyPI
libpysallibpysal provides core spatial analysis…
permissive · top 15,000 on PyPI
pointpatsPointpats provides statistical methods for…
permissive · top 15,000 on PyPI
cityseerComputes network centrality, land-use…
agpl · top 15,000 on PyPI