Skip to main content

GTFSDB

Join the chat at https://gitter.im/OpenTransitTools/gtfsdb

Supported Databases

  • PostgreSQL (PostGIS for Geo tables) - preferred

  • Oracle - tested

  • MySQL - tested

  • SQLite - tested

GTFS (General Transit Feed Specification) Database

Python code that will load GTFS data into a relational database, and SQLAlchemy ORM bindings to the GTFS tables in the gtfsdb. The gtfsdb project’s focus is on making GTFS data available in a programmatic context for software developers. The need for the gtfsdb project comes from the fact that a lot of developers start out a GTFS-related effort by first building some amount of code to read GTFS data (whether that’s an in-memory loader, a database loader, etc…); GTFSDB can hopefully reduce the need for such drudgery, and give developers a starting point beyond the first step of dealing with GTFS in .csv file format.

Available on pypi: https://pypi.python.org/pypi/gtfsdb

Install from source via github (if you want the latest code) :

  1. Install Python 3.x https://www.python.org/downloads/ (code also runs on 2.7 if you are stuck on that version)

  2. pip install zc.buildout - https://pypi.org/project/zc.buildout

  3. (optinal step for postgres users: ‘pip install psycopg2-binary’)

  4. git clone https://github.com/OpenTransitTools/gtfsdb.git

  5. cd gtfsdb

  6. buildout install prod – NOTE: if you’re using postgres, do a ‘buildout install prod postgresql’

  7. bin/gtfsdb-load –database_url <db url> <gtfs file | url>

  8. examples:

    • bin/gtfsdb-load –database_url sqlite:///gtfs.db gtfsdb/tests/large-sample-feed.zip

    • bin/gtfsdb-load –database_url sqlite:///gtfs.db http://developer.trimet.org/schedule/gtfs.zip

    • bin/gtfsdb-load –database_url postgresql://postgres@localhost:5432 –is_geospatial http://developer.trimet.org/schedule/gtfs.zip

  9. view db ( example: https://sqliteonline.com )

The best way to get gtfsbd up and running is via the ‘zc.buildout’ tool. Highly recommended to first install buildout (e.g., pip install zc.buildout) before doing much of anything else.

Postgres users, gtfsdb requires the psycopg2-binary database driver. Installing that via pip install psychopg2-binary will relieve gtfsdb from re-installing locally as part of the build. And if after the fact, you see exceptions mentioning

Usage with Docker:

  1. Build the image with docker build -t gtfsdb .

  2. Run it with:

docker run gtfsdb --database_url <db url>  <gtfs file | url>

Example Queries:

  • get first stop time of each trip for route_id 1

    select *
    from trips t, stop_times st
    where t.route_id = '1'
    and t.trip_id = st.trip_id
    and st.stop_sequence = 1
  • get agency name and number of routes

    select a.agency_name, a.agency_id, count(r.route_id)
    from routes r, agency a
    where r.agency_id = a.agency_id
    group by a.agency_id, a.agency_name
    order by 3 desc

Metadata

Release files for gtfsdb 0.6.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for gtfsdb 0.6.0
File Size Uploaded Provenance
gtfsdb-0.6.0.tar.gz 43.0 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for gtfsdb 0.6.0
File Interpreter ABI Platform
gtfsdb-0.6.0-py3-none-any.whl Python 3 none any Details

Total release size: 100.4 kB

Release files / gtfsdb-0.6.0.tar.gz

Download URL gtfsdb-0.6.0.tar.gz
Size 43.0 kB
Tags Source
SHA-256 checksum
How to use checksums
a83045d940d28623b0a54898ae05193c6d36a0837ba78bbadc92d3fb6b33336c
BLAKE2b-256 checksum
How to use checksums
e192abb7884a9a66b9d6f6cc3079f419fb05081493f67b4514f9f717f5c9a566
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.1

Release files / gtfsdb-0.6.0-py3-none-any.whl

Download URL gtfsdb-0.6.0-py3-none-any.whl
Size 57.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9bec3c1a848fd7445432fb8db67e1b6ccc0270ee4cf916b03b736f4725cca064
BLAKE2b-256 checksum
How to use checksums
78871b69cee2d45d7a3031e5f1f9d82747eb90211a8cb02a4c79a882c5c28c0f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.1

Security for gtfsdb 0.6.0

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page