SWITRS-to-SQLite
Looking to get right to work with the data? Check out the cleaned dataset on Kaggle: California Traffic Collision Data from SWITRS
SWITRS-to-SQLite is a Python 3 script that converts the CSV files from the California Highway Patrol's Statewide Integrated Traffic Records System (SWITRS) into an SQLite database.
Note: CHP shut down iSWITRS on January 8, 2025 and replaced it with the California Crash Reporting System (CCRS). This tool works with the legacy SWITRS CSV format (
CollisionRecords.txt,PartyRecords.txt,VictimRecords.txt). CCRS uses a different file layout; support for it is planned for a future release.
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
Or with UV:
uv tool install switrs-to-sqlite
This will give you access to the script simply by calling:
switrs_to_sqlite --help
Development Installation
For development, clone the repository and use UV to sync the environment (this handles the local package installation automatically):
git clone https://github.com/agude/SWITRS-to-SQLite.git
cd SWITRS-to-SQLite
uv sync --dev
SWITRS-to-SQLite requires Python 3.10+.
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 takes about 10 minutes for a full-sized dump. The database is
saved by default 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.sqlite3
The program provides the following help menu when called with --help:
usage: switrs_to_sqlite [-h] [--version] [-p {strict,ignore,replace}]
[-o OUTPUT_FILE]
collision_record party_record victim_record
Convert SWITRS text files to a SQLite3 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
options:
-h, --help show this help message and exit
--version show program's version number and exit
-p {strict,ignore,replace}, --parse-error {strict,ignore,replace}
how to handle unicode decoding errors in input files:
'strict' raises an error (default), 'ignore' skips
invalid characters, 'replace' substitutes a
replacement character
-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
folder). To run the tests:
uv run pytest -vv
Or with just:
just test
Run just with no arguments to see all available commands.
Release files for switrs-to-sqlite 5.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| switrs_to_sqlite-5.1.0.tar.gz | 98.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| switrs_to_sqlite-5.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 136.1 kB
Release files / switrs_to_sqlite-5.1.0.tar.gz
| Download URL | switrs_to_sqlite-5.1.0.tar.gz |
|---|---|
| Size | 98.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
dacfe67538d393cb0ecf0902916e5fde825df06fea22ceb00e96a0c0c20ab605
|
|
BLAKE2b-256 checksum How to use checksums |
4eec38ac68ff50189f7bee64b34d13723936341cb43efab71b82b9e894cd05d5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 29, 2026.
Transparency logRelease files / switrs_to_sqlite-5.1.0-py3-none-any.whl
| Download URL | switrs_to_sqlite-5.1.0-py3-none-any.whl |
|---|---|
| Size | 37.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d534651567eb3d9031cd5f1b213c286594fe05f62ebb2881120a0c1617efcbe4
|
|
BLAKE2b-256 checksum How to use checksums |
a88e46194c9b9837d39536fe2a22e31c551729ae943df1166c62b025eb199c19
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 29, 2026.
Transparency log