A python package to help conduct different various types of crime analysis. Mostly a collection of various functions I have used over the years.
Andrew Wheeler
Requires Python 3.11 or newer.
pip install crimepy-cdcThe PyPI project name is crimepy-cdc. The import name is crimepy:
import crimepySome heavier pieces are optional extras:
pip install "crimepy-cdc[network]" # OpenStreetMap street networks (osmnx)
pip install "crimepy-cdc[opt]" # patrol districting and site selection (PuLP, HiGHS, libpysal)
pip install "crimepy-cdc[notebooks]" # Jupyter, ipycytoscape, and contextily basemaps
pip install "crimepy-cdc[gbtm]" # statsmodels for Poisson-mixture GBTM
pip install "crimepy-cdc[tableau]" # Tableau dashboard scraping
pip install "crimepy-cdc[all]" # every extra abovePatrol-district notebooks use both [network] (street distances) and [opt] (the solver). To work from a checkout:
git clone https://github.com/apwheele/crimepy.git
cd crimepy
pip install -e ".[all,test]"See the notebooks folder for example analyses:
- Aoristic analysis
- DBScan hotspots
- Prioritizing Call Ins via Dominant Sets
- Time Series Charts
- Patrol Districting with Workload Equality
- Drone Base Site Selection
- SPPT Compare Pre to Post Crime
- Scalable SPPT by Crime Theme, Pre/Post
- Group-Based Trajectory Modelling (GBTM)
- Querying public Socrata or ESRI data
- Example Interactive Maps with Folium
- Weighted Displacement Difference to See Changes over Time
- Analysis of Vandalism in Dallas (generated using Claude Code + Skills)
- Andrew Wheeler (@apwheele) — creator and maintainer
- agari (@routineactivity) — scalable SPPT and GBTM functions and examples
Additional examples in Notebooks and documentation (contributors welcome!)
- Funnel charts
- nearby chains
- SPPT crime to police activity example
- small sample Benford/Day of week functions & example
- HDBSCAN functions
- github actions for linting
- try patrol districting with googles ORtools, see how fast it runs
- simpler tests for districting
- Folium example for lines and graduated circles
Other additional methods I may add (if you want these, let me know):
- synthetic control using Lasso (blog post)
- network spillovers optimal assignment (blog post)
- network experiment design (Notebook)
- ?survey duplicates? (Notebook)
Suggestions are always welcome -- direct contributions are a better way to get the items you want in the codebase.
Don't know where to get started? Check out my introductory book on python for crime analysts, Data Science for Crime Analysis with Python
-
Wheeler, A. P. (2016). Tables and graphs for monitoring temporal crime trends: Translating theory into practical crime analysis advice. International Journal of Police Science & Management, 18(3), 159-172. Preprint
-
Wheeler, A. P. (2019). Creating optimal patrol areas using the p-median model. Policing: An International Journal, 42(3), 318-333. Preprint
-
Wheeler, A. P., & Kovandzic, T. V. (2018). Monitoring volatile homicide trends across US cities. Homicide Studies, 22(2), 119-144. Preprint
-
Wheeler, A. P., McLean, S. J., Becker, K. J., & Worden, R. E. (2019). Choosing representatives to deliver the message in a group violence intervention. Justice Evaluation Journal, 2(2), 93-117. Preprint
-
Wheeler, A. P., & Ratcliffe, J. H. (2018). A simple weighted displacement difference test to evaluate place based crime interventions. Crime Science, 7(1), 11. (Crime Science is an open journal)
-
Wheeler, A. P., & Reuter, S. (2021). Redrawing hot spots of crime in Dallas, Texas. Police Quarterly, 24(2), 159-184. Preprint
-
Wheeler, A. P., Riddell, J. R., & Haberman, C. P. (2021). Breaking the chain: How arrests reduce the probability of near repeat crimes. Criminal Justice Review, 46(2), 236-258. Preprint
-
Wheeler, A. P., Steenbeek, W., & Andresen, M. A. (2018). Testing for similarity in area‐based spatial patterns: Alternative methods to Andresen's spatial point pattern test. Transactions in GIS, 22(3), 760-774. Preprint

