Skip to main content
Help us improve PyPI by participating in user testing. All experience levels needed!

Script for converting SWITRS reports to SQLite.

Project description

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.


The best way tin 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
cd SWITRS-to-SQLite
./switrs_to_sqlitswitrs_to_sqlite --help

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

git clone
cd SWITRS-to-SQLite
./ install

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

SWITRS-to-SQLite requires only Python3.


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 \

The script also supports reading gziped records files:

switrs_to_sqlite \
CollisionRecords.txt.gz \
PartyRecords.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

Release history Release notifications

This version
History Node


History Node


Download files

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

Filename, size & hash SHA256 hash help File type Python version Upload date
switrs-to-sqlite-1.0.0.tar.gz (8.0 kB) Copy SHA256 hash SHA256 Source None Oct 31, 2016

Supported by

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