Skip to main content

A small package to work with the Deutsche Bahn timetables api

Project description

Deutsche Bahn Api

This is a small Python package to access the Deutsche Bahn timetables api. The timetable api is able to request the timetable of a specific station and access all dynamic changes on the timetable e.g. changed departure or arrival of the train, changed platform of arrival or a changed path of the train.

Setup

ApiAuthentication

Create a new ApiAuthentication class and pass to it the newly created client id and client secret. And test with the api.test_credentials() function if the api authentication works.

api = ApiAuthentication("YOUR_CLIENT_ID", "YOUR_CLIENT_SECRET")
success: bool = api.test_credentials()

Stations

To get the timetable of a specific train station you can use the name or lat and long values.

station_helper = StationHelper()
found_stations = station_helper.find_stations_by_lat_long(47.996713, 7.842174, 10)
found_stations_by_name = station_helper.find_stations_by_name("Freiburg")

Timetable

With the station object you are able to request the timetable from the station using the following code.

timetable_helper = TimetableHelper(YOUR_STATION_OBJECT, YOUR_API_AUTHENTICATION_OBJECT)
trains_in_this_hour = timetable_helper.get_timetable()
trains_at_given_hour = timetable_helper.get_timetable(12)

This method returns you a list with all trains that are scheduled for departure at this station in the current hour. You can also pass the get_timetable() function the hour you want to request. Important this list don't contains delays, platform changes or changed stations. This can be achieved by using the get_timetable_changes() function and passing the list from the previous step.

trains_with_changes = timetable_helper.get_timetable_changes(trains)

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

deutsche-bahn-api-1.0.6.tar.gz (262.8 kB view details)

Uploaded Source

Built Distribution

deutsche_bahn_api-1.0.6-py3-none-any.whl (280.1 kB view details)

Uploaded Python 3

File details

Details for the file deutsche-bahn-api-1.0.6.tar.gz.

File metadata

  • Download URL: deutsche-bahn-api-1.0.6.tar.gz
  • Upload date:
  • Size: 262.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.5

File hashes

Hashes for deutsche-bahn-api-1.0.6.tar.gz
Algorithm Hash digest
SHA256 b0c8a2af2bc2b02f5945ed18c356ee70214faf3bb2f95778742e074cd19f8021
MD5 0fe0572c0eb5e73292047e76d4160869
BLAKE2b-256 157c1e5fbdc21ac9ec222d429c43e409e499bfcf5e880f9ebcf878ceafb16be6

See more details on using hashes here.

File details

Details for the file deutsche_bahn_api-1.0.6-py3-none-any.whl.

File metadata

File hashes

Hashes for deutsche_bahn_api-1.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 84b1227c08c42a808a56f75aba813631fe2305404c8874b5ddc26f52809c86b1
MD5 b788b69f45cdf1c1021353e64b27e6d8
BLAKE2b-256 197f236b6e991dc0b3a23c397685baf1b8c35780bb5872ee26bb6cdebd114093

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