Skip to main content

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 a 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
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_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.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for septa-api 0.3.0
File Size Uploaded Provenance Actions
septa_api-0.3.0.tar.gz 187.2 kB With provenance Details for septa_api-0.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for septa-api 0.3.0
File Interpreter ABI Platform Actions
septa_api-0.3.0-py3-none-any.whl Python 3 none any Details for septa_api-0.3.0-py3-none-any.whl

Total release size: 369.7 kB

Release files / septa_api-0.3.0.tar.gz

Download URL septa_api-0.3.0.tar.gz
Size 187.2 kB
Tags Source
SHA-256 checksum
How to use checksums
0f5b3364334f8b42c2fed8f03f5c17f99e06335bef97506b6642330dfdaf6360
BLAKE2b-256 checksum
How to use checksums
a5ec5d3c4709d9e10d6d4c876ec1de30c2f9cd0cb0fcca32ecbb217e6f81ad98
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 log

Release files / septa_api-0.3.0-py3-none-any.whl

Download URL septa_api-0.3.0-py3-none-any.whl
Size 182.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9043ccb79c4ed4665adbae9d6f0e3c79aa89068d38a97d7590b1e69d089c6138
BLAKE2b-256 checksum
How to use checksums
e1d1fa20ff12b1567d178c378e4e5484e926efcc8b2fb2185b6122abe5372bce
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 log

Security for septa-api 0.3.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.

Select from 2 files

Attestation for septa_api-0.3.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 log

A 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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page