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

Uploaded Python 3

File details

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

File metadata

  • Download URL: pybahn-0.1.15.tar.gz
  • Upload date:
  • Size: 13.9 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.15.tar.gz
Algorithm Hash digest
SHA256 528e99d94365dec7966e9ab6bac16b370fe201c440c0fb36e5d13ac47cb29204
MD5 b3d6d8c8f15744c2ac90344cb50d50e0
BLAKE2b-256 6a7dc24a342b4eae290e4777777ff04f215fe70cd7a6421e440dcee4cdd2861c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pybahn-0.1.15-py3-none-any.whl
  • Upload date:
  • Size: 15.3 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.15-py3-none-any.whl
Algorithm Hash digest
SHA256 3e641b4a27aade8c834be6592292cac2986eb7a974f75eec9bc68a893771ac5e
MD5 fc406897ff0eca8d6d83ba9a20db2974
BLAKE2b-256 fa5c51c5540bf0c09b3c5c706c3aa19dc4df73955da1260a0bcb30853bd45a15

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