MTA Realtime API JSON Proxy

MTAPI is a small HTTP server that converts the MTA's realtime subway feed from Protocol Buffers/GTFS to JSON. The app also adds caching and makes it possible to retrieve information by location and train line.

Active Development

This project is under active development and any part of the API may change. Feedback is very welcome.

Running the server

MTAPI is a Flask app designed to run under Python 3.3+.

  1. Create a settings.cfg file. A sample is provided as settings.cfg.sample.
  2. Set up your environment and install dependencies.
    $ python3 -m venv .venv
    $ source .venv/bin/activate
    $ python3 -m pip install -r requirements.txt
  3. Run the server
    $ python app.py

If your configuration is named something other than settings.cfg, set the MTAPI_SETTINGS env variable to your configuration path.

This app makes use of Python threads. If running under uWSGI include the --enable-threads flag.

Endpoints

Endpoints to retrieve train data and sample input and output are listed here.

Settings

Generating a Stations File

The MTA provides several static data files about the subway system but none include canonical information about each station. MTAPI includes a script that will parse the stops.txt and transfers.txt datasets provided by the MTA and attempt to group the different train stops into subway stations. MTAPI will use this JSON file for station names and locations. The grouping is not perfect and editing the resulting files is encouraged.

Usage:

$ python make_stations_csv.py stops.txt transfers.txt > stations.csv
# edit groupings in stations.csv
$ python make_stations_json.py stations.csv > stations.json
# edit names in stations.json

Help

Submit a GitHub Issues request.

Projects

Here are some projects that use MTAPI.

License

The project is made available under the MIT license.