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()

🔍 Search Station

stations = bahn.stations("Berlin")

for station in stations:
	print(station.name)

📍 Get a Single Station

station = bahn.station("Munich")
print(station.name)

🗺️ Nearby Stations

near_stations = bahn.nearby(latitude=52.5170365, longitude=13.3888599, limit=5)

for station in stations:
	print(station.name)

🚉 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, station2)

print(journeys[0].arrival_name)

🎯 Filter Departures/Arrivals

from pybahn.structs import Filter, Date


berlin = bahn.station("Berlin hbf")
frankfurt = bahn.station("Frankfurt")

date = Date().set_time(hour=12, minute=00).set_date(month=10, day=2)

filters = Filter.from_list(["S", "U", "BUS"])

berlin_departures = bahn.departures(berlin, filters=filters, date=date)
print(berlin_departures[0].line_name)


berlin_arrivals = bahn.arrivals(berlin, filters=filters, date=date)
print(berlin_arrivals[0].line_name)

🎯 Filter Journeys

from pybahn.structs import Products


station1 = bahn.station("Frankfurt")
station2 = bahn.station("Berlin")

journeys = bahn.journeys(station1, station2, 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 pybahn.structs import Date

station1 = bahn.station("Kassel")
station2 = bahn.station("Berlin")

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

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


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.13.tar.gz (12.5 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.13-py3-none-any.whl (13.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pybahn-0.1.13.tar.gz
  • Upload date:
  • Size: 12.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for pybahn-0.1.13.tar.gz
Algorithm Hash digest
SHA256 236f00dbdcce834d3d95435197a90d8504cf6520e328d4d9b0ebce223ae3a761
MD5 887ddc8b642662231614355021a995e5
BLAKE2b-256 1771ac55734b9df74f676bdb182da83c13ca53e295ce02b63003b003516bc082

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pybahn-0.1.13-py3-none-any.whl
  • Upload date:
  • Size: 13.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for pybahn-0.1.13-py3-none-any.whl
Algorithm Hash digest
SHA256 e45aadb271cb47af3b265b711e5800bcefba21c28d74a1618a19bf7ef2082605
MD5 a52d56d4b492034c71737e4b360648ca
BLAKE2b-256 d0f52576ced6a3318e511537b4edab20f314ba25593931fe35ccd9f16c1c0cb7

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