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.7.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.7-py3-none-any.whl (16.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pybahn-0.1.7.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.7.tar.gz
Algorithm Hash digest
SHA256 239a171c2c7cb2e1f934310009d1907ca3443baa03237f7a52d421858445641b
MD5 091a94ae329679334dbe47a70119c349
BLAKE2b-256 7aea19240ca90fba686c23345bb9a6dfed5a5afe8893a0ce126fb7e5fce5d7db

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pybahn-0.1.7-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.7-py3-none-any.whl
Algorithm Hash digest
SHA256 c74e8ef24360a9568cbd014088f64def8f488d676186ff92ee12ae0dadb463bf
MD5 911e5fdde4d515d9f655b12277171804
BLAKE2b-256 ddb7ab8c5ed0d5542823320a2aab7e6c1dc1c78470d723f37d3100994050db8c

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