Skip to content

Latest commit

 

History

History
47 lines (36 loc) · 1.63 KB

README.md

File metadata and controls

47 lines (36 loc) · 1.63 KB

Python GTFS-realtime Language Bindings

PyPI version

Provides Python classes generated from the GTFS-realtime Protocol Buffer specification. These classes will allow you to parse a binary Protocol Buffer GTFS-realtime data feed into Python objects.

Add the Dependency

To use the gtfs-realtime-bindings classes in your own project, you need to first install the module from the PyPI repository.

# Using easy_install
easy_install --upgrade gtfs-realtime-bindings

# Using pip
pip install --upgrade gtfs-realtime-bindings

Example Code

The following code snippet demonstrates downloading a GTFS-realtime data feed from a particular URL, parsing it as a FeedMessage (the root type of the GTFS-realtime schema), and iterating over the results.

from google.transit import gtfs_realtime_pb2
import requests

feed = gtfs_realtime_pb2.FeedMessage()
response = requests.get('URL OF YOUR GTFS-REALTIME SOURCE GOES HERE')
feed.ParseFromString(response.content)
for entity in feed.entity:
  if entity.HasField('trip_update'):
    print(entity.trip_update)

For more details on the naming conventions for the Python classes generated from the gtfs-realtime.proto, check out the Python Generated Code section of the Protocol Buffers developer site.