Skip to main content

Python wrapper for downloading California Crash Reporting System (CCRS) data.

Project description

pyccrs

Purpose

California crash data is incredibly rich, and yet is a bit of a hassle to access. pyccrs is my solution. With this package, downloading CCRS data requires just a basic understanding of Python, allowing data analysts to focus on what they do best: last-mile data wrangling, and analysis.

Dependencies

ckanpy

ckanpy is a package I created for pyccrs, which handles interactions with the CKAN database that CCRS data is accessible through.

pydantic

pydantic is used for improving data models, providing type validation, parsing, and stability with respect to bugs.

pandas

pandas is used mainly as an export option, as well as a few filters.

Use Cases

Downloading CCRS Table Data

pyccrs makes it very simple to download CCRS data efficiently, using SQL queries to parse data across all the years of data one wishes to request. SQL queries are generated Pythonically, with no SQL knowledge necessary from the user. For stability, as sometimes a year may be available only through downloading the CSV, such years will be downloaded and filtered accordingly, albeit with a significantly longer load time and memory usage.

For the sake of usability, the easiest way to download CCRS data through pyccrs is by a particular column:

  • Crashes: city name
  • Parties: collision ID
  • People: collision ID

(Note: what CCRS calls "InjuredWitnessPassenger", pyccrs calls "Person", or "People".)

In addition, pyccrs automatically remaps the column names to a standardized, Pythonic format, like "column_name", as opposed to CCRS's un-Pythonic "Column Name".

Each table has its own download function:

  • download_crashes()
  • download_parties()
  • download_people()

Downloading Node-Based Data

pyccrs also allows downloading data as nodes in a graph, which may be the superior data structure for certain analyses. This may be achieved using download_nodes().

Downloading Modeled Data

It is also possible to download data as lists of pydantic models, with the export style option "model".

Documentation

pyccrs also serves as documentation. CCRS metadata is somewhat inaccurate, with some columns inproperly typed or outright missing. One of the objectives of pyccrs, then, is to document the data and enforce that documentation through pydantic models and docstrings.

Contributing

Though functional, there are still many ways this package can be improved. Feel free to look around for leftover TODOs, send a pull request suggesting a change, or reach out to me by email to discuss specific improvements.

Project details


Download files

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

Source Distribution

pyccrs-0.13.6.tar.gz (32.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyccrs-0.13.6-py3-none-any.whl (49.0 kB view details)

Uploaded Python 3

File details

Details for the file pyccrs-0.13.6.tar.gz.

File metadata

  • Download URL: pyccrs-0.13.6.tar.gz
  • Upload date:
  • Size: 32.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.19 {"installer":{"name":"uv","version":"0.11.19","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for pyccrs-0.13.6.tar.gz
Algorithm Hash digest
SHA256 1b90b8d6c7b45ee62283cfaa91693a25ce0d9fd277301749ec0398591b632dab
MD5 3262bb3b676fc3b426479f577561b0ca
BLAKE2b-256 b35478950a97a5c144f01277bef9596417159ede43c592ed83a05987b76835d9

See more details on using hashes here.

File details

Details for the file pyccrs-0.13.6-py3-none-any.whl.

File metadata

  • Download URL: pyccrs-0.13.6-py3-none-any.whl
  • Upload date:
  • Size: 49.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.19 {"installer":{"name":"uv","version":"0.11.19","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for pyccrs-0.13.6-py3-none-any.whl
Algorithm Hash digest
SHA256 06bb0f222cb517a764315a5bcb4e69c02403e0ca92c13d1618e8d1570d654ba8
MD5 03114d2f4c39646665e913a879b6c597
BLAKE2b-256 9035cd06de33c16a93e509934224f959e0d4876fb93cc4fa1aac102b5d1030d6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page