Skip to main content

realtime-trains-api-python README

A Python wrapper for the Realtime Trains API v1.

This library simplfies the process of making a call to the Realtime Trains API. Requests to specific endpoints can be made from the RttApi class, with the returned JSON data parsed and wrapped into a data object.

For now this is a literal mapping of the Realtime Trains API data structure into Python data classes. Helper functionality may be added in future.

Prerequisites

In order to make requests from this library you must first sign up for a Realtime Trains API account. You can do so at api.rtt.io.

Getting Started

IMPORTANT - Note that you must use the API Auth Credentials as displayed within your Realtime Trains API account, not the credentials you use to log into the website.

Create an instance of an RttApi object using your Realtime Trains API auth credentials like so:

from rttapi.api import RttApi

api = RttApi('rttapi_exampleuser', '00112233aabbccdd')

Request Station Information

To request the list of upcoming departures from Clapham Junction station:

departures = api.search_station_departures('CLJ') 

This will return a SearchResult object with containing the station details and the list of upcoming departures. You may either search using the three-letter CRS (computer reservation system) code, or a longer TIPLOC (timing point location) code. You can find a station's CRS code by searching on the National Rail website.

Arrivals can also be queried by using:

arrivals = api.search_station_arrivals('CLJ') 

Which again returns a SearchResult object.

A detailed breakdown on the information returned can be found on the Realtime Trains API documentation page. This library mirrors the data returned by the API, albeit using Pythonesque underscore_case properties instead of the camelCase properties returned by the API.

Request Detailed Service Information

Detailed journey information for an individual service can be queried using:

service_info = api.fetch_service_info_datetime(service_uid, service_date) 

where:

  • service_uid is the unique identifier of the service obtained from the SearchResult e.g. 8U09FW
  • service_datetime is a datetime.date object representing the date on which the service is due to depart.

Alternatively, the year, month and day of departure can be explicitly set (e.g. 27th March 2021) by using:

service_info = api.fetch_service_info_ymd('8U09FW', '2021', '3', '27') 

Both of these examples will return a Service object, which is explained in more detail on the Realtime Trains API documentation page.

Other Examples

A more detailed example on how to use this library can be found in my pyRailTimes project.

Thanks

With thanks to the Realtime Trains API team.

Release files for rttapi 0.1.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 rttapi 0.1.0
File Size Uploaded
rttapi-0.1.0.tar.gz 9.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for rttapi 0.1.0
File Interpreter ABI Platform
rttapi-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 20.2 kB

Release files / rttapi-0.1.0.tar.gz

Download URL rttapi-0.1.0.tar.gz
Size 9.8 kB
Tags Source
SHA-256 checksum
How to use checksums
16f769441bd064446fd8fdd2d204f74ffa7fb183b52f7c65b9989f879ed5bde5
BLAKE2b-256 checksum
How to use checksums
e3a992fc568cfbc893bb40b87028e335bc6a4c104ef36bfa5122e3ec3c624b97
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.8

Release files / rttapi-0.1.0-py3-none-any.whl

Download URL rttapi-0.1.0-py3-none-any.whl
Size 10.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f51f8a882d4a25f438d8c26c145c8ad5c77e9cb999b30b4cb7b5dd322c6fe2ba
BLAKE2b-256 checksum
How to use checksums
b559afda1982e47d9f0fc8ec7d4c3d39776e2f19106d59022bb68ee806a584fd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.8

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

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