Skip to main content

A library for working with data submitted to the PDI.

Project description

OpenPDI Build Status code style DOI Thanks

OpenPDI is an unofficial effort to document and standardize data submitted to the Police Data Initiative (PDI). The goal is to make the data more accessible by addressing a number of issues related to a lack of standardization—namely,

  • File types: While some agencies make use if the Socrata Open Data API, many provide their data in raw .csv, .xlsx, or .xls files of varying structures.
  • Column names: Many columns that represent the same data (e.g., the race police officer) are named differently across departments, cities, and states.
  • Value formats: Dates, times, and other comparable fields are submitted in many different formats.
  • Column availability: It's currently very difficult to identify data sources that contain certain columns—e.g., Use of Force data specifying the hire date of the involved officer(s).

Getting Started

$ pip install openpdi
Dataset ID Source
Use of Force uof
import csv
import openpdi

# The library has a single entry point:
dataset = openpdi.Dataset(
    # The dataset ID (see the table above).
    # Limit the data sources to a specific state using its two-letter code.
    # Default: `scope=[]`.
    # A list of columns that must be provided in every data source included in
    # this dataset. See `openpdi/meta/{ID}/schema.json` for the available
    # columns.
    # Default: `columns=[]`.
    # If `True`, only return the user-specified columns -- i.e., those listed
    # in the `columns` parameter.
    # Default: `strict=False`.

# The names of the agencies included in this dataset:

# The URLs of the external data sources inlcuded in this dataset:

# `gen` is a generator object for iterating over the CSV-formatted dataset.
gen =

# Write to a CSV file:
with open("dataset.csv", "w+") as f:
    writer = csv.writer(f, delimiter=",", quoting=csv.QUOTE_ALL)


In an attempt to avoid unnecessary bloat (in terms of GBs), we don't actually store any PDI data in this repository. Instead, we store small, JSON-formatted descriptions of externally hosted datasets—for example, uof/CA/meta.json:

        "url": "",
        "type": "csv",
        "start": 1,
        "columns": {
            "date": {
                "index": 0,
                "specifier": "%m/%d/%Y"
            "city": {
                "raw": "Richmond"
            "state": {
                "raw": "CA"
            "service_type": {
                "index": 1
            "force_type": {
                "index": 10
            "light_conditions": {
                "index": 8
            "weather_conditions": {
                "index": 7
            "reason": {
                "index": 2
            "officer_injured": {
                "index": 6
            "officer_race": {
                "index": 9
            "subject_injured": {
                "index": 5
            "aggravating_factors": {
                "index": 3
            "arrested": {
                "index": 4

This file describes a Use of Force (uof) dataset from Richmond, CA. Each entry in the columns array maps a column from the externally-hosted data to a column in the dataset's schema file (uof/schema.json).


The schema.json file assigns a format to every possible column in a particular dataset, which is a Python function tasked with standardizing a raw column value (see openpdi/

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for openpdi, version 0.1.3
Filename, size File type Python version Upload date Hashes
Filename, size openpdi-0.1.3-py2.py3-none-any.whl (16.6 kB) File type Wheel Python version py2.py3 Upload date Hashes View hashes
Filename, size openpdi-0.1.3.tar.gz (13.7 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page