Skip to main content

Simple Alameda-Contra Costa Transit District (AC Transit) API wrapper

Project description

PyPI version fury.io PyPI pyversions

A simple Alameda-Contra Costa Transit District (AC Transit) API wrapper.

Installation

pip install python-actransit

API Examples

Make an instance of the ACTransit class.

from actransit import ACTransit
ac_transit = ACTransit()

Get vehicle information and positions from a GTFS real-time feed.

realtime_vehicles = ac_transit.gtfsrt.vehicles()
print(realtime_vehicles)

{'entity': [{'id': '1',
            'vehicle': {'position': {'bearing': 116.0,
                                    'latitude': 37.80388259887695,
                                    'longitude': -122.276611328125,
                                    'speed': 0.0},
                        'timestamp': 1579463770,
                        'trip': {'route_id': '19',
                                'schedule_relationship': 0,
                                'trip_id': '751100010'},
                        'vehicle': {'id': '5020'}}},
            # ...
            ],
'header': {'gtfs_realtime_version': '1.0',
            'incrementality': 0,
            'timestamp': 1579463788}}

Get information for any existing schedule: current, past and future.

existing_schedules = ac_transit.gtfs.all()
print(existing_schedules)

[{'BookingId': '1912WR',
'EarliestServiceDate': '2019-12-14T00:00:00',
'LatestServiceDate': '2020-03-28T00:00:00',
'UpdatedDate': '2019-12-11T07:45:25.96'},
{'BookingId': '1908FA',
'EarliestServiceDate': '2019-08-10T00:00:00',
'LatestServiceDate': '2019-12-14T00:00:00',
'UpdatedDate': '2019-08-01T15:20:19.587'},
# ...
]

Get trip information for a bus route (e.g. route 212).

route_212 = ac_transit.route.trips(rt=212)
print(route_212)

{'RouteId': '212', 'Name': '212', 'Description': 'Fremont Blvd. - Pacific Commons'}

Get real-time predictions for a bus stop (e.g. stop ID 51331).

predict_stop = ac_transit.actrealtime.prediction(stpid=51331)
print(predict_stop)

{'bustime-response': {'prd': [{'des': 'Downtown Berkeley',
                           'dly': False,
                           'dstp': 1490,
                           'dyn': 0,
                           'geoid': '3539',
                           'prdctdn': '1',
                           'prdtm': '20200122 10:47',
                           'rid': '604',
                           'rt': '6',
                           'rtdd': '6',
                           'rtdir': 'To Downtown Berkeley',
                           'schdtm': '20200122 10:47',
                           'seq': 7,
                           'stpid': '51331',
                           'stpnm': 'Telegraph Av + 29th St',
                           'tablockid': '6002',
                           'tatripid': '6619563',
                           'tmstmp': '20200122 10:45',
                           'tripdyn': 0,
                           'tripid': '743320020',
                           'typ': 'A',
                           'vid': '1350',
                           'zone': ''},
                           # ...
                          ]}}

Get information for every AC Transit bus stop.

all_stops = ac_transit.stops.all()
print(all_stops)

[{'Latitude': 37.7773372,
'Longitude': -122.2630574,
'Name': 'Sherman St:Buena Vista Av',
'ScheduledTime': None,
'StopId': 52304},
{'Latitude': 37.9262186,
'Longitude': -122.3169712,
'Name': 'Cutting Blvd:Ohlone Greenway (Del Norte BART)',
'ScheduledTime': None,
'StopId': 52306},
# ...
]

Every method in ACTransit

from actransit import ACTransit
ac_transit = ACTransit()


# GTFS
ac_transit.gtfs.all()

# GTFSRT
ac_transit.gtfsrt.vehicles()
ac_transit.gtfsrt.alerts()
ac_transit.gtfsrt.tripupdates()

# Routes
ac_transit.route.all()
ac_transit.route.directions(rt)  # route ID (type int or str)
ac_transit.route.trips(rt, direction='')  # route ID (type int or str) and direction (type str)
ac_transit.route.tripsestimates(rt, fromStopID='', toStopID='') # route ID and stop ID (both type int or str)
ac_transit.route.tripsinstructions(rt, direction='')  # route ID (type int or str) and direction (type str)
ac_transit.route.vehicles(rt)  # route ID (type int or str)

# AC Transit real-time
ac_transit.actrealtime.detour(rt='', rtdir='')   # route ID (type int or str) and route direction (type str)
ac_transit.actrealtime.direction(rt)  # route ID (type int or str)
ac_transit.actrealtime.line()
ac_transit.actrealtime.locale()
ac_transit.actrealtime.pattern(pid='', rt='')  # PID and route ID (both type int or str)
ac_transit.actrealtime.prediction(stpid='', rt='', vid='', top='', tmres='')  # stop ID, route ID, vehicle ID,
# max items return, time resolution ('s', 'm')  (all type int or str, except tmres, which takes str)
ac_transit.actrealtime.time(unixTime='')  # UNIX time (type int or str)
ac_transit.actrealtime.servicebulletin(rt='', rtdir='', stpid='')  # route ID, route direction, and stop ID
# (all type int or str, except rtdir, which takes str)
ac_transit.actrealtime.stop(rt='', dir='', stpid='')  # route ID, route direction, and stop ID
# (all type int or str, except dir, which takes str)
ac_transit.actrealtime.vehicle(vid='', rt='', tmres='') # vehicle ID, route ID, and time resolution
# (all type int or str, except tmres, which takes str)

# Vehicle
ac_transit.vehicle.id(id)  # vehicle ID (type int or str)

# Stops
ac_transit.stops.all()
ac_transit.stops.predictions(stpid)  # stop ID (type int or str)
ac_transit.stops.routes(stpid)  # stop ID (type int or str)

Contribute

Support

If you are having issues or would like to propose a new feature, please use the issues tracker.

License

The project is licensed under the MIT license.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

python-actransit-0.1.4.tar.gz (6.3 kB view details)

Uploaded Source

Built Distribution

python_actransit-0.1.4-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

Details for the file python-actransit-0.1.4.tar.gz.

File metadata

  • Download URL: python-actransit-0.1.4.tar.gz
  • Upload date:
  • Size: 6.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.12

File hashes

Hashes for python-actransit-0.1.4.tar.gz
Algorithm Hash digest
SHA256 bd32546da2e8f790d4d46f4f119fcf9ccad00757a55a5c2fb91b43b0fb0c4b80
MD5 52deb0546384125c02a95bef00116cdb
BLAKE2b-256 aa02e022b8635126d51ac4ba6f0cc37fa232f579760709f162d40ab8f9a31caf

See more details on using hashes here.

File details

Details for the file python_actransit-0.1.4-py3-none-any.whl.

File metadata

File hashes

Hashes for python_actransit-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 f05403612a0a4b332fb11e80a41aeeab4722658bd4f1e215ebbbd8d2f15b6a94
MD5 a8f95750e8b14eb07222fa37811f2929
BLAKE2b-256 8fad13e253d02f61a248f7f0e05b35b7cf9afcfb689155e0aa00e6ff9c80d436

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page