Python wrapper for the MBTA v3 API
pip install pymbta3
To get data from the MBTA API, import the library and call the object with your API key. The API Key may also be stored in the environment variable MBTA_API_KEY
.
from pymbta3 import Alerts
at = Alerts(key=YOUR_API_KEY_HERE)
# Find all alerts affecting Alewife
alerts = at.get(stop='place-alfcl')
# Find the short header for the alert
for alert in alerts['data']:
print(alert['attributes']['short_header'])
Alerts affecting Orange and Red lines
alerts = at.get(route=['Orange', 'Red'])
Alerts affecting parking or Wheelchair use
alerts = at.get(activity=['PARK_CAR', 'USING_WHEELCHAIR'])
Return the stop data along with routes
from pymbta3 import Routes
rt = Routes(key=YOUR_API_KEY_HERE)
# Find all Route data for the Red Line
routes = rt.get(route='Red', include='stops')
- Alerts
- Routes
- Stops
- Vehicles
- Predictions
- Schedules
- Trips
- Facilities