Skip to main content

py-nycmta

A lightweight Python library for getting NYC MTA train arrival times. Simple, fast, and focused.

Installation

pip install py-nycmta

Quick Start

from py_nycmta import Train

# Create a train instance for any line
f_train = Train('F')

# Get arrivals at 7 Av (F24)
arrivals = f_train.get_arrivals('F24')

for arrival in arrivals:
    print(f"{arrival.train_id} train in {arrival.minutes_away} minutes ({arrival.direction}bound)")

Features

  • Ultra-lightweight: Only 3 dependencies (httpx, gtfs-realtime-bindings, protobuf)
  • Simple: Just one Train class for all subway lines
  • Fast: Direct GTFS feed access, no unnecessary abstractions
  • Type-safe: Full type hints for better IDE support

Usage

Basic Usage

from py_nycmta import Train

# Create train instances for any line
f_train = Train('F')
n_train = Train('N')
a_train = Train('A')
one_train = Train('1')

# Get arrivals at a stop
arrivals = f_train.get_arrivals('F24')  # 7 Av

Filter by Direction

f_train = Train('F')

# Get only northbound trains
northbound = f_train.get_arrivals('F24', direction='N')

# Get only southbound trains
southbound = f_train.get_arrivals('F24', direction='S')

Get Next Few Arrivals

f_train = Train('F')

# Get next 2 arrivals
next_trains = f_train.get_next_arrivals('F24', count=2)

Working with Arrival Data

f_train = Train('F')
arrivals = f_train.get_arrivals('F24')

for arrival in arrivals:
    print(f"Train: {arrival.train_id}")
    print(f"Minutes away: {arrival.minutes_away}")
    print(f"Direction: {arrival.direction}")
    print(f"Status: {arrival.status}")
    print(f"Arrival time: {arrival.arrival_time}")
    print(f"Stop ID: {arrival.stop_id}")
    print("---")

Supported Train Lines

All NYC subway lines are supported using the single Train class:

from py_nycmta import Train

# Letter trains
Train('A'), Train('B'), Train('C'), Train('D'), Train('E')
Train('F'), Train('G'), Train('J'), Train('L'), Train('M')
Train('N'), Train('Q'), Train('R'), Train('W'), Train('Z')

# Number trains  
Train('1'), Train('2'), Train('3'), Train('4'), Train('5'), Train('6'), Train('7')

Stop IDs

Use MTA stop IDs without the direction suffix:

  • F24 - 7 Av
  • A41 - Jay St-MetroTech
  • R16 - Times Sq-42 St
  • R20 - 14 St-Union Sq

The library automatically handles northbound (N) and southbound (S) directions.

Error Handling

from py_nycmta import Train

try:
    # Invalid train line
    train = Train('X')  # Raises ValueError
except ValueError as e:
    print(f"Error: {e}")  # Shows valid train options

try:
    train = Train('F')
    arrivals = train.get_arrivals('INVALID_STOP')
except Exception as e:
    print(f"Error: {e}")

Development

git clone https://github.com/dvd-rsnw/py-nycmta
cd py-nycmta
pip install -e ".[dev]"
pytest

Requirements

  • Python 3.8+
  • Internet connection (for MTA GTFS feeds)

License

MIT License - see LICENSE file for details.

Metadata

Release files for py-nycmta 0.2.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 py-nycmta 0.2.0
File Size Uploaded Provenance Actions
py_nycmta-0.2.0.tar.gz 27.1 kB Without provenance Details for py_nycmta-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for py-nycmta 0.2.0
File Interpreter ABI Platform Actions
py_nycmta-0.2.0-py3-none-any.whl Python 3 none any Details for py_nycmta-0.2.0-py3-none-any.whl

Total release size: 46.1 kB

Release files / py_nycmta-0.2.0.tar.gz

Download URL py_nycmta-0.2.0.tar.gz
Size 27.1 kB
Tags Source
SHA-256 checksum
How to use checksums
704b5b54eecf610e6bbf6af9bea86e6edaf9beaa3baaa46e7292a689349d12a6
BLAKE2b-256 checksum
How to use checksums
138bc84d4cf482d2bb76e512b86daae1ea89e0640c3d878b15ae0f31df0be087
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.3

Release files / py_nycmta-0.2.0-py3-none-any.whl

Download URL py_nycmta-0.2.0-py3-none-any.whl
Size 18.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
12e54f2178a102df981b262123b7f64ad49373defa9e2716211766e15ae1be89
BLAKE2b-256 checksum
How to use checksums
acd7301036338d5a4b2529f68d42dc0705873b8077f4767ac13ec8ca709ab99d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.3

Security for py-nycmta 0.2.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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files No provenance

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