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("your_app")
🔍 Search Station
stations = bahn.stations("Berlin")
print(stations[0].name)
📍 Get a Single Station
station = bahn.station("Munich")
🗺️ Nearby Stations
stations = bahn.nearby(latitude=00.00000, longitude=00.0000)
🚉 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.lid, stat2.lid)
print(journeys[0].arrival_name)
or
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 Products
from datetime import datetime
station1 = bahn.station("Frankfurt")
station2 = bahn.station("Berlin")
time = datetime.now().strftime("%Y-%m-%dT%H:%M:%S")
journeys = bahn.journeys(departure = station1,
destination = station2,
time = time,
products = [Products.EC_IC, Products.SBAHN],
only_d_ticket = True)
print(journeys[0].changes_amont)
🎯 Filter Journeys
from pybahn.structs import Products
station1 = bahn.station("Frankfurt")
station2 = bahn.station("Berlin")
journeys = bahn.journeys(station1.lid, station2.lid, 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 datetime import datetime
station1 = bahn.station("kassel")
station2 = bahn.station("Berlin")
stopo = bahn.station("frankfurt")
stopo.stopover_time = 5
time = datetime.strptime("2025-05-23T21:40:00", "%Y-%m-%dT%H:%M:%S")
time = time.strftime("%Y-%m-%dT%H:%M:%S")
journeys = bahn.journeys(departure=station1, destination=station2, stopovers=[stopo], time=time)
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
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
File details
Details for the file pybahn-0.1.6.tar.gz.
File metadata
- Download URL: pybahn-0.1.6.tar.gz
- Upload date:
- Size: 15.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3056a636020f22548ccfa1e3b63ba5d85b78a60d567b7b922834427faed2a48f
|
|
| MD5 |
38c3ee7233ec5acaec67c966754d2ab9
|
|
| BLAKE2b-256 |
8fdacd082a0ce3b745c551ee2f67a24cb12aa50bfe82d03aee47804f1e6b62a5
|
File details
Details for the file pybahn-0.1.6-py3-none-any.whl.
File metadata
- Download URL: pybahn-0.1.6-py3-none-any.whl
- Upload date:
- Size: 16.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
03398cba61f7fe89ce45a79a7fc457026c924f39f8913fd226721a5fa6b04426
|
|
| MD5 |
0e0a0dca5196ea7a19bca5c4e8ec56f2
|
|
| BLAKE2b-256 |
22e5300de50832506c73cf44b7a42d79d20774874bcd7917bcfef34fe304958d
|