Skip to main content

An unofficial Python library for Realtime Trains API

Project description

Introduction

This is an unofficial Python library for the Realtime Trains API.

The library allows you to make calls to the Realtime Trains API, and receive full response as JSON, or as custom objects. Some basic helper filtering of data is also included.

Requirements

This library requires you to use your own API key, which (at the time of writing) can be obtained for free from Realtime Trains developer website.

Once registered and logged in, please make note of the API Auth Credentials that have automatically been generated for your account.

Installation

Use pip to install this library. We recommend you use it within a virtual environment (either with venv or poetry).

pip install realtime-trains

Usage

To be able to use the library, you need to authenticate yourself. The result will be an object which you can then use to query the Realtime Trains data.

from realtime_trains.realtime_trains.api import RealtimeTrainsApi, SearchOptions

rtt = RealtimeTrainsApi(username="<your_rtt_username>", password="<your_rtt_password>")

Request station information

To specify the search options, use the SearchOptions class.

options = SearchOptions(
	from_station = "CLJ",	# required
	to_station = "WAT",		# optional
	date = "25 Jan 2024", 	# optional
	time = "13:45",			# optional
	platform = "2",			# optional
	num_results = 5,		# optional
	passenger_only = True,	# optional
	show_arrivals = False,	# optional
	show_trains_only = True	# optional
)

NOTE: Not all options apply to all calls.

After you have created your authenticated object and you specified the search options, you can start requesting data.

Get raw json response

json = rtt.get_search_json(options)

Get resulting data as an object

data = rtt.get_search(options)

Get data as a list of train services

services = rtt.get_search_services(options)

Reporting issues

Please report all the issues and feature requests via GitHub.

Enjoy!

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

realtime_trains-0.0.5.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

realtime_trains-0.0.5-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

Details for the file realtime_trains-0.0.5.tar.gz.

File metadata

  • Download URL: realtime_trains-0.0.5.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.10.12 Linux/5.15.133.1-microsoft-standard-WSL2

File hashes

Hashes for realtime_trains-0.0.5.tar.gz
Algorithm Hash digest
SHA256 c728fc86b150c8dd7edf4d2390a2d736218d1be430204948b4767144d72624bb
MD5 0c3d839695a7687c86a3552f7a8b1be7
BLAKE2b-256 1661d2eaa09aaacf36d76c5d3a07cf6c9660a14c0aa40df7fd73f0540c45969a

See more details on using hashes here.

File details

Details for the file realtime_trains-0.0.5-py3-none-any.whl.

File metadata

  • Download URL: realtime_trains-0.0.5-py3-none-any.whl
  • Upload date:
  • Size: 5.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.10.12 Linux/5.15.133.1-microsoft-standard-WSL2

File hashes

Hashes for realtime_trains-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 d522102b48da2ae2bcbffd42133bf2c68076949fb319930b147fc2ceb31c33e3
MD5 4f5eb6039976e5c504b4598fe4aeff56
BLAKE2b-256 8991e87b5d6d1dbf3ec7809d01890455058f8c1affa07b59421bfbc69b171a51

See more details on using hashes here.

Supported by

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