septa-api
Async Python client for SEPTA real-time data: service alerts, Regional Rail departure boards and trip planning, bus and trolley positions, and stop departures for every bus, trolley, and subway route. Built for the SEPTA Home Assistant integration, usable anywhere.
No API key needed. Not affiliated with SEPTA.
Installation
pip install septa-api
Usage
import asyncio
import aiohttp
from septa_api import SeptaClient, load_catalog
async def main():
catalog = load_catalog()
route = catalog.routes["B1"]
northbound = next(d for d in route.directions if d.name == "Northbound")
stop_id = northbound.stop_ids[0]
async with aiohttp.ClientSession() as session:
client = SeptaClient(session)
alerts = await client.async_get_alerts()
cancelled = {t for a in alerts if a.effect == "NO_SERVICE" for t in a.trip_ids}
departures = await client.async_get_stop_departures(
stop_id, route.id, results=3, cancelled_trip_ids=cancelled
)
for departure in departures:
if departure.cancelled:
label = "cancelled"
else:
label = "live" if departure.realtime else "scheduled"
print(f"{catalog.stops[stop_id]}: {departure.expected:%H:%M} ({label})")
for alert in alerts:
if route.id in alert.route_ids:
print(f"{alert.severity}: {alert.header}")
asyncio.run(main())
Data sources
SEPTA's real-time data is spread over three systems, each with gaps. This library uses each one for what it does best.
| Data | Source | Notes |
|---|---|---|
| Routes, directions, stops | Static GTFS, bundled | Refreshed daily by a workflow when SEPTA publishes a new release |
| Service alerts | GTFS-RT alert feeds | Every mode; uses the same route IDs as the catalog |
| Bus and trolley detours | JSON API (BusDetours) |
Adds the direction and location alerts don't have |
| Stop departures | JSON API timetable, plus live bus/trolley delay | Broad Street and Market-Frankford Lines are timetable only |
| Bus and trolley positions | JSON API (TransitView) |
|
| Regional Rail departures and trips | JSON API (Arrivals, NextToArrive) |
Live delays, tracks, and transfers |
SEPTA publishes no live predictions for the Broad Street Line or Market-Frankford Line. Their GTFS-RT trip updates are generated from the timetable, so this library doesn't pretend otherwise: their StopDeparture.realtime is always False.
API
All times are timezone-aware in America/New_York (septa_api.TIMEZONE).
load_catalog()
Returns the bundled Catalog: routes by route ID, stops (stop ID to name), and the gtfs_version it was built from. It reads a file, so call it in an executor from async code. The result is cached.
A route's directions carry each direction's GTFS id, name (Northbound, Inbound, ...), destination, and ordered stop_ids. Direction IDs mean different things on different routes, so match on name.
SeptaClient(session)
Takes an aiohttp.ClientSession, which the caller owns.
await client.async_get_alerts()
Every active and upcoming Alert across all modes. Route-level alerts list route_ids and apply to both directions. Trip cancellations list only trip_ids, which match StopDeparture.trip_id. Use alert.is_active(now) to filter by the alert's active periods.
await client.async_get_detours() and match_detours(alerts, detours)
SEPTA's alerts have no direction, so a northbound detour shows up for both directions of a route. The detour feed has what's missing: each Detour has a direction (spelled like the catalog's direction names, e.g. Northbound), the start_location and end_location intersections it runs between, and its start and end.
match_detours() pairs DETOUR alerts with their detours on route, reason (the alert's header), and start time, returning matched detours by alert ID. On 2026-11-30 it matched all 119 active detour alerts, 105 of them to a single direction; the rest were detours SEPTA posted for both directions at once, which match both. Treat an unmatched alert as affecting every direction.
alerts, detours = await asyncio.gather(client.async_get_alerts(), client.async_get_detours())
matches = match_detours(alerts, detours)
northbound = [
a
for a in alerts
if "45" in a.route_ids
and (a.id not in matches or any(d.direction == "Northbound" for d in matches[a.id]))
]
await client.async_get_stop_departures(stop_id, route_id, results=20, cancelled_trip_ids=())
Upcoming StopDepartures of one route from a bus, trolley, or subway stop, from the timetable. When a live vehicle is running the trip, delay_minutes and vehicle_id are filled in and realtime is True; expected is the scheduled time plus the delay. SEPTA caps results at 20.
The timetable still lists trips SEPTA has cancelled. Pass the trip_ids of NO_SERVICE alerts as cancelled_trip_ids and those departures come back with cancelled set to True, so they don't pass for a bus that's coming. Taking the IDs from the caller avoids fetching the alert feeds again for every stop.
await client.async_get_vehicles(route_id)
Live Vehicle positions on a bus or trolley route. direction matches the catalog's direction names case-insensitively. Empty for subway lines.
await client.async_get_station_departures(station, results=5, cancelled_trains=None)
A Regional Rail station's live departure board, as TrainDepartures, results per direction. direction is N or S (SEPTA's through-Center-City convention), not inbound/outbound.
await client.async_get_next_to_arrive(origin, destination, results=5, cancelled_trains=None)
The next Regional Rail Trips between two stations, each with one or two TripLegs and the connection_station if there's a transfer.
Station arguments are catalog stop names; the client translates them to the legacy names SEPTA's JSON API expects. Station names in the results (origin, connection_station, ...) are SEPTA's legacy names.
cancelled_trains(alerts)
SEPTA lists cancelled Regional Rail trains as on time. This maps the train numbers that alerts say are cancelled to None (the whole train) or the alert's text (part of its run). Pass it as cancelled_trains to either rail method: wholly cancelled TrainDepartures and TripLegs come back with cancelled set to True, partly cancelled ones with cancelled left False and the alert text in cancellation_note.
now = datetime.now(TIMEZONE)
alerts = [a for a in await client.async_get_alerts() if a.is_active(now)]
trips = await client.async_get_next_to_arrive(
"Doylestown", "Suburban Station", cancelled_trains=cancelled_trains(alerts)
)
Filter by is_active() first: train numbers repeat daily, so an expired alert would otherwise flag the same train on a later day.
Rail cancellations come either as structured trip alerts or only as alert text ("Inbound train #5319 ... is canceled ..."), and the text match follows SEPTA's current wording. Partial cancellations aren't flagged because the same train really does run on the rest of its route: on 2026-11-30, train 5319 "canceled to Suburban Station" skipped Doylestown to Suburban but ran on to Wawa, so flagging it would have been wrong at Media and Wawa. Show cancellation_note so riders at the affected stations still see the warning.
The text match is tested against SEPTA's published wording from 2020 through 2026. An alert that names a train and mentions a cancellation in wording it doesn't recognize is logged as a warning (once per alert) rather than silently ignored; unmatched_cancellations(alerts) returns those alerts directly.
Exceptions
SeptaRequestError: SEPTA rejected the request, e.g. an unknown station or stop.SeptaConnectionError: SEPTA couldn't be reached or returned a server error.SeptaError: base class; also raised for malformed responses.
License
MIT
Metadata
Release files for septa-api 0.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| septa_api-0.4.0.tar.gz | 189.9 kB | With provenance | Details for septa_api-0.4.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| septa_api-0.4.0-py3-none-any.whl | Python 3 | none | any | Details for septa_api-0.4.0-py3-none-any.whl |
Total release size: 373.8 kB
Release files / septa_api-0.4.0.tar.gz
| Download URL | septa_api-0.4.0.tar.gz |
|---|---|
| Size | 189.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
25d6d8a548e42fd3ff2226ac6a192e1339adf5f94e68c28cb1cf5e2f38ea536b
|
|
BLAKE2b-256 checksum How to use checksums |
99fb9c6c7ed236e4b348d1ac012b1976ea5ad00405e80165ba0f181fbfbefeed
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 30, 2026.
Transparency logRelease files / septa_api-0.4.0-py3-none-any.whl
| Download URL | septa_api-0.4.0-py3-none-any.whl |
|---|---|
| Size | 184.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5b8673a70e4cb76df294b4fe6ce0c503897855bbb533e572185e52cb2b80cfdd
|
|
BLAKE2b-256 checksum How to use checksums |
06ca804608b5669f01d6579bfe560fcf0fed81e7801b0d559f2c583fd47c385e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 30, 2026.
Transparency logSecurity for septa-api 0.4.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.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for septa_api-0.4.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 30, 2026.
Transparency logA 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.