A companion to GerryChain, GerryTools provides tools for retrieving redistricting data, recording and scoring ensembles, comparing districting plans, and producing publication-ready figures and tables. It is developed by the Data and Democracy Research Initiative and distributed under the 3-Clause BSD License.
GerryTools requires Python 3.11 or newer. Published wheels include the compiled scoring engine; building from source requires a stable Rust toolchain and a C++ compiler.
To install GerryTools from PyPI, run:
pip install gerrytoolsThe gerrytools.ben API is included in the base installation. To use the Docker-backed ensemble
runners in gerrytools.mgrp, install the optional dependency:
pip install "gerrytools[mgrp]"The runners also require Docker Desktop, Docker Engine, or another compatible daemon. See the Docker documentation for platform requirements and setup instructions.
GerryTools is organized into public modules that can be used independently or together:
-
gerrytools.dataretrieves decennial Census and American Community Survey tables, estimates block-level citizen voting-age population, and downloads processed 2020 geographic products. -
gerrytools.plan_comparisoncompares plans by population or area, finds optimal district relabelings, and measures population dispersion. -
gerrytools.plottingprovides composable statistical and geographic plot builders that work with Matplotlib figures and axes. -
gerrytools.colorsprovides named colors, district palettes, color conversion, and Matplotlib and seaborn colormaps. -
gerrytools.mgrpruns Rust ReCom, Forest ReCom, Sequential Monte Carlo, and optimization workflows through a versioned Docker image. -
gerrytools.benrecords GerryChain runs as self-describing BENDL files and reconstructs recorded partitions for lookup, subsampling, and analysis. -
gerrytools.scoringprepares graph and geometry resources once, evaluates plans with the compiled Rust scoring engine, and provides one-shot functions and array formulas. -
gerrytools.latexbuilds LaTeX documents and tables plus TikZ-native paintball and seats-votes figures.
See the module guides for examples and the API reference for signatures and parameters.
GerryTools is an active project, and has multiple contributors. If you'd like to contribute, here are a few house rules:
-
Install
taskanduv, then runtask setupfrom the repository root. Usetask --list-allto see the available development workflows. -
Run
task checkbefore opening a pull request. Usetask formatfor Ruff formatting and import sorting,task lintfor Ruff linting,task testfor the test suite, andtask docsto build the documentation locally. -
Write tests. All changes, major or minor, must be accompanied by testing code. Code and tests will be immediately reviewed by Lab maintainers.
-
Test coverage must stay at least the same; this can be checked by running
uv run pytest --cov=gerrytools --cov-report=term-missingafter the tests are added totests/. -
Write documentation. Document public APIs and non-obvious invariants. Prefer clear names and focused functions over comments that merely restate the code.
We look forward to your contributions!