septa-api 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- septa_api-0.1.0/LICENSE +21 -0
- septa_api-0.1.0/PKG-INFO +117 -0
- septa_api-0.1.0/README.md +102 -0
- septa_api-0.1.0/pyproject.toml +38 -0
- septa_api-0.1.0/septa_api/__init__.py +24 -0
- septa_api-0.1.0/septa_api/catalog.json +1 -0
- septa_api-0.1.0/septa_api/catalog.py +71 -0
- septa_api-0.1.0/septa_api/client.py +319 -0
- septa_api-0.1.0/septa_api/exceptions.py +13 -0
- septa_api-0.1.0/septa_api/models.py +132 -0
- septa_api-0.1.0/septa_api/py.typed +0 -0
- septa_api-0.1.0/septa_api.egg-info/PKG-INFO +117 -0
- septa_api-0.1.0/septa_api.egg-info/SOURCES.txt +17 -0
- septa_api-0.1.0/septa_api.egg-info/dependency_links.txt +1 -0
- septa_api-0.1.0/septa_api.egg-info/requires.txt +2 -0
- septa_api-0.1.0/septa_api.egg-info/top_level.txt +1 -0
- septa_api-0.1.0/setup.cfg +4 -0
- septa_api-0.1.0/tests/test_catalog.py +83 -0
- septa_api-0.1.0/tests/test_client.py +330 -0
septa_api-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Zack Wagner
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
septa_api-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: septa-api
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Python API client for SEPTA real-time data, alerts, and schedules
|
|
5
|
+
Author: zackwag
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/zackwag/septa-api
|
|
8
|
+
Project-URL: Issues, https://github.com/zackwag/septa-api/issues
|
|
9
|
+
Requires-Python: >=3.12
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Requires-Dist: aiohttp>=3.9.0
|
|
13
|
+
Requires-Dist: gtfs-realtime-bindings>=3.0.0
|
|
14
|
+
Dynamic: license-file
|
|
15
|
+
|
|
16
|
+
# septa-api
|
|
17
|
+
|
|
18
|
+
Async Python client for [SEPTA](https://www.septa.org/) 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.
|
|
19
|
+
|
|
20
|
+
No API key needed. Not affiliated with SEPTA.
|
|
21
|
+
|
|
22
|
+
## Installation
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
pip install septa-api
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Usage
|
|
29
|
+
|
|
30
|
+
```python
|
|
31
|
+
import asyncio
|
|
32
|
+
|
|
33
|
+
import aiohttp
|
|
34
|
+
|
|
35
|
+
from septa_api import SeptaClient, load_catalog
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
async def main():
|
|
39
|
+
catalog = load_catalog()
|
|
40
|
+
route = catalog.routes["B1"]
|
|
41
|
+
northbound = next(d for d in route.directions if d.name == "Northbound")
|
|
42
|
+
stop_id = northbound.stop_ids[0]
|
|
43
|
+
|
|
44
|
+
async with aiohttp.ClientSession() as session:
|
|
45
|
+
client = SeptaClient(session)
|
|
46
|
+
|
|
47
|
+
for departure in await client.async_get_stop_departures(stop_id, route.id, results=3):
|
|
48
|
+
label = "live" if departure.realtime else "scheduled"
|
|
49
|
+
print(f"{catalog.stops[stop_id]}: {departure.expected:%H:%M} ({label})")
|
|
50
|
+
|
|
51
|
+
for alert in await client.async_get_alerts():
|
|
52
|
+
if route.id in alert.route_ids:
|
|
53
|
+
print(f"{alert.severity}: {alert.header}")
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
asyncio.run(main())
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Data sources
|
|
60
|
+
|
|
61
|
+
SEPTA's real-time data is spread over three systems, each with gaps. This library uses each one for what it does best.
|
|
62
|
+
|
|
63
|
+
| Data | Source | Notes |
|
|
64
|
+
| --- | --- | --- |
|
|
65
|
+
| Routes, directions, stops | Static GTFS, bundled | Refreshed daily by a workflow when SEPTA publishes a new release |
|
|
66
|
+
| Service alerts | GTFS-RT alert feeds | Every mode; uses the same route IDs as the catalog |
|
|
67
|
+
| Stop departures | JSON API timetable, plus live bus/trolley delay | Broad Street and Market-Frankford Lines are timetable only |
|
|
68
|
+
| Bus and trolley positions | JSON API (`TransitView`) | |
|
|
69
|
+
| Regional Rail departures and trips | JSON API (`Arrivals`, `NextToArrive`) | Live delays, tracks, and transfers |
|
|
70
|
+
|
|
71
|
+
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`.
|
|
72
|
+
|
|
73
|
+
## API
|
|
74
|
+
|
|
75
|
+
All times are timezone-aware in `America/New_York` (`septa_api.TIMEZONE`).
|
|
76
|
+
|
|
77
|
+
### `load_catalog()`
|
|
78
|
+
|
|
79
|
+
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.
|
|
80
|
+
|
|
81
|
+
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`.
|
|
82
|
+
|
|
83
|
+
### `SeptaClient(session)`
|
|
84
|
+
|
|
85
|
+
Takes an `aiohttp.ClientSession`, which the caller owns.
|
|
86
|
+
|
|
87
|
+
### `await client.async_get_alerts()`
|
|
88
|
+
|
|
89
|
+
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.
|
|
90
|
+
|
|
91
|
+
### `await client.async_get_stop_departures(stop_id, route_id, results=20)`
|
|
92
|
+
|
|
93
|
+
Upcoming `StopDeparture`s 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.
|
|
94
|
+
|
|
95
|
+
### `await client.async_get_vehicles(route_id)`
|
|
96
|
+
|
|
97
|
+
Live `Vehicle` positions on a bus or trolley route. `direction` matches the catalog's direction names case-insensitively. Empty for subway lines.
|
|
98
|
+
|
|
99
|
+
### `await client.async_get_station_departures(station, results=5)`
|
|
100
|
+
|
|
101
|
+
A Regional Rail station's live departure board, as `TrainDeparture`s, `results` per direction. `direction` is `N` or `S` (SEPTA's through-Center-City convention), not inbound/outbound.
|
|
102
|
+
|
|
103
|
+
### `await client.async_get_next_to_arrive(origin, destination, results=5)`
|
|
104
|
+
|
|
105
|
+
The next Regional Rail `Trip`s between two stations, each with one or two `TripLeg`s and the `connection_station` if there's a transfer.
|
|
106
|
+
|
|
107
|
+
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.
|
|
108
|
+
|
|
109
|
+
### Exceptions
|
|
110
|
+
|
|
111
|
+
- `SeptaRequestError`: SEPTA rejected the request, e.g. an unknown station or stop.
|
|
112
|
+
- `SeptaConnectionError`: SEPTA couldn't be reached or returned a server error.
|
|
113
|
+
- `SeptaError`: base class; also raised for malformed responses.
|
|
114
|
+
|
|
115
|
+
## License
|
|
116
|
+
|
|
117
|
+
MIT
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
# septa-api
|
|
2
|
+
|
|
3
|
+
Async Python client for [SEPTA](https://www.septa.org/) 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.
|
|
4
|
+
|
|
5
|
+
No API key needed. Not affiliated with SEPTA.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pip install septa-api
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```python
|
|
16
|
+
import asyncio
|
|
17
|
+
|
|
18
|
+
import aiohttp
|
|
19
|
+
|
|
20
|
+
from septa_api import SeptaClient, load_catalog
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
async def main():
|
|
24
|
+
catalog = load_catalog()
|
|
25
|
+
route = catalog.routes["B1"]
|
|
26
|
+
northbound = next(d for d in route.directions if d.name == "Northbound")
|
|
27
|
+
stop_id = northbound.stop_ids[0]
|
|
28
|
+
|
|
29
|
+
async with aiohttp.ClientSession() as session:
|
|
30
|
+
client = SeptaClient(session)
|
|
31
|
+
|
|
32
|
+
for departure in await client.async_get_stop_departures(stop_id, route.id, results=3):
|
|
33
|
+
label = "live" if departure.realtime else "scheduled"
|
|
34
|
+
print(f"{catalog.stops[stop_id]}: {departure.expected:%H:%M} ({label})")
|
|
35
|
+
|
|
36
|
+
for alert in await client.async_get_alerts():
|
|
37
|
+
if route.id in alert.route_ids:
|
|
38
|
+
print(f"{alert.severity}: {alert.header}")
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
asyncio.run(main())
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Data sources
|
|
45
|
+
|
|
46
|
+
SEPTA's real-time data is spread over three systems, each with gaps. This library uses each one for what it does best.
|
|
47
|
+
|
|
48
|
+
| Data | Source | Notes |
|
|
49
|
+
| --- | --- | --- |
|
|
50
|
+
| Routes, directions, stops | Static GTFS, bundled | Refreshed daily by a workflow when SEPTA publishes a new release |
|
|
51
|
+
| Service alerts | GTFS-RT alert feeds | Every mode; uses the same route IDs as the catalog |
|
|
52
|
+
| Stop departures | JSON API timetable, plus live bus/trolley delay | Broad Street and Market-Frankford Lines are timetable only |
|
|
53
|
+
| Bus and trolley positions | JSON API (`TransitView`) | |
|
|
54
|
+
| Regional Rail departures and trips | JSON API (`Arrivals`, `NextToArrive`) | Live delays, tracks, and transfers |
|
|
55
|
+
|
|
56
|
+
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`.
|
|
57
|
+
|
|
58
|
+
## API
|
|
59
|
+
|
|
60
|
+
All times are timezone-aware in `America/New_York` (`septa_api.TIMEZONE`).
|
|
61
|
+
|
|
62
|
+
### `load_catalog()`
|
|
63
|
+
|
|
64
|
+
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.
|
|
65
|
+
|
|
66
|
+
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`.
|
|
67
|
+
|
|
68
|
+
### `SeptaClient(session)`
|
|
69
|
+
|
|
70
|
+
Takes an `aiohttp.ClientSession`, which the caller owns.
|
|
71
|
+
|
|
72
|
+
### `await client.async_get_alerts()`
|
|
73
|
+
|
|
74
|
+
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.
|
|
75
|
+
|
|
76
|
+
### `await client.async_get_stop_departures(stop_id, route_id, results=20)`
|
|
77
|
+
|
|
78
|
+
Upcoming `StopDeparture`s 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.
|
|
79
|
+
|
|
80
|
+
### `await client.async_get_vehicles(route_id)`
|
|
81
|
+
|
|
82
|
+
Live `Vehicle` positions on a bus or trolley route. `direction` matches the catalog's direction names case-insensitively. Empty for subway lines.
|
|
83
|
+
|
|
84
|
+
### `await client.async_get_station_departures(station, results=5)`
|
|
85
|
+
|
|
86
|
+
A Regional Rail station's live departure board, as `TrainDeparture`s, `results` per direction. `direction` is `N` or `S` (SEPTA's through-Center-City convention), not inbound/outbound.
|
|
87
|
+
|
|
88
|
+
### `await client.async_get_next_to_arrive(origin, destination, results=5)`
|
|
89
|
+
|
|
90
|
+
The next Regional Rail `Trip`s between two stations, each with one or two `TripLeg`s and the `connection_station` if there's a transfer.
|
|
91
|
+
|
|
92
|
+
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.
|
|
93
|
+
|
|
94
|
+
### Exceptions
|
|
95
|
+
|
|
96
|
+
- `SeptaRequestError`: SEPTA rejected the request, e.g. an unknown station or stop.
|
|
97
|
+
- `SeptaConnectionError`: SEPTA couldn't be reached or returned a server error.
|
|
98
|
+
- `SeptaError`: base class; also raised for malformed responses.
|
|
99
|
+
|
|
100
|
+
## License
|
|
101
|
+
|
|
102
|
+
MIT
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=68.0", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "septa-api"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Python API client for SEPTA real-time data, alerts, and schedules"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = {text = "MIT"}
|
|
11
|
+
requires-python = ">=3.12"
|
|
12
|
+
authors = [
|
|
13
|
+
{name = "zackwag"},
|
|
14
|
+
]
|
|
15
|
+
dependencies = [
|
|
16
|
+
"aiohttp>=3.9.0",
|
|
17
|
+
"gtfs-realtime-bindings>=3.0.0",
|
|
18
|
+
]
|
|
19
|
+
|
|
20
|
+
[project.urls]
|
|
21
|
+
Homepage = "https://github.com/zackwag/septa-api"
|
|
22
|
+
Issues = "https://github.com/zackwag/septa-api/issues"
|
|
23
|
+
|
|
24
|
+
[tool.pytest.ini_options]
|
|
25
|
+
asyncio_mode = "auto"
|
|
26
|
+
asyncio_default_fixture_loop_scope = "function"
|
|
27
|
+
|
|
28
|
+
[tool.setuptools.packages.find]
|
|
29
|
+
include = ["septa_api*"]
|
|
30
|
+
|
|
31
|
+
[tool.setuptools.package-data]
|
|
32
|
+
septa_api = ["catalog.json", "py.typed"]
|
|
33
|
+
|
|
34
|
+
[tool.ruff]
|
|
35
|
+
line-length = 100
|
|
36
|
+
|
|
37
|
+
[tool.ruff.lint]
|
|
38
|
+
extend-select = ["DTZ"]
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"""Python API client for SEPTA (Southeastern Pennsylvania Transportation Authority)."""
|
|
2
|
+
|
|
3
|
+
from .catalog import Catalog, Route, RouteDirection, load_catalog
|
|
4
|
+
from .client import TIMEZONE, SeptaClient
|
|
5
|
+
from .exceptions import SeptaConnectionError, SeptaError, SeptaRequestError
|
|
6
|
+
from .models import Alert, StopDeparture, TrainDeparture, Trip, TripLeg, Vehicle
|
|
7
|
+
|
|
8
|
+
__all__ = [
|
|
9
|
+
"TIMEZONE",
|
|
10
|
+
"Alert",
|
|
11
|
+
"Catalog",
|
|
12
|
+
"Route",
|
|
13
|
+
"RouteDirection",
|
|
14
|
+
"SeptaClient",
|
|
15
|
+
"SeptaConnectionError",
|
|
16
|
+
"SeptaError",
|
|
17
|
+
"SeptaRequestError",
|
|
18
|
+
"StopDeparture",
|
|
19
|
+
"TrainDeparture",
|
|
20
|
+
"Trip",
|
|
21
|
+
"TripLeg",
|
|
22
|
+
"Vehicle",
|
|
23
|
+
"load_catalog",
|
|
24
|
+
]
|