Skip to main content

db-timetables

A Python library for the Deutsche Bahn Timetables API.

Requirements

  • Python 3.13+
  • requests

Installation

uv add db-timetables

Or with pip:

pip install db-timetables

Setup

  1. Register at developers.deutschebahn.com, create an application, and subscribe to the Timetables API.
  2. Copy your Client ID and API Key.

Usage

from db_timetables import TimetablesClient

client = TimetablesClient(
    client_id="your_client_id",
    api_key="your_api_key",
)

Find a station

stations = client.get_station("Frankfurt")
# [Station(name='Frankfurt am Main - Stadion', eva='8002040'), ...]

eva = stations[0].eva

Stations are identified by their EVA number, a numeric DB station ID.

Planned timetable

plan = client.get_plan(eva)               # current hour
plan = client.get_plan(eva, hour=14)      # specific hour today
plan = client.get_plan(eva, date=datetime(2026, 5, 20), hour=9)

for stop in plan.stops:
    dp = stop.departure
    print(stop.train_line.display_name, dp.planned_time, dp.planned_platform)

Returns one hour of scheduled departures/arrivals. No live data.

Live timetable (plan + changes merged)

live = client.get_timetable_with_changes(eva)

for stop in live.stops:
    dp = stop.departure
    if dp and dp.delay_minutes:
        print(f"{stop.train_line.display_name} is +{dp.delay_minutes} min late")
    if stop.is_cancelled:
        print(f"{stop.train_line.display_name} is cancelled")

This is the most useful method - it fetches the plan and all current deviations, then merges them so each stop reflects reality.

Changes only

# All current deviations for the station (delays, cancellations, platform changes)
changes = client.get_full_changes(eva)

# Only what changed since your last call - use this when polling
recent = client.get_recent_changes(eva)

Data model

TimetableStop

Attribute Type Description
id str Unique stop identifier
train_line TrainLine Train category and number
arrival ArrivalDeparture | None Arrival data
departure ArrivalDeparture | None Departure data
messages list[Message] Delay/disruption messages
is_cancelled bool True if arrival or departure is cancelled

ArrivalDeparture

Attribute Type Description
planned_time datetime | None Scheduled time
changed_time datetime | None Actual/expected time (set when delayed)
planned_platform str Scheduled platform
changed_platform str Actual platform (set when changed)
planned_path list[str] Scheduled route as station names
changed_path list[str] Actual route (set when rerouted)
effective_time datetime | None changed_time if set, else planned_time
effective_platform str changed_platform if set, else planned_platform
delay_minutes int | None Difference in minutes, or None if on time
is_cancelled bool True if status is cancelled

TrainLine

Attribute Type Description
category str Train category (ICE, IC, RE, S, …)
number str Train number
owner str Operator code
display_name str "{category} {number}" (e.g. "ICE 9551")

Station

Attribute Type Description
eva str EVA station number
name str Station name
ds100 str DS100 abbreviation
lat / lon float Coordinates

Exceptions

Exception When
AuthenticationError Invalid or missing credentials (401/403)
NotFoundError Station or resource not found (404)
RateLimitError Too many requests (429) - free tier allows 60 req/min
DBApiError Any other API or network error
from db_timetables import TimetablesClient, RateLimitError, NotFoundError

try:
    stations = client.get_station("München")
except NotFoundError:
    print("No stations found")
except RateLimitError:
    print("Slow down - rate limit hit")

API reference

Full DB API documentation: developers.deutschebahn.com

Data is provided under CC BY 4.0.

Metadata

Release files for db-timetables 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for db-timetables 0.1.1
File Size Uploaded Provenance Actions
db_timetables-0.1.1.tar.gz 23.0 kB Without provenance Details for db_timetables-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for db-timetables 0.1.1
File Interpreter ABI Platform Actions
db_timetables-0.1.1-py3-none-any.whl Python 3 none any Details for db_timetables-0.1.1-py3-none-any.whl

Total release size: 32.9 kB

Release files / db_timetables-0.1.1.tar.gz

Download URL db_timetables-0.1.1.tar.gz
Size 23.0 kB
Tags Source
SHA-256 checksum
How to use checksums
62515e531f7f065ab2ea855108cd55665764a47d2b73fa0bf35cbc42e9368f8d
BLAKE2b-256 checksum
How to use checksums
a7796245df3d4da61fdca70345b55b3a0eb95a26ecfc07ea09b18e1714fded78
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.8 {"installer":{"name":"uv","version":"0.11.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / db_timetables-0.1.1-py3-none-any.whl

Download URL db_timetables-0.1.1-py3-none-any.whl
Size 10.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f7970a3f6afa6d45ec4a5c650ad2e195f2ac78aac44d20a8f6731d87d6b064df
BLAKE2b-256 checksum
How to use checksums
2cdcf129e514d5f385221eefd29d0523f60f7f925e94ee8a908f1de675002edd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.8 {"installer":{"name":"uv","version":"0.11.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for db-timetables 0.1.1

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.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page