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.
Version 3.0.0 requires Python 3.10 or later and protobuf 7.34.0 or later. If you are using an older version of Python or need an older protobuf runtime, please continue using version 2.x.
To use the gtfs-realtime-bindings classes in your own project, you need to
first install the module from the
PyPI repository.
pip install --upgrade gtfs-realtime-bindings
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.