Member-only story
Parsing GTFS format transit data in real time with Python
This week I started playing around with real-time transit data from New York City’s Metropolitan Transit Authority. It’s really cool, and quite easy to get your hands on this data. However, getting started with the GTFS data format can be challenging at first.
This is the quick setup guide for Python that I wish I had earlier this week.
Get yourself an API key
Before we start, you’ll need to decide what GTFS transit data you want to access.
I live in New York, so I’m working with NYC’s real-time data feeds. Most major cities offer their data and the GTFS format has become a standard.
Check out this awesome list of public APIs for ideas of transportation data (or any other type of data) you can use for your projects!
Install Google’s GTFS Python library
Google has already created a library of GTFS bindings for Python. This took me a little while to find and start using, so I’ll help you out with some setup instructions.
To install:
pip install --upgrade gtfs-realtime-bindings
Now try:
python -m google.transit.gtfs_realtime_pb2