Skip to main content

A Python library for interacting with Deutsche Bahn data.

Project description

Pybahn

A Python library to query Deutsche Bahn journey, departure, and arrival data using the (unofficial) API.

📚 Table of Contents

📦 Installation

pip install pybahn

🛠️ Usage

🔧 Initialize PyBahn

from pybahn import PyBahn

bahn = PyBahn("your_app")

🔍 Search Station

stations = bahn.stations("Berlin")

print(stations[0].name)

📍 Get a Single Station

station = bahn.station("Munich")

🗺️ Nearby Stations

stations = bahn.nearby(latitude=00.00000, longitude=00.0000)

🚉 Departures

departures = bahn.departures("8000105")  # Berlin Hbf

print(departures[0].lineName)

or

station = bahn.station("Munich")

departures = bahn.departures(station)

print(departures[0].lineName)

🚉 Arrivals

arrivals = bahn.arrivals("8000105")  # Berlin Hbf

print(arrivals[0].lineName)

or

station = bahn.station("Munich")

arrivals = bahn.arrivals(station)

print(arrivals[0].lineName)

🚆 Journeys

station1 = bahn.station("Frankfurt")

station2 = bahn.station("Berlin")

journeys = bahn.journeys(station1.lid, stat2.lid)

print(journeys[0].arrival_name)

or

station1 = bahn.station("Frankfurt")

station2 = bahn.station("Berlin")

journeys = bahn.journeys(station1, station2)

print(journeys[0].arrival_name)

🎯 Filter Departures/Arrivals

from pybahn.structs import Products
from datetime import datetime

station1 = bahn.station("Frankfurt")

station2 = bahn.station("Berlin")

time = datetime.now().strftime("%Y-%m-%dT%H:%M:%S")

journeys = bahn.journeys(departure = station1, 
                      destination = station2, 
                      time = time,
                      products = [Products.EC_IC, Products.SBAHN],
                      only_d_ticket = True)

print(journeys[0].changes_amont)

🎯 Filter Journeys

from pybahn.structs import Products


station1 = bahn.station("Frankfurt")

station2 = bahn.station("Berlin")

journeys = bahn.journeys(station1.lid, station2.lid, products=Products.REGIONALS)

print(journeys[0].changes_amont)

or

from pybahn.structs import Products


station1 = bahn.station("Frankfurt")

station2 = bahn.station("Berlin")

journeys = bahn.journeys(departure=station2, 
                           destination=station1, 
                           products=[Products.EC_IC, Products.REGIONAL])

print(journeys[0].changes_amont)

🚆 Stopovers

from datetime import datetime


station1 = bahn.station("kassel")

station2 = bahn.station("Berlin")

stopo = bahn.station("frankfurt")
stopo.stopover_time = 5


time = datetime.strptime("2025-05-23T21:40:00", "%Y-%m-%dT%H:%M:%S")
time = time.strftime("%Y-%m-%dT%H:%M:%S")


journeys = bahn.journeys(departure=station1, destination=station2, stopovers=[stopo], time=time)


print(journeys)

📄 License

MIT License

⚠️ Disclaimer

This library (pybahn) is an unofficial wrapper around Deutsche Bahn’s internal web APIs, discovered via publicly accessible browser traffic.

  • It is not affiliated with or endorsed by Deutsche Bahn.
  • It uses undocumented and unsupported endpoints, which may break or change without notice.
  • Use this library at your own risk.
  • Please respect Deutsche Bahn’s terms of use and avoid abusive behavior.

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

pybahn-0.1.8.tar.gz (15.7 kB view details)

Uploaded Source

Built Distribution

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

pybahn-0.1.8-py3-none-any.whl (16.2 kB view details)

Uploaded Python 3

File details

Details for the file pybahn-0.1.8.tar.gz.

File metadata

  • Download URL: pybahn-0.1.8.tar.gz
  • Upload date:
  • Size: 15.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.4

File hashes

Hashes for pybahn-0.1.8.tar.gz
Algorithm Hash digest
SHA256 3fd94de9733c6b4fcfb06c5953b8a2f3970a542ad645c69eaa691b6dfe24ffcf
MD5 6ca1fb7fb24d7725fbfdcf31c2a80a91
BLAKE2b-256 7dcedd939770e98328a625d088578daf5588db04850b2f79073d2a931146b46d

See more details on using hashes here.

File details

Details for the file pybahn-0.1.8-py3-none-any.whl.

File metadata

  • Download URL: pybahn-0.1.8-py3-none-any.whl
  • Upload date:
  • Size: 16.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.4

File hashes

Hashes for pybahn-0.1.8-py3-none-any.whl
Algorithm Hash digest
SHA256 48d9e916657acb213c84dcb38be7caeb1db99b2b840a5767319f27f76b9f6d43
MD5 b9f62c41edc2d8aaf55e71b246ee8d4a
BLAKE2b-256 5a4880a3468c863b48d3af83e7230b2502cc9c22e8586975d57663a26dbc4a00

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