--- id: spopt version: "0.7.0" license: BSD 3-Clause license_treatment: permissive maintenance: active --- # spopt — Spatial Optimization in PySAL License: permissive · Maintenance: active · Downloads: 102.1K/mo ## What it is and what it does Spopt is a Python library for solving spatial optimization problems on geographic data, originating from PySAL's region module and now actively developed as a standalone package. It handles three main problem classes: regionalization (grouping geographic units into contiguous regions under constraints), facility location (siting facilities to serve demand across a network), and transportation-oriented modeling. The library integrates tightly with geopandas for spatial data handling, libpysal for spatial weights and connectivity, and pulp for constraint programming, allowing you to define optimization objectives and constraints over geographic features. Typical workflows involve loading geographic data as GeoDataFrames, defining spatial relationships through weights matrices, and instantiating a model class (like MaxPHeuristic for regionalization or MCLP for facility location) with your data and parameters. The library handles the translation to an optimization problem, solves it via an external solver, and returns region assignments or facility locations as labels you can map back to your original data. It's designed for researchers and practitioners working with spatial planning, urban design, or resource allocation problems where geography and adjacency constraints matter. Use it for: - Partition a country into regions for administrative planning or data collection while respecting population thresholds and geographic contiguity. - Locate emergency service facilities (hospitals, fire stations) to maximize coverage of demand points across a street network. - Group census tracts or neighborhoods into homogeneous clusters for analysis while maintaining spatial connectivity. - Solve max-p-regions problems to find the minimum number of regions that satisfy a population or attribute threshold. - Model transportation networks to optimize routing or service delivery under distance and capacity constraints. ## Worth the install? AI-flagged interpretation of the facts above — verify before relying. Spopt solves spatial optimization problems including regionalization, facility location, and transportation-oriented modeling using geographic data and constraint-based algorithms. Yes. Spopt is actively maintained, has no known vulnerabilities, installs with low friction, and fills a specific niche in spatial optimization that is not easily replicated by combining other packages. Install it if you are solving regionalization, facility location, or network-based optimization problems on geographic data; skip it if your work is purely aspatial or does not require constraint-based optimization. ## Install pip install spopt uv add spopt poetry add spopt ## Installing spopt Before you install: Low friction installation with a pure-Python wheel. Actively maintained as of July 2026 with a stable release cycle; 13 runtime dependencies are all mature, widely-used scientific libraries. License in practice: BSD 3-Clause is permissive; you may use, modify, and distribute spopt freely in commercial or proprietary projects provided you retain the license notice. Quickstart: pip install spopt import spopt import geopandas import libpysal import numpy mexico = geopandas.read_file(libpysal.examples.get_path("mexicojoin.shp")) w = libpysal.weights.Queen.from_dataframe(mexico) model = spopt.region.MaxPHeuristic(mexico, w, ["PCGDP1950"], "count", 4, 2) model.solve() mexico["regions"] = model.labels_ Requires Python 3.11 or later; pulp solver backend needs an external optimization engine (CBC is included by default). Verify before relying: - Performance characteristics and scalability limits for large geographic datasets are not quantified in the fact sheet. - Whether the package supports alternative solvers beyond pulp's default CBC backend. ## Package facts - License: BSD 3-Clause (permissive) - Python support: supports_current - Install friction: low - Maintenance: active - Downloads: 102.1K/month (top 15,000 on PyPI) - Known vulnerabilities: none known ## Tags spatial optimization regionalization, facility location modeling, geographic clustering constraints, spatial partitioning algorithms, network-based optimization, geopandas optimization, max-p regions problem, spatial-optimization, regionalization, facility-location [View on SkillFed](https://skillfed.io/packages/spopt) · [View on PyPI](https://pypi.org/project/spopt/)