weiche 0.9.1.dev1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- weiche-0.9.1.dev1/.coveragerc +3 -0
- weiche-0.9.1.dev1/.flake8 +7 -0
- weiche-0.9.1.dev1/.github/workflows/ci.yml +29 -0
- weiche-0.9.1.dev1/.gitignore +14 -0
- weiche-0.9.1.dev1/.pre-commit-config.yaml +75 -0
- weiche-0.9.1.dev1/LICENSE +21 -0
- weiche-0.9.1.dev1/MANIFEST.in +5 -0
- weiche-0.9.1.dev1/PKG-INFO +269 -0
- weiche-0.9.1.dev1/README.md +213 -0
- weiche-0.9.1.dev1/pyproject.toml +80 -0
- weiche-0.9.1.dev1/setup.cfg +4 -0
- weiche-0.9.1.dev1/src/py.typed +0 -0
- weiche-0.9.1.dev1/src/weiche/__init__.py +48 -0
- weiche-0.9.1.dev1/src/weiche/api/__init__.py +0 -0
- weiche-0.9.1.dev1/src/weiche/api/asynchronous.py +68 -0
- weiche-0.9.1.dev1/src/weiche/api/base.py +47 -0
- weiche-0.9.1.dev1/src/weiche/api/parser.py +17 -0
- weiche-0.9.1.dev1/src/weiche/api/synchronous.py +68 -0
- weiche-0.9.1.dev1/src/weiche/const.py +1 -0
- weiche-0.9.1.dev1/src/weiche/formatter.py +9 -0
- weiche-0.9.1.dev1/src/weiche/objects.py +387 -0
- weiche-0.9.1.dev1/src/weiche/schiene.py +135 -0
- weiche-0.9.1.dev1/src/weiche/tests/__init__.py +1 -0
- weiche-0.9.1.dev1/src/weiche/tests/test_asynchronous.py +25 -0
- weiche-0.9.1.dev1/src/weiche/tests/test_schiene.py +19 -0
- weiche-0.9.1.dev1/src/weiche/tests/test_synchronous.py +43 -0
- weiche-0.9.1.dev1/src/weiche/version.py +21 -0
- weiche-0.9.1.dev1/src/weiche.egg-info/PKG-INFO +269 -0
- weiche-0.9.1.dev1/src/weiche.egg-info/SOURCES.txt +32 -0
- weiche-0.9.1.dev1/src/weiche.egg-info/dependency_links.txt +1 -0
- weiche-0.9.1.dev1/src/weiche.egg-info/requires.txt +17 -0
- weiche-0.9.1.dev1/src/weiche.egg-info/top_level.txt +1 -0
- weiche-0.9.1.dev1/tox.ini +53 -0
- weiche-0.9.1.dev1/utils/pre-commit +11 -0
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
run-name: Run unit tests, code checker, build docs.
|
|
3
|
+
on: [push]
|
|
4
|
+
jobs:
|
|
5
|
+
build:
|
|
6
|
+
runs-on: ubuntu-latest
|
|
7
|
+
strategy:
|
|
8
|
+
matrix:
|
|
9
|
+
python-version: ['3.11']
|
|
10
|
+
steps:
|
|
11
|
+
- uses: actions/checkout@v3
|
|
12
|
+
- uses: actions/setup-python@v4.5.0
|
|
13
|
+
with:
|
|
14
|
+
python-version: ${{ matrix.python-version }}
|
|
15
|
+
- name: Install dependencies
|
|
16
|
+
run: |
|
|
17
|
+
python -m pip install --upgrade pip
|
|
18
|
+
python -m pip install --use-pep517 pytest-cov pytest-random pytest-remove-stale-bytecode flake8 pycodestyle pydocstyle Sphinx sphinx_rtd_theme
|
|
19
|
+
python -m pip install .
|
|
20
|
+
- name: Run unittest
|
|
21
|
+
run: pytest -v --random --cov=src/weiche --cov-report=term
|
|
22
|
+
- name: flake8
|
|
23
|
+
run: flake8 src
|
|
24
|
+
- name: pycodestyle
|
|
25
|
+
run: pycodestyle -v --first src
|
|
26
|
+
- name: pydocstyle
|
|
27
|
+
run: pydocstyle -v --match='(?!test_|version)(.*)?\.py' src
|
|
28
|
+
- name: build docs
|
|
29
|
+
run: sphinx-build -M html docs/source doc/build
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# Auto-generated from https://github.com/xcnt/xcnt-gardener/blob/main/templates/common/.pre-commit-config.yaml
|
|
2
|
+
|
|
3
|
+
repos:
|
|
4
|
+
- repo: https://github.com/asottile/pyupgrade
|
|
5
|
+
rev: v3.19.1
|
|
6
|
+
hooks:
|
|
7
|
+
- id: pyupgrade
|
|
8
|
+
args:
|
|
9
|
+
- --py36-plus
|
|
10
|
+
- --py37-plus
|
|
11
|
+
- --py38-plus
|
|
12
|
+
- --py39-plus
|
|
13
|
+
- --py310-plus
|
|
14
|
+
- repo: https://github.com/ambv/black
|
|
15
|
+
rev: "25.1.0"
|
|
16
|
+
hooks:
|
|
17
|
+
- id: black
|
|
18
|
+
- repo: https://github.com/hakancelik96/unimport
|
|
19
|
+
rev: "1.2.1"
|
|
20
|
+
hooks:
|
|
21
|
+
- id: unimport
|
|
22
|
+
args: ["-r", "--exclude", "(__init__.py)|venv|env"]
|
|
23
|
+
- repo: https://github.com/pycqa/flake8
|
|
24
|
+
rev: "7.2.0"
|
|
25
|
+
hooks:
|
|
26
|
+
- id: flake8
|
|
27
|
+
- repo: https://github.com/pre-commit/pre-commit-hooks
|
|
28
|
+
rev: v5.0.0
|
|
29
|
+
hooks:
|
|
30
|
+
- id: check-toml
|
|
31
|
+
- id: end-of-file-fixer
|
|
32
|
+
- id: debug-statements
|
|
33
|
+
- id: check-merge-conflict
|
|
34
|
+
- repo: https://github.com/pre-commit/mirrors-mypy
|
|
35
|
+
rev: "v1.15.0"
|
|
36
|
+
hooks:
|
|
37
|
+
- id: mypy
|
|
38
|
+
additional_dependencies:
|
|
39
|
+
- types-requests
|
|
40
|
+
- repo: https://github.com/MarcoGorelli/absolufy-imports
|
|
41
|
+
rev: v0.3.1
|
|
42
|
+
hooks:
|
|
43
|
+
- id: absolufy-imports
|
|
44
|
+
- repo: https://github.com/PyCQA/isort
|
|
45
|
+
rev: "6.0.1"
|
|
46
|
+
hooks:
|
|
47
|
+
- id: isort
|
|
48
|
+
additional_dependencies: [toml]
|
|
49
|
+
- repo: https://github.com/pre-commit/pygrep-hooks
|
|
50
|
+
rev: v1.10.0
|
|
51
|
+
hooks:
|
|
52
|
+
- id: python-check-blanket-noqa
|
|
53
|
+
- id: python-no-eval
|
|
54
|
+
- repo: https://github.com/jumanjihouse/pre-commit-hooks
|
|
55
|
+
rev: "3.0.0"
|
|
56
|
+
hooks:
|
|
57
|
+
- id: script-must-have-extension
|
|
58
|
+
- repo: local
|
|
59
|
+
hooks:
|
|
60
|
+
- id: markdownlint_docker # Configure in .mdlrc
|
|
61
|
+
name: Markdownlint Docker
|
|
62
|
+
language: docker_image
|
|
63
|
+
files: \.(md|mdown|markdown)$
|
|
64
|
+
exclude: CHANGELOG.md
|
|
65
|
+
entry: markdownlint/markdownlint
|
|
66
|
+
- repo: https://github.com/pycqa/pydocstyle
|
|
67
|
+
rev: 6.3.0
|
|
68
|
+
hooks:
|
|
69
|
+
- id: pydocstyle
|
|
70
|
+
additional_dependencies: [toml]
|
|
71
|
+
args:
|
|
72
|
+
# Google convention, and all public requiremenst disabled (for now).
|
|
73
|
+
# http://www.pydocstyle.org/en/6.1.1/error_codes.html
|
|
74
|
+
# See Google Python Style Guide https://google.github.io/styleguide/pyguide.html for more infos.
|
|
75
|
+
- --ignore=D100,D101,D102,D103,D104,D105,D106,D107, D203, D204, D213, D215, D400, D401, D404, D406, D407, D408, D409, D413
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Christoph Brand
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: weiche
|
|
3
|
+
Version: 0.9.1.dev1
|
|
4
|
+
Summary: A wrapper around the DB Website API for querying train connections.
|
|
5
|
+
Author-email: Christoph Brand <christoph+pypi@brand.rest>
|
|
6
|
+
License: MIT License
|
|
7
|
+
|
|
8
|
+
Copyright (c) 2025 Christoph Brand
|
|
9
|
+
|
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
+
in the Software without restriction, including without limitation the rights
|
|
13
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
+
furnished to do so, subject to the following conditions:
|
|
16
|
+
|
|
17
|
+
The above copyright notice and this permission notice shall be included in all
|
|
18
|
+
copies or substantial portions of the Software.
|
|
19
|
+
|
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
26
|
+
SOFTWARE.
|
|
27
|
+
|
|
28
|
+
Project-URL: Homepage, https://github.com/cbrand/weiche
|
|
29
|
+
Classifier: Development Status :: 3 - Alpha
|
|
30
|
+
Classifier: Intended Audience :: Developers
|
|
31
|
+
Classifier: License :: OSI Approved :: MIT No Attribution License (MIT-0)
|
|
32
|
+
Classifier: Programming Language :: Python
|
|
33
|
+
Classifier: Programming Language :: Python :: 3
|
|
34
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
35
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
36
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
37
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
38
|
+
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
39
|
+
Requires-Python: >=3.10
|
|
40
|
+
Description-Content-Type: text/markdown
|
|
41
|
+
License-File: LICENSE
|
|
42
|
+
Requires-Dist: pydantic<3,>=2
|
|
43
|
+
Provides-Extra: test
|
|
44
|
+
Requires-Dist: pytest; extra == "test"
|
|
45
|
+
Requires-Dist: pytest-asyncio; extra == "test"
|
|
46
|
+
Requires-Dist: tox; extra == "test"
|
|
47
|
+
Requires-Dist: requests; extra == "test"
|
|
48
|
+
Requires-Dist: aiohttp; extra == "test"
|
|
49
|
+
Provides-Extra: sync
|
|
50
|
+
Requires-Dist: requests; extra == "sync"
|
|
51
|
+
Provides-Extra: async
|
|
52
|
+
Requires-Dist: aiohttp; extra == "async"
|
|
53
|
+
Provides-Extra: schiene
|
|
54
|
+
Requires-Dist: requests; extra == "schiene"
|
|
55
|
+
Dynamic: license-file
|
|
56
|
+
|
|
57
|
+
# 🚆 weiche
|
|
58
|
+
|
|
59
|
+
This is an unofficial library wrapper around the API of the
|
|
60
|
+
Deutsche Bahn (DB) website for identifying connections.
|
|
61
|
+
It returns **realtime**, **live** data.
|
|
62
|
+
If you do not need this in your project I strongly recommend
|
|
63
|
+
not to use this API as it might break any moment if DB changes
|
|
64
|
+
the API for getting station and train connections.
|
|
65
|
+
|
|
66
|
+
It has a API compatibility layer to the
|
|
67
|
+
[`schiene`](https://pypi.org/project/schiene/) package for
|
|
68
|
+
easy drop-in replacement as
|
|
69
|
+
[`schiene`](https://pypi.org/project/schiene/) no longer
|
|
70
|
+
works.
|
|
71
|
+
|
|
72
|
+
## Requirements
|
|
73
|
+
|
|
74
|
+
- Python 3.10 and above
|
|
75
|
+
- requests package for the synchronous API and Schiene wrapper
|
|
76
|
+
- aiohttp for the asynchronous API
|
|
77
|
+
|
|
78
|
+
## Features
|
|
79
|
+
|
|
80
|
+
- Get connections between two stations
|
|
81
|
+
- Search stations by name
|
|
82
|
+
- Get station information
|
|
83
|
+
|
|
84
|
+
## Setup
|
|
85
|
+
|
|
86
|
+
$ python -m venv /path/to/venv
|
|
87
|
+
$ /path/to/venv/bin/python -m pip install weiche[sync,async,schiene]
|
|
88
|
+
|
|
89
|
+
## Usage
|
|
90
|
+
|
|
91
|
+
### Use the synchronous API
|
|
92
|
+
|
|
93
|
+
```python
|
|
94
|
+
from datetime import datetime
|
|
95
|
+
from weiche import SynchronousApi
|
|
96
|
+
|
|
97
|
+
api = SynchronousApi()
|
|
98
|
+
|
|
99
|
+
amsterdam_query = api.search_locations('Amsterdam', limit=1)
|
|
100
|
+
amsterdam = amsterdam_query[0]
|
|
101
|
+
munich_query = api.search_locations('München Hbf', limit=1)
|
|
102
|
+
munich = munich_query[0]
|
|
103
|
+
|
|
104
|
+
api.search_connections(
|
|
105
|
+
at=datetime(2025,5,10,18,0,0),
|
|
106
|
+
from_location=munich.id,
|
|
107
|
+
to_location=amsterdam.id,
|
|
108
|
+
limit=10,
|
|
109
|
+
)
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
<details>
|
|
113
|
+
<summary>Response from Synchronous API</summary>
|
|
114
|
+
|
|
115
|
+
The return format is an object which can also be found in the [objects.py](./src/weiche/objects.py) file.
|
|
116
|
+
|
|
117
|
+
Look for the [`Connection`](./src/weiche/objects.py#L175) class and see the API definition there.
|
|
118
|
+
|
|
119
|
+
</details>
|
|
120
|
+
|
|
121
|
+
### Use the asynchronous API
|
|
122
|
+
|
|
123
|
+
```python
|
|
124
|
+
import asyncio
|
|
125
|
+
from datetime import datetime
|
|
126
|
+
from weiche import AsynchronousApi
|
|
127
|
+
|
|
128
|
+
async def search():
|
|
129
|
+
api = AsynchronousApi()
|
|
130
|
+
|
|
131
|
+
amsterdam_query = await api.search_locations('Amsterdam', limit=1)
|
|
132
|
+
amsterdam = amsterdam_query[0]
|
|
133
|
+
munich_query = await api.search_locations('München Hbf', limit=1)
|
|
134
|
+
munich = munich_query[0]
|
|
135
|
+
|
|
136
|
+
return await api.search_connections(
|
|
137
|
+
at=datetime(2025,5,10,18,0,0),
|
|
138
|
+
from_location=munich.id,
|
|
139
|
+
to_location=amsterdam.id,
|
|
140
|
+
limit=10,
|
|
141
|
+
)
|
|
142
|
+
|
|
143
|
+
asyncio.get_event_loop().run_until_complete(search())
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
<details>
|
|
147
|
+
<summary>Response from Asynchronous API</summary>
|
|
148
|
+
|
|
149
|
+
The return format is an object which can also be found in the [objects.py](./src/weiche/objects.py) file.
|
|
150
|
+
|
|
151
|
+
Look for the [`Connection`](./src/weiche/objects.py#L175) class and see the API definition there.
|
|
152
|
+
|
|
153
|
+
</details>
|
|
154
|
+
|
|
155
|
+
### Use the `schiene` compatibility layer
|
|
156
|
+
|
|
157
|
+
```python
|
|
158
|
+
from weiche import Schiene
|
|
159
|
+
|
|
160
|
+
Schiene().connections('Mannheim HbF', 'Stuttgart HbF')
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
<details>
|
|
164
|
+
<summary>Response from Schiene Layer</summary>
|
|
165
|
+
|
|
166
|
+
```python
|
|
167
|
+
[{'arrival': '15:47',
|
|
168
|
+
'canceled': False,
|
|
169
|
+
'departure': '14:30',
|
|
170
|
+
'details': '',
|
|
171
|
+
'price': 55.0,
|
|
172
|
+
'products': ['ICE'],
|
|
173
|
+
'time': '01:16',
|
|
174
|
+
'transfers': 0,
|
|
175
|
+
'ontime': True,
|
|
176
|
+
'delay': None},
|
|
177
|
+
{'arrival': '16:21',
|
|
178
|
+
'canceled': False,
|
|
179
|
+
'departure': '14:38',
|
|
180
|
+
'details': '',
|
|
181
|
+
'price': 50.99,
|
|
182
|
+
'products': ['SBAHN', 'ICE'],
|
|
183
|
+
'time': '01:42',
|
|
184
|
+
'transfers': 1,
|
|
185
|
+
'ontime': True,
|
|
186
|
+
'delay': None},
|
|
187
|
+
{'arrival': '16:25',
|
|
188
|
+
'canceled': False,
|
|
189
|
+
'departure': '14:46',
|
|
190
|
+
'details': '',
|
|
191
|
+
'price': 50.99,
|
|
192
|
+
'products': ['ICE', 'REGIONAL'],
|
|
193
|
+
'time': '01:23',
|
|
194
|
+
'transfers': 1,
|
|
195
|
+
'ontime': True,
|
|
196
|
+
'delay': None},
|
|
197
|
+
{'arrival': '16:45',
|
|
198
|
+
'canceled': False,
|
|
199
|
+
'departure': '15:31',
|
|
200
|
+
'details': '',
|
|
201
|
+
'price': 55.0,
|
|
202
|
+
'products': ['ICE'],
|
|
203
|
+
'time': '01:14',
|
|
204
|
+
'transfers': 0,
|
|
205
|
+
'ontime': True,
|
|
206
|
+
'delay': None},
|
|
207
|
+
{'arrival': '17:27',
|
|
208
|
+
'canceled': False,
|
|
209
|
+
'departure': '15:34',
|
|
210
|
+
'details': '',
|
|
211
|
+
'price': 55.0,
|
|
212
|
+
'products': ['ICE', 'REGIONAL'],
|
|
213
|
+
'time': '01:53',
|
|
214
|
+
'transfers': 1,
|
|
215
|
+
'ontime': True,
|
|
216
|
+
'delay': None},
|
|
217
|
+
{'arrival': '17:15',
|
|
218
|
+
'canceled': False,
|
|
219
|
+
'departure': '15:35',
|
|
220
|
+
'details': '',
|
|
221
|
+
'price': 21.8,
|
|
222
|
+
'products': ['REGIONAL', 'REGIONAL'],
|
|
223
|
+
'time': '01:40',
|
|
224
|
+
'transfers': 1,
|
|
225
|
+
'ontime': True,
|
|
226
|
+
'delay': None},
|
|
227
|
+
{'arrival': '17:44',
|
|
228
|
+
'canceled': False,
|
|
229
|
+
'departure': '15:35',
|
|
230
|
+
'details': '',
|
|
231
|
+
'price': 21.8,
|
|
232
|
+
'products': ['REGIONAL', 'REGIONAL'],
|
|
233
|
+
'time': '02:09',
|
|
234
|
+
'transfers': 1,
|
|
235
|
+
'ontime': True,
|
|
236
|
+
'delay': None},
|
|
237
|
+
{'arrival': '17:33',
|
|
238
|
+
'canceled': False,
|
|
239
|
+
'departure': '15:36',
|
|
240
|
+
'details': '',
|
|
241
|
+
'price': 24.99,
|
|
242
|
+
'products': ['SBAHN', 'ICE'],
|
|
243
|
+
'time': '02:06',
|
|
244
|
+
'transfers': 1,
|
|
245
|
+
'ontime': False,
|
|
246
|
+
'delay': {'delay_departure': 0, 'delay_arrival': 9}},
|
|
247
|
+
{'arrival': '18:20',
|
|
248
|
+
'canceled': False,
|
|
249
|
+
'departure': '16:38',
|
|
250
|
+
'details': '',
|
|
251
|
+
'price': 47.99,
|
|
252
|
+
'products': ['SBAHN', 'ICE'],
|
|
253
|
+
'time': '01:42',
|
|
254
|
+
'transfers': 1,
|
|
255
|
+
'ontime': True,
|
|
256
|
+
'delay': None},
|
|
257
|
+
{'arrival': '18:24',
|
|
258
|
+
'canceled': False,
|
|
259
|
+
'departure': '16:46',
|
|
260
|
+
'details': '',
|
|
261
|
+
'price': 50.99,
|
|
262
|
+
'products': ['ICE', 'REGIONAL'],
|
|
263
|
+
'time': '01:38',
|
|
264
|
+
'transfers': 1,
|
|
265
|
+
'ontime': True,
|
|
266
|
+
'delay': None}]
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
</details>
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
# 🚆 weiche
|
|
2
|
+
|
|
3
|
+
This is an unofficial library wrapper around the API of the
|
|
4
|
+
Deutsche Bahn (DB) website for identifying connections.
|
|
5
|
+
It returns **realtime**, **live** data.
|
|
6
|
+
If you do not need this in your project I strongly recommend
|
|
7
|
+
not to use this API as it might break any moment if DB changes
|
|
8
|
+
the API for getting station and train connections.
|
|
9
|
+
|
|
10
|
+
It has a API compatibility layer to the
|
|
11
|
+
[`schiene`](https://pypi.org/project/schiene/) package for
|
|
12
|
+
easy drop-in replacement as
|
|
13
|
+
[`schiene`](https://pypi.org/project/schiene/) no longer
|
|
14
|
+
works.
|
|
15
|
+
|
|
16
|
+
## Requirements
|
|
17
|
+
|
|
18
|
+
- Python 3.10 and above
|
|
19
|
+
- requests package for the synchronous API and Schiene wrapper
|
|
20
|
+
- aiohttp for the asynchronous API
|
|
21
|
+
|
|
22
|
+
## Features
|
|
23
|
+
|
|
24
|
+
- Get connections between two stations
|
|
25
|
+
- Search stations by name
|
|
26
|
+
- Get station information
|
|
27
|
+
|
|
28
|
+
## Setup
|
|
29
|
+
|
|
30
|
+
$ python -m venv /path/to/venv
|
|
31
|
+
$ /path/to/venv/bin/python -m pip install weiche[sync,async,schiene]
|
|
32
|
+
|
|
33
|
+
## Usage
|
|
34
|
+
|
|
35
|
+
### Use the synchronous API
|
|
36
|
+
|
|
37
|
+
```python
|
|
38
|
+
from datetime import datetime
|
|
39
|
+
from weiche import SynchronousApi
|
|
40
|
+
|
|
41
|
+
api = SynchronousApi()
|
|
42
|
+
|
|
43
|
+
amsterdam_query = api.search_locations('Amsterdam', limit=1)
|
|
44
|
+
amsterdam = amsterdam_query[0]
|
|
45
|
+
munich_query = api.search_locations('München Hbf', limit=1)
|
|
46
|
+
munich = munich_query[0]
|
|
47
|
+
|
|
48
|
+
api.search_connections(
|
|
49
|
+
at=datetime(2025,5,10,18,0,0),
|
|
50
|
+
from_location=munich.id,
|
|
51
|
+
to_location=amsterdam.id,
|
|
52
|
+
limit=10,
|
|
53
|
+
)
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
<details>
|
|
57
|
+
<summary>Response from Synchronous API</summary>
|
|
58
|
+
|
|
59
|
+
The return format is an object which can also be found in the [objects.py](./src/weiche/objects.py) file.
|
|
60
|
+
|
|
61
|
+
Look for the [`Connection`](./src/weiche/objects.py#L175) class and see the API definition there.
|
|
62
|
+
|
|
63
|
+
</details>
|
|
64
|
+
|
|
65
|
+
### Use the asynchronous API
|
|
66
|
+
|
|
67
|
+
```python
|
|
68
|
+
import asyncio
|
|
69
|
+
from datetime import datetime
|
|
70
|
+
from weiche import AsynchronousApi
|
|
71
|
+
|
|
72
|
+
async def search():
|
|
73
|
+
api = AsynchronousApi()
|
|
74
|
+
|
|
75
|
+
amsterdam_query = await api.search_locations('Amsterdam', limit=1)
|
|
76
|
+
amsterdam = amsterdam_query[0]
|
|
77
|
+
munich_query = await api.search_locations('München Hbf', limit=1)
|
|
78
|
+
munich = munich_query[0]
|
|
79
|
+
|
|
80
|
+
return await api.search_connections(
|
|
81
|
+
at=datetime(2025,5,10,18,0,0),
|
|
82
|
+
from_location=munich.id,
|
|
83
|
+
to_location=amsterdam.id,
|
|
84
|
+
limit=10,
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
asyncio.get_event_loop().run_until_complete(search())
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
<details>
|
|
91
|
+
<summary>Response from Asynchronous API</summary>
|
|
92
|
+
|
|
93
|
+
The return format is an object which can also be found in the [objects.py](./src/weiche/objects.py) file.
|
|
94
|
+
|
|
95
|
+
Look for the [`Connection`](./src/weiche/objects.py#L175) class and see the API definition there.
|
|
96
|
+
|
|
97
|
+
</details>
|
|
98
|
+
|
|
99
|
+
### Use the `schiene` compatibility layer
|
|
100
|
+
|
|
101
|
+
```python
|
|
102
|
+
from weiche import Schiene
|
|
103
|
+
|
|
104
|
+
Schiene().connections('Mannheim HbF', 'Stuttgart HbF')
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
<details>
|
|
108
|
+
<summary>Response from Schiene Layer</summary>
|
|
109
|
+
|
|
110
|
+
```python
|
|
111
|
+
[{'arrival': '15:47',
|
|
112
|
+
'canceled': False,
|
|
113
|
+
'departure': '14:30',
|
|
114
|
+
'details': '',
|
|
115
|
+
'price': 55.0,
|
|
116
|
+
'products': ['ICE'],
|
|
117
|
+
'time': '01:16',
|
|
118
|
+
'transfers': 0,
|
|
119
|
+
'ontime': True,
|
|
120
|
+
'delay': None},
|
|
121
|
+
{'arrival': '16:21',
|
|
122
|
+
'canceled': False,
|
|
123
|
+
'departure': '14:38',
|
|
124
|
+
'details': '',
|
|
125
|
+
'price': 50.99,
|
|
126
|
+
'products': ['SBAHN', 'ICE'],
|
|
127
|
+
'time': '01:42',
|
|
128
|
+
'transfers': 1,
|
|
129
|
+
'ontime': True,
|
|
130
|
+
'delay': None},
|
|
131
|
+
{'arrival': '16:25',
|
|
132
|
+
'canceled': False,
|
|
133
|
+
'departure': '14:46',
|
|
134
|
+
'details': '',
|
|
135
|
+
'price': 50.99,
|
|
136
|
+
'products': ['ICE', 'REGIONAL'],
|
|
137
|
+
'time': '01:23',
|
|
138
|
+
'transfers': 1,
|
|
139
|
+
'ontime': True,
|
|
140
|
+
'delay': None},
|
|
141
|
+
{'arrival': '16:45',
|
|
142
|
+
'canceled': False,
|
|
143
|
+
'departure': '15:31',
|
|
144
|
+
'details': '',
|
|
145
|
+
'price': 55.0,
|
|
146
|
+
'products': ['ICE'],
|
|
147
|
+
'time': '01:14',
|
|
148
|
+
'transfers': 0,
|
|
149
|
+
'ontime': True,
|
|
150
|
+
'delay': None},
|
|
151
|
+
{'arrival': '17:27',
|
|
152
|
+
'canceled': False,
|
|
153
|
+
'departure': '15:34',
|
|
154
|
+
'details': '',
|
|
155
|
+
'price': 55.0,
|
|
156
|
+
'products': ['ICE', 'REGIONAL'],
|
|
157
|
+
'time': '01:53',
|
|
158
|
+
'transfers': 1,
|
|
159
|
+
'ontime': True,
|
|
160
|
+
'delay': None},
|
|
161
|
+
{'arrival': '17:15',
|
|
162
|
+
'canceled': False,
|
|
163
|
+
'departure': '15:35',
|
|
164
|
+
'details': '',
|
|
165
|
+
'price': 21.8,
|
|
166
|
+
'products': ['REGIONAL', 'REGIONAL'],
|
|
167
|
+
'time': '01:40',
|
|
168
|
+
'transfers': 1,
|
|
169
|
+
'ontime': True,
|
|
170
|
+
'delay': None},
|
|
171
|
+
{'arrival': '17:44',
|
|
172
|
+
'canceled': False,
|
|
173
|
+
'departure': '15:35',
|
|
174
|
+
'details': '',
|
|
175
|
+
'price': 21.8,
|
|
176
|
+
'products': ['REGIONAL', 'REGIONAL'],
|
|
177
|
+
'time': '02:09',
|
|
178
|
+
'transfers': 1,
|
|
179
|
+
'ontime': True,
|
|
180
|
+
'delay': None},
|
|
181
|
+
{'arrival': '17:33',
|
|
182
|
+
'canceled': False,
|
|
183
|
+
'departure': '15:36',
|
|
184
|
+
'details': '',
|
|
185
|
+
'price': 24.99,
|
|
186
|
+
'products': ['SBAHN', 'ICE'],
|
|
187
|
+
'time': '02:06',
|
|
188
|
+
'transfers': 1,
|
|
189
|
+
'ontime': False,
|
|
190
|
+
'delay': {'delay_departure': 0, 'delay_arrival': 9}},
|
|
191
|
+
{'arrival': '18:20',
|
|
192
|
+
'canceled': False,
|
|
193
|
+
'departure': '16:38',
|
|
194
|
+
'details': '',
|
|
195
|
+
'price': 47.99,
|
|
196
|
+
'products': ['SBAHN', 'ICE'],
|
|
197
|
+
'time': '01:42',
|
|
198
|
+
'transfers': 1,
|
|
199
|
+
'ontime': True,
|
|
200
|
+
'delay': None},
|
|
201
|
+
{'arrival': '18:24',
|
|
202
|
+
'canceled': False,
|
|
203
|
+
'departure': '16:46',
|
|
204
|
+
'details': '',
|
|
205
|
+
'price': 50.99,
|
|
206
|
+
'products': ['ICE', 'REGIONAL'],
|
|
207
|
+
'time': '01:38',
|
|
208
|
+
'transfers': 1,
|
|
209
|
+
'ontime': True,
|
|
210
|
+
'delay': None}]
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
</details>
|