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.14.tar.gz (12.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.14-py3-none-any.whl (13.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pybahn-0.1.14.tar.gz
  • Upload date:
  • Size: 12.7 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.14.tar.gz
Algorithm Hash digest
SHA256 b1a4b788be98a49c2f12abd6a9d7661b0e3816922356749a0ce60813e0fcd2c3
MD5 6b2a22c58e58c2ac3d73d74f2a501538
BLAKE2b-256 06dd5d001ac7dcdddfbe92dd11c4f622b37eed4026ebc6ce77bc63742071bd7a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pybahn-0.1.14-py3-none-any.whl
  • Upload date:
  • Size: 13.9 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.14-py3-none-any.whl
Algorithm Hash digest
SHA256 2e79215d009f8270a8dc5fb9ec2c6b48e114ca4321955356c1a412c21aed9356
MD5 c9a8483f97914431e0be7ab6e5a5ad32
BLAKE2b-256 1651401a2038caa802a8705b4a2ba8fc92696382f41ab79620fa96ac11717dc1

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