🚆 weiche
This is an unofficial library wrapper around the API of the Deutsche Bahn (DB) website for identifying connections. It returns realtime, live data. If you do not need this in your project I strongly recommend not to use this API as it might break any moment if DB changes the API for getting station and train connections.
It has a API compatibility layer to the
schiene package for
easy drop-in replacement as
schiene no longer
works.
Requirements
- Python 3.10 and above
- requests package for the synchronous API and Schiene wrapper
- aiohttp for the asynchronous API
Features
- Get connections between two stations
- Search stations by name
- Get station information
Setup
$ python -m venv /path/to/venv $ /path/to/venv/bin/python -m pip install weiche[sync,async,schiene]
Usage
Use the synchronous API
from datetime import datetime
from weiche import SynchronousApi
api = SynchronousApi()
amsterdam_query = api.search_locations('Amsterdam', limit=1)
amsterdam = amsterdam_query[0]
munich_query = api.search_locations('München Hbf', limit=1)
munich = munich_query[0]
api.search_connections(
at=datetime(2025,5,10,18,0,0),
from_location=munich.id,
to_location=amsterdam.id,
limit=10,
)
You can also add an HTTP proxy to connect via as Bahn tends to block server ip addresses.
from weiche import SynchronousApi
api = SynchronousApi(proxy="192.168.0.1:8888")
Response from Synchronous API
The return format is an object which can also be found in the objects.py file.
Look for the Connection class
and see the API definition there.
Use the asynchronous API
import asyncio
from datetime import datetime
from weiche import AsynchronousApi
async def search():
api = AsynchronousApi()
amsterdam_query = await api.search_locations('Amsterdam', limit=1)
amsterdam = amsterdam_query[0]
munich_query = await api.search_locations('München Hbf', limit=1)
munich = munich_query[0]
return await api.search_connections(
at=datetime(2025,5,10,18,0,0),
from_location=munich.id,
to_location=amsterdam.id,
limit=10,
)
asyncio.get_event_loop().run_until_complete(search())
You can also add an HTTP proxy to connect via as Bahn tends to block server ip addresses.
from weiche import AsynchronousApi
api = AsynchronousApi(proxy="192.168.0.1:8888")
Response from Asynchronous API
The return format is an object which can also be found in the objects.py file.
Look for the Connection
class and see the API definition there.
Use the schiene compatibility layer
from weiche import Schiene
Schiene().connections('Mannheim HbF', 'Stuttgart HbF')
You can also add an HTTP proxy to connect via as Bahn tends to block server ip addresses.
from weiche import Schiene
api = Schiene(proxy="192.168.0.1:8888")
Response from Schiene Layer
[{'arrival': '15:47',
'canceled': False,
'departure': '14:30',
'details': '',
'price': 55.0,
'products': ['ICE'],
'time': '01:16',
'transfers': 0,
'ontime': True,
'delay': None},
{'arrival': '16:21',
'canceled': False,
'departure': '14:38',
'details': '',
'price': 50.99,
'products': ['SBAHN', 'ICE'],
'time': '01:42',
'transfers': 1,
'ontime': True,
'delay': None},
{'arrival': '16:25',
'canceled': False,
'departure': '14:46',
'details': '',
'price': 50.99,
'products': ['ICE', 'REGIONAL'],
'time': '01:23',
'transfers': 1,
'ontime': True,
'delay': None},
{'arrival': '16:45',
'canceled': False,
'departure': '15:31',
'details': '',
'price': 55.0,
'products': ['ICE'],
'time': '01:14',
'transfers': 0,
'ontime': True,
'delay': None},
{'arrival': '17:27',
'canceled': False,
'departure': '15:34',
'details': '',
'price': 55.0,
'products': ['ICE', 'REGIONAL'],
'time': '01:53',
'transfers': 1,
'ontime': True,
'delay': None},
{'arrival': '17:15',
'canceled': False,
'departure': '15:35',
'details': '',
'price': 21.8,
'products': ['REGIONAL', 'REGIONAL'],
'time': '01:40',
'transfers': 1,
'ontime': True,
'delay': None},
{'arrival': '17:44',
'canceled': False,
'departure': '15:35',
'details': '',
'price': 21.8,
'products': ['REGIONAL', 'REGIONAL'],
'time': '02:09',
'transfers': 1,
'ontime': True,
'delay': None},
{'arrival': '17:33',
'canceled': False,
'departure': '15:36',
'details': '',
'price': 24.99,
'products': ['SBAHN', 'ICE'],
'time': '02:06',
'transfers': 1,
'ontime': False,
'delay': {'delay_departure': 0, 'delay_arrival': 9}},
{'arrival': '18:20',
'canceled': False,
'departure': '16:38',
'details': '',
'price': 47.99,
'products': ['SBAHN', 'ICE'],
'time': '01:42',
'transfers': 1,
'ontime': True,
'delay': None},
{'arrival': '18:24',
'canceled': False,
'departure': '16:46',
'details': '',
'price': 50.99,
'products': ['ICE', 'REGIONAL'],
'time': '01:38',
'transfers': 1,
'ontime': True,
'delay': None}]
Metadata
Release files for weiche 0.10.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| weiche-0.10.1.tar.gz | 17.1 kB | Without provenance | Details for weiche-0.10.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| weiche-0.10.1-py3-none-any.whl | Python 3 | none | any | Details for weiche-0.10.1-py3-none-any.whl |
Total release size: 33.0 kB
Release files / weiche-0.10.1.tar.gz
| Download URL | weiche-0.10.1.tar.gz |
|---|---|
| Size | 17.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
401692d699435804c352a329bd09f3be67775bae1bbde1cb881054405d1f1c33
|
|
BLAKE2b-256 checksum How to use checksums |
5025794a57857dae613190f9b8ae9fd8849cb8a0234690014f624f227c32c4c5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.0
|
Release files / weiche-0.10.1-py3-none-any.whl
| Download URL | weiche-0.10.1-py3-none-any.whl |
|---|---|
| Size | 15.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f441d11ae461ba917448677ceac52adf87ca6b62094bb53a10824d58d10fd766
|
|
BLAKE2b-256 checksum How to use checksums |
73665e4296698bea401ec99aea0e881dd12a4e295a53704c547e952e3cee0867
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.0
|
Security for weiche 0.10.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.