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
- 🛠️ 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.
Project details
Release history Release notifications | RSS feed
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.16.tar.gz
(14.2 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
pybahn-0.1.16-py3-none-any.whl
(15.5 kB
view details)
File details
Details for the file pybahn-0.1.16.tar.gz.
File metadata
- Download URL: pybahn-0.1.16.tar.gz
- Upload date:
- Size: 14.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4f5b3d7647332aacf252570de22e39303d3d10f227b1c33d8dc20f81847981c5
|
|
| MD5 |
6e27a1b321954ee0570bff5b62bea2b9
|
|
| BLAKE2b-256 |
ecd469d55614c85243b696e00224907f8522ddd0cc731c9950b739e9440086da
|
File details
Details for the file pybahn-0.1.16-py3-none-any.whl.
File metadata
- Download URL: pybahn-0.1.16-py3-none-any.whl
- Upload date:
- Size: 15.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3f302d20950b47ef9cf64fa6c72377afde0da86cda2155e08a561fb77473d3ca
|
|
| MD5 |
790bcd51be88a291626570068aab7737
|
|
| BLAKE2b-256 |
aa72dd34e5edf1867c36e4945ce40de1191cdfd1c71aa797b7e1b910ce772ea1
|