-
Notifications
You must be signed in to change notification settings - Fork 3
Examples
anonymous44401 edited this page Jul 12, 2026
·
11 revisions
Tip
For different example data, head over to the main branch on the repository and head to the /examples folder.
In the folder, you'll be able to find a whole range of example code you can run and modify.
A few examples are provided here:
# Import the package
from realtime_trains_py import RealtimeTrainsPy
# Configure the package
rtt = RealtimeTrainsPy(
request_token="<YOUR_REQUEST_TOKEN>",
complexity="simple"
)
# Get the departures
rtt.get_departures(tiploc="KNGX")Below is the following output for the above command:
╭──────────────────┬────────────────────┬──────────────────────┬────────────┬──────────────────┬───────────────╮
│ Booked Arrival │ Destination │ Origin │ Platform │ Actual Arrival │ Service UID │
├──────────────────┼────────────────────┼──────────────────────┼────────────┼──────────────────┼───────────────┤
│ 18:00 │ London Kings Cross │ Leeds │ 0 │ Exp 18:13 │ C71246 │
├──────────────────┼────────────────────┼──────────────────────┼────────────┼──────────────────┼───────────────┤
│ 18:02 │ London Kings Cross │ Ely │ 10 │ Exp 18:13 │ W23374 │
├──────────────────┼────────────────────┼──────────────────────┼────────────┼──────────────────┼───────────────┤
│ 18:05 │ London Kings Cross │ Bradford Interchange │ 1R │ Exp 18:15 │ G26250 │
├──────────────────┼────────────────────┼──────────────────────┼────────────┼──────────────────┼───────────────┤
│ 18:22 │ London Kings Cross │ York │ 2 │ On time │ C71632 │
├──────────────────┼────────────────────┼──────────────────────┼────────────┼──────────────────┼───────────────┤
│ 18:21 │ London Kings Cross │ Cambridge │ 8 │ Exp 18:27 │ W23573 │
├──────────────────┼────────────────────┼──────────────────────┼────────────┼──────────────────┼───────────────┤
│ 18:30 │ London Kings Cross │ Harrogate │ 7 │ Exp 18:31 │ C71248 │
├──────────────────┼────────────────────┼──────────────────────┼────────────┼──────────────────┼───────────────┤
│ 18:32 │ London Kings Cross │ Kings Lynn │ 10 │ On time │ W23380 │
├──────────────────┼────────────────────┼──────────────────────┼────────────┼──────────────────┼───────────────┤
│ 18:41 │ London Kings Cross │ Edinburgh │ 6 │ Exp 18:39 │ C71442 │
├──────────────────┼────────────────────┼──────────────────────┼────────────┼──────────────────┼───────────────┤
│ 18:48 │ London Kings Cross │ Edinburgh │ 5 │ Exp 18:44 │ C71445 │
├──────────────────┼────────────────────┼──────────────────────┼────────────┼──────────────────┼───────────────┤
│ 18:51 │ London Kings Cross │ Cambridge │ 8 │ Exp 18:50 │ W23578 │
├──────────────────┼────────────────────┼──────────────────────┼────────────┼──────────────────┼───────────────┤
│ 19:00 │ London Kings Cross │ Leeds │ 3 │ Exp 18:57 │ C71251 │
├──────────────────┼────────────────────┼──────────────────────┼────────────┼──────────────────┼───────────────┤
│ 19:02 │ London Kings Cross │ Kings Lynn │ 9 │ Exp 19:01 │ W23385 │
├──────────────────┼────────────────────┼──────────────────────┼────────────┼──────────────────┼───────────────┤
│ 19:06 │ London Kings Cross │ Sunderland │ 1F │ On time │ G26248 │
├──────────────────┼────────────────────┼──────────────────────┼────────────┼──────────────────┼───────────────┤
│ 19:22 │ London Kings Cross │ Lincoln Central │ 0 │ Exp 19:19 │ C71302 │
├──────────────────┼────────────────────┼──────────────────────┼────────────┼──────────────────┼───────────────┤
│ 19:23 │ London Kings Cross │ Welwyn Garden City │ 9 │ On time │ W23581 │
├──────────────────┼────────────────────┼──────────────────────┼────────────┼──────────────────┼───────────────┤
# -- snip --
│ 22:02 │ London Kings Cross │ Kings Lynn │ 9 │ Exp 22:01 │ W23418 │
├──────────────────┼────────────────────┼──────────────────────┼────────────┼──────────────────┼───────────────┤
│ 22:08 │ London Kings Cross │ Aberdeen │ 0 │ Exp 22:05 │ C71463 │
╰──────────────────┴────────────────────┴──────────────────────┴────────────┴──────────────────┴───────────────╯
# Import the package
from realtime_trains_py import RealtimeTrainsPy
# Configure the package
rtt = RealtimeTrainsPy(
request_token="<YOUR_REQUEST_TOKEN>",
complexity="simple_normal"
)
# Get the arrivals
departures = rtt.get_departures(tiploc="LEEDS", date="2025-01-10")
for departures in departures.board:
# Print the details
print(f"{departures.service_uid} | {departures.scheduled_arrival} | {departures.origin} to {departures.terminus}")Below is the following output for the above command:
W47683 | 23:54 | York to Leeds
W45825 | 00:03 | Blackpool North to Leeds
P13154 | 23:57 | Redcar Central to Manchester Victoria
W46174 | 00:09 | Manchester Victoria to Leeds
C71394 | 00:12 | London Kings Cross to Leeds
P13844 | 00:15 | Huddersfield to York
W47230 | 00:22 | Doncaster to Leeds
P13842 | 00:22 | Selby to Leeds
P13055 | 00:15 | Scarborough to Manchester Piccadilly
P13837 | 00:24 | Huddersfield to Leeds
W49477 | 00:27 | Sheffield to Leeds
C58575 | 00:32 | Leeds Bradford Airport to Leeds
P13162 | 00:15 | Manchester Airport to York
N36168 | 00:39 | Bradford Interchange to Leeds
W52371 | 00:41 | Selby to Leeds
W46021 | 00:45 | Manchester Victoria to Leeds
W52379 | 00:50 | York to Leeds
C71475 | 00:57 | Aberdeen to Leeds
N36171 | 01:15 | Halifax to Leeds
P13839 | 01:24 | Huddersfield to Leeds
P13166 | 01:19 | Manchester Airport to York
C71397 | 02:17 | London Kings Cross to Leeds
P12947 | 02:08 | York to Manchester Victoria
P12942 | 02:05 | Manchester Victoria to York
P12954 | 03:13 | York to Manchester Airport
P12950 | 04:13 | Manchester Piccadilly to York
C58453 | 05:37 | Leeds Bradford Airport to Leeds
P13060 | 05:40 | York to Manchester Victoria
P12957 | 05:50 | Manchester Victoria to Scarborough
C58459 | 06:07 | Leeds Bradford Airport to Leeds
# -- snip --
All of our data is kindly provided by Realtime Trains.