https://github.com/williambdean/cta
Python Client for Chicago Transit Authority
https://github.com/williambdean/cta
chicago chicago-data-portal chicago-transit-authority cta mobility-data public-transportation python python3
Last synced: 6 months ago
JSON representation
Python Client for Chicago Transit Authority
- Host: GitHub
- URL: https://github.com/williambdean/cta
- Owner: williambdean
- Created: 2022-02-14T22:02:32.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-03-04T10:53:29.000Z (over 2 years ago)
- Last Synced: 2025-03-19T12:39:44.065Z (7 months ago)
- Topics: chicago, chicago-data-portal, chicago-transit-authority, cta, mobility-data, public-transportation, python, python3
- Language: Python
- Homepage:
- Size: 26.4 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Chicago Transit Authority API
The CTA has three public endpoints for tracking CTA trains. This client supports
those endpoints.The `CTAClient` has methods for each endpoints. Namely,
- arrivals: Arrival information for a given station(s) or stop(s).
- follow: Follow specific train by runnumber.
- locations: Get all trains for a given route(s).More endpoint specific documentation found [here](
https://www.transitchicago.com/developers/ttdocs/)This API requires a key which can be easily received [here](https://www.transitchicago.com/developers/traintrackerapply/).
Follow the `.env.example` file for setting.## Installation
This package is available on `pip`. Install with:
```bash
$ pip install python-cta
```## Getting Started
```python
from cta import CTAClient
damen_blue_line_mapid = 40590# Get arrival information for damen blue line station.
cta_client = CTAClient()
arrival_response = cta_client.arrivals(mapid=damen_blue_line_mapid)
df_arrivals = arrival_response.to_frame()
print(df_arrivals)# Follow specific train
runnumber = df_arrivals["rn"].tolist()[0]
follow_response = cta_client.follow(runnumber=runnumber)
df_follow = follow_response.to_frame()
print(df_follow)
``````python
from cta import Route# Get the location of all Blue Line trains.
location_response = cta_client.locations(Route.BLUE)
df_locations = location_response.to_frame()
print(df_locations)# Or all trains on the track
location_response = cta_client.locations(route=[route for route in Route])
df_locations = location_response.to_frame()
print(df_locations)
```Information about the stations can be found with the `Stations` class. Below is an
example to find the mapid for Damen blue line.```python
from cta import Stationsstations = Stations()
df_stations = stations.data
print(df_stations)df_damen = stations.lookup("Damen", route=Route.BLUE)
print(df_damen)
```Try this example for yourself in `scripts/readme_example.py`
## Notes
This currently doesn't support the [CTA bus API endpoints](https://www.transitchicago.com/developers/bustracker/). However, it might in the future.