Skip to content

Documentation

anonymous44401 edited this page Jul 27, 2026 · 25 revisions

Documentation

Contents

Method Description
Get Departures Get the departures for a given station.
Get Service Get the service information for a given service.
Get Live Get a live departure board for a given station.
Watch Service Coming Autumn 2026

Get Departures

The get_departures method returns the departures and arrivals for the station you specified.

The get_departures method takes up to 6 arguments. These are:

  • tiploc (Timing point location code) (a string) - like "KNGX"
  • filter_from (a string) - like "STEVNGE"
  • filter_to (a string) - like "STEVNGE"
  • date (a string) - like "2024-11-16"
  • rows (an integer) - like 15
  • time (a string) - like "1250" or "12:50"

A tiploc is required. The filter_from, filter_to, time, date and rows1 arguments are all optional. If left blank, filters will not be applied, the date and time will default to the current date and time and the rows will default to the number of rows returned by the API.

The time you pass into the function should be a string of the 24-hour time you need. For example, if you're looking for arrivals at 16:55, you can enter "1655" or "16:55".

Here is one request you could provide:

get_departures(tiploc="KNGX", filter_to="STEVNGE", date="2024-11-16", time="1250", rows=20)

This request will return up to 20 rows of departures for London King's Cross (KNGX) on 16-11-2024 around 12:50, provided they call at Stevenage (STEVNGE).

Tip

In the tiploc, filter_to and filter_from fields, station CRS (Computer Reservation System) codes can be provided instead of a TIPLOC (Timing Point Location) code.

A list of TIPLOC and CRS codes can be found here. This site is not managed by anonymous44401.

Data Extraction - Normal Mode

To get departure data out of the objects, you'll need to iterate through them. Remember you can only do this if you're using normal mode.

Each request you make will return an object, with the following attributes:

  • .location - The requested location
  • .board - The contents of the departure board
    • .scheduled_arrival - The arrival time of the service according to the timetable
    • .scheduled_departure - The departure time of the service according to the timetable
    • .terminus - The terminus of the service
    • .origin - The origin of the service
    • .platform - The platform the service will depart from
    • .expected_arrival - The expected arrival time of the service
    • .expected_departure - The expected departure time of the service
    • .service_uid - The Unique ID of the service
    • .coaches - The number of coaches the service has

For example, to get the terminus of each service the following code can be implemented:

departures = get_departures(tiploc="KNGX", filter_to="STEVNGE")

print(f"Departures for {departures.location}:\n")

for service in departures.board:
    print(service.terminus)

And here's the example output for the above code:

Departures for London Kings Cross:

Cambridge
Lincoln Central
Cambridge
Leeds
Cambridge
York
Cambridge
Harrogate
Cambridge
Lincoln Central
Cambridge
Bradford Forster Square
Cambridge
Peterborough
Cambridge
Harrogate

Get Service

The get_service method returns the information for the specified service.

The get_service method takes up to 2 arguments. These are:

  • service_uid (a string) - like "G54072"
  • date (a string) - like "2024-11-16"

A service_uid is required. The date argument is optional; it will default to the current date if left blank.

Here is one request you could provide:

get_service(service_uid="G54072", date="2024-11-16")

This request will return the service information for G54072 on 16-11-2024.

Data Extraction - Normal Mode

To get service data out of the objects, you'll need to iterate through them. You can only do this if you're using normal mode.

Each request you make will return an object, with the following attributes:

  • .service_uid - The Unique ID of the service
  • .operator - The operator of the service
  • .origin - The origin of the service
  • .destination - The destination of the service
  • .calling_points - A list of calling point objects.
    • .stop_name - The name of this stop
    • .scheduled_arrival - The arrival time of the service according to the timetable
    • .expected_arrival - The expected arrival time of the service
    • .platform - The platform the service will depart from
    • .line - The line the train will be taking
    • .scheduled_departure - The departure time of the service according to the timetable
    • .expected_departure - The expected departure time of the service
    • .coaches - The number of coaches the service has2
  • .start_time - The start time of the service according to the timetable
  • .end_time - The end time of the service according to the timetable
  • .coaches - The number of coaches the service has2

You should iterate through the calling points to get the data out of the objects.

For example, to get the calling points of each service the following code can be implemented:

service_details = get_service(service_uid="W23502")

print(f"Service: {service_details.service_uid}\n")
for calling_point in service_details.calling_points:
    print(f"{calling_point.stop_name}: {calling_point.expected_arrival}")

And here's the example output for the above code:

Service: W23502

Cambridge: 
Foxton: 07:05
Shepreth: 07:08
Meldreth: 07:11
Royston: 07:16
Ashwell & Morden: 07:21
Baldock: 07:26
Letchworth: 07:29
Hitchin: 07:33
Stevenage: 07:39
Knebworth: 07:43
Welwyn North: 07:46
Welwyn Garden City: 07:50
Hatfield: 07:55
Potters Bar: 08:00
Alexandra Palace: 08:09
Finsbury Park: 08:14
London Kings Cross: 08:22

Get Live

The get_live method displays a live departure board for the specified tiploc. The board will automatically update every 90 seconds, to prevent API overuse. This method does not change its output based on your selected complexity; it is meant to replicate a real life station departure board.

The get_live method takes up to 2 arguments. These are:

  • tiploc (Timing point location code) (a string) - like "KNGX"
  • mode (a string) - like "LCD"

The tiploc argument is mandatory. The mode argument is optional.

Types of mode:

  • LCD (Liquid Crystal Display)
    • A board style that uses a variety of colours for different information on the board. This is the default mode if not provided. Use mode="LCD".
  • DMI (Yellow) (Display Machine Interface)
    • A board style that shows all text in yellow. Use mode="DMI_yellow".
  • DMI (White) (Display Machine Interface)
    • A board style that shows all text in white. Use mode="DMI_white".

The departure board will run infinitely until there is a connection error or you close the board by pressing Ctrl + C.

Your request token expires after approximately 20 minutes. realtime-trains-py will automatically generate a new one when it expires.

Here are some requests you could provide:

get_live(tiploc="ELYY") # Live board for Ely.

get_live(tiploc="PBRO", mode="DMI_yellow") # Live board for Peterborough - DMI Yellow mode.

And here's the example output for the Live Board for Ely:

Ely Live:
16:54 Stansted Airport 2 On time
Calling at: Cambridge, Stansted Airport
16:56 Kings Lynn 1 On time
17:00 Peterborough 1 On time
     16:52:30

Footnotes

1 rows will be ignored if you're using complex mode.

2 There are two coaches attributes for get_service as some services split at some stops, so their number of coaches will change.

The number of coaches within the calling point shows the number of coaches the service has at that particular stop, whereas the number of coaches outside the calling point shows the number of coaches at the end of the service.

Clone this wiki locally