Pybahn
A Python library to query Deutsche Bahn journey, departure, and arrival data using the (unofficial) API.
📚 Table of Contents
- 📦 Installation
- 🛠️ Usage
- 🔧 Initialize PyBahn
- 🔍 Search Stations
- 📍 Get a Single Station
- 🗺️ Nearby Stations
- 🚉 Departures
- 🚉 Arrivals
- 🚆 Journeys
- 🎯 Filter Departures/Arrivals
- 🎯 Filter Journeys
- 🚆 Stopovers
- ⚠️ License
- ⚠️ Disclaimer
📦 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
⚠️ 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.
Release files for PyBahn 0.1.17
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pybahn-0.1.17.tar.gz | 3.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pybahn-0.1.17-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 6.7 kB
Release files / pybahn-0.1.17.tar.gz
| Download URL | pybahn-0.1.17.tar.gz |
|---|---|
| Size | 3.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1f6a88016976332d010217e1d5ee6540daf2ab0cde088e86df325a2eb18ec7c2
|
|
BLAKE2b-256 checksum How to use checksums |
d87eadb6fe63e4fd550e3593e4035e70707e27fd646100bc9a06feee9518b1db
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.4
|
Release files / pybahn-0.1.17-py3-none-any.whl
| Download URL | pybahn-0.1.17-py3-none-any.whl |
|---|---|
| Size | 3.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5925b494160b3c624b4ee4d36b43dc201346b99df240410f91a4c27bdabeec13
|
|
BLAKE2b-256 checksum How to use checksums |
fa88808f13d4e7134f4701dbcb2eb4ac4d98923d195e6dd7836dccfe0c0f7e23
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.4
|