Skip to main content

Script for converting SWITRS reports to SQLite.

Project description

Looking to get right to work with the data? Checkout the cleaned dataset on Kaggle: California Traffic Collision Data from SWITRS

SWITRS-to-SQLite is a Python3 script that will convert the CSV files provided by the California Highway Patrol’s Statewide Integrated Traffic Records System (SWITRS) and convert them to an SQLite3 database.

Instructions to download the SWITRS data can be found here.

Versioning

This repository follows Semver. I will increment the MAJOR version if a change is backwards incompatible for either the Python command line or the structure of the output database.

Installation

The best way to install SWITRS-to-SQLite is with pip:

pip install switrs-to-sqlite

This will give you access to the script simply by calling:

switrs_to_sqlite --help

You can also clone this repository:

git clone https://github.com/agude/SWITRS-to-SQLite.git
cd SWITRS-to-SQLite
./switrs_to_sqlite/switrs_to_sqlite --help

If you clone the repository, SWITRS-to-SQLite can be installed as a local application using the setup.py script:

git clone https://github.com/agude/SWITRS-to-SQLite.git
cd SWITRS-to-SQLite
./setup.py install

Which, like using pip, will give you access to the script by calling switrs_to_sqlite.

SWITRS-to-SQLite requires only Python3.

Usage

Using SWITRS-to-SQLite is simple, just point it to the unzipped files from SWITRS and it will run the conversion:

switrs_to_sqlite \
CollisionRecords.txt \
PartyRecords.txt \
VictimRecords.txt

The script also supports reading gziped records files:

switrs_to_sqlite \
CollisionRecords.txt.gz \
PartyRecords.txt.gz \
VictimRecords.txt.gz

The conversion process will take about an hour to write the database, which by default is saved to a file named switrs.sqlite3. The output file can be changed as follows:

switrs_to_sqlite \
CollisionRecords.txt \
PartyRecords.txt \
VictimRecords.txt \
-o new_db_file.sql

The program provides the following help menu when called with --help:

usage: switrs_to_sqlite [-h] [-o OUTPUT_FILE]
                             collision_record party_record victim_record

Convert SWITRS text files to a SQLite database

positional arguments:
  collision_record      the CollisionRecords.txt file or the same file gzipped
  party_record          the PartyRecords.txt file or the same file gzipped
  victim_record         the VictimRecords.txt file or the same file gzipped

optional arguments:
  -h, --help            show this help message and exit
  -o OUTPUT_FILE, --output-file OUTPUT_FILE
                        file to save the database to

Unit Tests

SWITRS-to-SQLite uses pytest to run unit tests (contained in the tests folders). To run the tests, run this command from the base directory:

python3 -m pytest -v

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

switrs_to_sqlite-4.1.3.tar.gz (41.5 kB view details)

Uploaded Source

Built Distribution

switrs_to_sqlite-4.1.3-py3-none-any.whl (33.9 kB view details)

Uploaded Python 3

File details

Details for the file switrs_to_sqlite-4.1.3.tar.gz.

File metadata

  • Download URL: switrs_to_sqlite-4.1.3.tar.gz
  • Upload date:
  • Size: 41.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for switrs_to_sqlite-4.1.3.tar.gz
Algorithm Hash digest
SHA256 cc152e5ced0c7a2daf2e39f5db0e177b1041525999a4b6b61ca0974734069088
MD5 f39f5032196e652cb5997fa49c994877
BLAKE2b-256 d20ad72fa25804d87bbc43486ae1c4f1a0a9dd7fcbed430ec9e3e9c2fb82afcb

See more details on using hashes here.

Provenance

The following attestation bundles were made for switrs_to_sqlite-4.1.3.tar.gz:

Publisher: release.yml on agude/SWITRS-to-SQLite

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file switrs_to_sqlite-4.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for switrs_to_sqlite-4.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 9b22ad46ac834c3f2297465b69e107f85cb6736cc5b23fe8dc0a2884ecc5140f
MD5 da90f4f9d7d6123d727567d42764e32d
BLAKE2b-256 ac8e56fa5d44f4d14245d7d27e1b4fe460cb1705fcfdbf236f364e9869b98abe

See more details on using hashes here.

Provenance

The following attestation bundles were made for switrs_to_sqlite-4.1.3-py3-none-any.whl:

Publisher: release.yml on agude/SWITRS-to-SQLite

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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