Autoredistrict is a local-first congressional redistricting workbench. It can generate reproducible district plans from synthetic demo geography or live Census/TIGER state data, score the plans with district metrics, and export map and data artifacts for inspection.
- Automatic Redistricting: Generate congressional district maps from demo or live state geography.
- Graph Solver: Build contiguous districts over an adjacency graph with deterministic multi-start growth, local boundary moves, annealing, and adjacent-pair recombination.
- Multiple Algorithms: Choose a fair baseline or Democratic/Republican advantage modes.
- Customizable Criteria: Adjust parameters like population equality and compactness.
- VRA and COI Heuristics: Enable Voting Rights Act opportunity-district scoring and preserve communities of interest by GEOID.
- Data Fetching: Automatically fetches the latest census data and shapefiles.
- Local Web/API Mode: Run a FastAPI server with a browser UI for generating and reviewing plans.
- Export Options: Export PNG maps, dissolved GeoJSON, unit assignment CSV, metrics CSV, JSON reports, and optional shapefiles.
-
Clone the repository:
git clone <repository_url> cd <repository_directory>
-
Install the dependencies: Make sure you have Python 3 installed. Then, run the following command to install the necessary libraries:
pip install -r requirements.txt
To run the legacy desktop application, execute the src.app module:
python -m src.appThis will open the main application window, where you can select a state, choose an algorithm, and generate a district map.
The browser-based local interface is the preferred path for ongoing development and automated testing:
uv run python -m src.webappThen open http://127.0.0.1:8765. The current web UI runs the graph-based synthetic demo solver by default, can request a live state run with a Census API key, displays the generated map and district metrics, and exposes PNG, GeoJSON, assignment CSV, metrics CSV, and JSON report artifacts.
Useful API routes:
GET /api/healthPOST /api/plans/demoPOST /api/plans/stateGET /api/plans/{plan_id}
For quick smoke tests or server use, run the CLI:
python -m src.cli <state> --api-key $CENSUS_API_KEY --map-out map.png --shp-out districts.shpTo exercise the pipeline without network/API keys, use the synthetic demo dataset:
python -m src.cli demo --demo --districts 4 --seed 11 --map-out demo.png --report-out plan.jsonFor faster but lower-fidelity runs, use tract resolution:
python -m src.cli "North Carolina" --api-key $CENSUS_API_KEY --resolution tractTo prefetch and cache data/shapefiles only (no map generation):
python -m src.cli "North Carolina" --api-key $CENSUS_API_KEY --cache-onlyFor a no-network smoke run with assertions:
uv run python -m src.cli --demo --mode smoke --map-out smoke.png --quietRun the automated test suite:
uv run --frozen pytestThe current tests cover API health and artifact serving, demo plan generation, mocked live-state solving, deterministic graph-solver behavior, contiguity, VRA/COI heuristics, recombination population-balance improvement, and CLI report/map output.