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
- Create a account at: https://developers.deutschebahn.com
- Create a new application using this url: https://developers.deutschebahn.com/db-api-marketplace/apis/application/new and choose a name that you want
- After that save you the client id and the client secret. You need it to interact with the api
- Navigate to all available apis page at: https://developers.deutschebahn.com/db-api-marketplace/apis/product and select the "Timetables" api
- And click the red subscribe button and select your application
- Now you are done and can start using the api
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_authentication = 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(station_helper, api_authentication)
trains_in_this_hour = timetable_helper.get_timetable()
trains_at_given_hour = timetable_helper.get_timetable(12)
trains_at_given_hour_tomorrow = timetable_helper.get_timetable(12, datetime.now() + timedelta(days=1)) # It's also possible to request the next day
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)
Metadata
Release files for deutsche-bahn-api 1.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| deutsche_bahn_api-1.1.0.tar.gz | 263.1 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| deutsche_bahn_api-1.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 543.5 kB
Release files / deutsche_bahn_api-1.1.0.tar.gz
| Download URL | deutsche_bahn_api-1.1.0.tar.gz |
|---|---|
| Size | 263.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
34372193d2b105dcc97ba13384031ea2aacd27728a9c006170a6d5a6d136aa99
|
|
BLAKE2b-256 checksum How to use checksums |
59a87cf0b1e0bdab5d9831582d2732542a6c0307f1577c796d45a7971e2c355d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.9.6
|
Release files / deutsche_bahn_api-1.1.0-py3-none-any.whl
| Download URL | deutsche_bahn_api-1.1.0-py3-none-any.whl |
|---|---|
| Size | 280.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
cad2f59e2731d7a363e92990afdc545e87bdbfb50197664f372aba9645b04ad7
|
|
BLAKE2b-256 checksum How to use checksums |
44ceb0da683935429cb683b4351fa5302fc0aa31bd0b69f1e39d0e0b04bcba35
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.9.6
|
Security for deutsche-bahn-api 1.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.