rzd-api 2.0.0__tar.gz → 3.0.0__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.
Files changed (30) hide show
  1. {rzd_api-2.0.0 → rzd_api-3.0.0}/PKG-INFO +36 -5
  2. {rzd_api-2.0.0 → rzd_api-3.0.0}/README.md +35 -4
  3. {rzd_api-2.0.0 → rzd_api-3.0.0}/mcp_server/server.py +91 -6
  4. {rzd_api-2.0.0 → rzd_api-3.0.0}/pyproject.toml +1 -1
  5. {rzd_api-2.0.0 → rzd_api-3.0.0}/rzd_api/__init__.py +14 -0
  6. rzd_api-3.0.0/rzd_api/api.py +711 -0
  7. {rzd_api-2.0.0 → rzd_api-3.0.0}/rzd_api/client.py +160 -62
  8. {rzd_api-2.0.0 → rzd_api-3.0.0}/rzd_api/config.py +6 -0
  9. rzd_api-3.0.0/rzd_api/models.py +193 -0
  10. {rzd_api-2.0.0 → rzd_api-3.0.0}/rzd_api.egg-info/PKG-INFO +36 -5
  11. rzd_api-3.0.0/tests/test_api.py +388 -0
  12. {rzd_api-2.0.0 → rzd_api-3.0.0}/tests/test_client.py +60 -13
  13. {rzd_api-2.0.0 → rzd_api-3.0.0}/tests/test_config_models.py +6 -0
  14. {rzd_api-2.0.0 → rzd_api-3.0.0}/tests/test_mcp_protocol.py +4 -0
  15. {rzd_api-2.0.0 → rzd_api-3.0.0}/tests/test_mcp_server.py +6 -2
  16. rzd_api-2.0.0/rzd_api/api.py +0 -399
  17. rzd_api-2.0.0/rzd_api/models.py +0 -84
  18. rzd_api-2.0.0/tests/test_api.py +0 -220
  19. {rzd_api-2.0.0 → rzd_api-3.0.0}/LICENSE +0 -0
  20. {rzd_api-2.0.0 → rzd_api-3.0.0}/mcp_server/__init__.py +0 -0
  21. {rzd_api-2.0.0 → rzd_api-3.0.0}/rzd_api/exceptions.py +0 -0
  22. {rzd_api-2.0.0 → rzd_api-3.0.0}/rzd_api/py.typed +0 -0
  23. {rzd_api-2.0.0 → rzd_api-3.0.0}/rzd_api/query.py +0 -0
  24. {rzd_api-2.0.0 → rzd_api-3.0.0}/rzd_api.egg-info/SOURCES.txt +0 -0
  25. {rzd_api-2.0.0 → rzd_api-3.0.0}/rzd_api.egg-info/dependency_links.txt +0 -0
  26. {rzd_api-2.0.0 → rzd_api-3.0.0}/rzd_api.egg-info/entry_points.txt +0 -0
  27. {rzd_api-2.0.0 → rzd_api-3.0.0}/rzd_api.egg-info/requires.txt +0 -0
  28. {rzd_api-2.0.0 → rzd_api-3.0.0}/rzd_api.egg-info/top_level.txt +0 -0
  29. {rzd_api-2.0.0 → rzd_api-3.0.0}/setup.cfg +0 -0
  30. {rzd_api-2.0.0 → rzd_api-3.0.0}/tests/test_query.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: rzd-api
3
- Version: 2.0.0
3
+ Version: 3.0.0
4
4
  Summary: Typed Python client and MCP server for the unofficial ticket.rzd.ru API
5
5
  Author: drgod
6
6
  License-Expression: MIT
@@ -41,7 +41,7 @@ Requires-Dist: types-requests<3,>=2.31; extra == "dev"
41
41
  Requires-Dist: uvicorn<0.52,>=0.51; extra == "dev"
42
42
  Dynamic: license-file
43
43
 
44
- # RZD API 2.0
44
+ # RZD API
45
45
 
46
46
  Типизированный Python-клиент и MCP-сервер для неофициального API
47
47
  [`ticket.rzd.ru`](https://ticket.rzd.ru). Проект не связан с ОАО «РЖД»; внутренние
@@ -54,7 +54,8 @@ endpoint и схема ответов могут изменяться без п
54
54
 
55
55
  - поиск прямых поездов в одну сторону и туда-обратно;
56
56
  - поиск станций по названию и синонимам;
57
- - информация о вагонах, местах и станциях маршрута;
57
+ - календарь доступности и минимальные цены по датам;
58
+ - информация о вагонах, местах, схемах, изображениях и станциях маршрута;
58
59
  - dataclass-модели с полным исходным объектом в `raw`;
59
60
  - MCP через `stdio` и защищённый `streamable-http`;
60
61
  - retries, раздельные таймауты и кэш поиска станций.
@@ -110,7 +111,34 @@ with RzdClient() as client:
110
111
  | `find_stations(query, ...)` | `list[Station]` |
111
112
  | `resolve_station_code(station)` | код станции |
112
113
  | `get_carriages(...)` | `CarriageResult` |
113
- | `get_route_stations(object_id)` | `RouteStationsResult` |
114
+ | `get_train_availability(...)` | `TrainAvailabilityResult` |
115
+ | `get_minimal_prices(...)` | `MinimalPricingResult` |
116
+ | `get_car_scheme(...)` | `CarScheme` |
117
+ | `get_car_images(...)` | `CarImagesResult` |
118
+ | `get_route_stations(...)` | `RouteStationsResult` |
119
+
120
+ `get_carriages()` использует актуальный `CarPricing` и сразу возвращает все вагоны
121
+ поезда. `car_number` этому методу больше не передаётся. Значения `number`,
122
+ `car_sub_type`, `service_class`, `carrier` и `numeration` из выбранного `Carriage`
123
+ можно передать в `get_car_scheme()` и `get_car_images()`.
124
+
125
+ ```python
126
+ with RzdClient() as client:
127
+ carriages = client.get_carriages(
128
+ "2001025", "2004001", departure, "00:48", "059Г"
129
+ )
130
+ car = carriages.cars[0]
131
+ scheme = client.get_car_scheme(
132
+ departure,
133
+ "00:48",
134
+ car.train_number or "059Г",
135
+ car.number or "",
136
+ car.car_sub_type or "",
137
+ car.service_class or "",
138
+ car.carrier or "",
139
+ car_numeration=car.numeration or "FromHead",
140
+ )
141
+ ```
114
142
 
115
143
  `only_with_seats=True` фильтрует по доступности мест из `CarGroups`. Современный
116
144
  pricing endpoint не поддерживает маршруты с пересадками и фильтр типа транспорта,
@@ -124,6 +152,8 @@ from rzd_api import Config, RzdClient
124
152
 
125
153
  config = Config(
126
154
  language="ru",
155
+ # По умолчанию выводится из base_url.
156
+ b2b_base_url=None,
127
157
  connect_timeout=5,
128
158
  read_timeout=20,
129
159
  retry_total=3,
@@ -141,7 +171,8 @@ station-not-found и ambiguous-station.
141
171
  ## MCP
142
172
 
143
173
  Инструменты: `search_tickets`, `find_stations`, `get_carriages`,
144
- `get_route_stations`.
174
+ `get_train_availability`, `get_minimal_prices`, `get_car_scheme`,
175
+ `get_car_images`, `get_route_stations`.
145
176
 
146
177
  Локальный stdio:
147
178
 
@@ -1,4 +1,4 @@
1
- # RZD API 2.0
1
+ # RZD API
2
2
 
3
3
  Типизированный Python-клиент и MCP-сервер для неофициального API
4
4
  [`ticket.rzd.ru`](https://ticket.rzd.ru). Проект не связан с ОАО «РЖД»; внутренние
@@ -11,7 +11,8 @@ endpoint и схема ответов могут изменяться без п
11
11
 
12
12
  - поиск прямых поездов в одну сторону и туда-обратно;
13
13
  - поиск станций по названию и синонимам;
14
- - информация о вагонах, местах и станциях маршрута;
14
+ - календарь доступности и минимальные цены по датам;
15
+ - информация о вагонах, местах, схемах, изображениях и станциях маршрута;
15
16
  - dataclass-модели с полным исходным объектом в `raw`;
16
17
  - MCP через `stdio` и защищённый `streamable-http`;
17
18
  - retries, раздельные таймауты и кэш поиска станций.
@@ -67,7 +68,34 @@ with RzdClient() as client:
67
68
  | `find_stations(query, ...)` | `list[Station]` |
68
69
  | `resolve_station_code(station)` | код станции |
69
70
  | `get_carriages(...)` | `CarriageResult` |
70
- | `get_route_stations(object_id)` | `RouteStationsResult` |
71
+ | `get_train_availability(...)` | `TrainAvailabilityResult` |
72
+ | `get_minimal_prices(...)` | `MinimalPricingResult` |
73
+ | `get_car_scheme(...)` | `CarScheme` |
74
+ | `get_car_images(...)` | `CarImagesResult` |
75
+ | `get_route_stations(...)` | `RouteStationsResult` |
76
+
77
+ `get_carriages()` использует актуальный `CarPricing` и сразу возвращает все вагоны
78
+ поезда. `car_number` этому методу больше не передаётся. Значения `number`,
79
+ `car_sub_type`, `service_class`, `carrier` и `numeration` из выбранного `Carriage`
80
+ можно передать в `get_car_scheme()` и `get_car_images()`.
81
+
82
+ ```python
83
+ with RzdClient() as client:
84
+ carriages = client.get_carriages(
85
+ "2001025", "2004001", departure, "00:48", "059Г"
86
+ )
87
+ car = carriages.cars[0]
88
+ scheme = client.get_car_scheme(
89
+ departure,
90
+ "00:48",
91
+ car.train_number or "059Г",
92
+ car.number or "",
93
+ car.car_sub_type or "",
94
+ car.service_class or "",
95
+ car.carrier or "",
96
+ car_numeration=car.numeration or "FromHead",
97
+ )
98
+ ```
71
99
 
72
100
  `only_with_seats=True` фильтрует по доступности мест из `CarGroups`. Современный
73
101
  pricing endpoint не поддерживает маршруты с пересадками и фильтр типа транспорта,
@@ -81,6 +109,8 @@ from rzd_api import Config, RzdClient
81
109
 
82
110
  config = Config(
83
111
  language="ru",
112
+ # По умолчанию выводится из base_url.
113
+ b2b_base_url=None,
84
114
  connect_timeout=5,
85
115
  read_timeout=20,
86
116
  retry_total=3,
@@ -98,7 +128,8 @@ station-not-found и ambiguous-station.
98
128
  ## MCP
99
129
 
100
130
  Инструменты: `search_tickets`, `find_stations`, `get_carriages`,
101
- `get_route_stations`.
131
+ `get_train_availability`, `get_minimal_prices`, `get_car_scheme`,
132
+ `get_car_images`, `get_route_stations`.
102
133
 
103
134
  Локальный stdio:
104
135
 
@@ -67,7 +67,6 @@ def get_carriages(
67
67
  departure_date: str,
68
68
  departure_time: str,
69
69
  train_number: str,
70
- car_number: str = "01",
71
70
  provider: str = "P1",
72
71
  ) -> dict[str, Any]:
73
72
  """Get typed carriage and seat availability details for a train."""
@@ -78,15 +77,97 @@ def get_carriages(
78
77
  departure_date,
79
78
  departure_time,
80
79
  train_number,
81
- car_number=car_number,
82
80
  provider=provider,
83
81
  ).to_dict()
84
82
 
85
83
 
86
- def get_route_stations(object_id: str) -> dict[str, Any]:
87
- """Get all stations for an RZD route object."""
84
+ def get_train_availability(
85
+ from_station: str,
86
+ to_station: str,
87
+ date_from: str,
88
+ date_to: str,
89
+ ) -> dict[str, Any]:
90
+ """Get dates with available trains for a direction."""
91
+ with RzdClient() as client:
92
+ return client.get_train_availability(from_station, to_station, date_from, date_to).to_dict()
93
+
94
+
95
+ def get_minimal_prices(
96
+ from_station: str,
97
+ to_station: str,
98
+ date_from: str,
99
+ ) -> dict[str, Any]:
100
+ """Get the minimum published prices from a selected date."""
101
+ with RzdClient() as client:
102
+ return client.get_minimal_prices(from_station, to_station, date_from).to_dict()
103
+
104
+
105
+ def get_car_scheme(
106
+ departure_date: str,
107
+ departure_time: str,
108
+ train_number: str,
109
+ car_number: str,
110
+ car_sub_type: str,
111
+ service_class: str,
112
+ carrier: str,
113
+ car_numeration: str = "FromHead",
114
+ ) -> dict[str, Any]:
115
+ """Get carriage scheme metadata."""
116
+ with RzdClient() as client:
117
+ return client.get_car_scheme(
118
+ departure_date,
119
+ departure_time,
120
+ train_number,
121
+ car_number,
122
+ car_sub_type,
123
+ service_class,
124
+ carrier,
125
+ car_numeration=car_numeration,
126
+ ).to_dict()
127
+
128
+
129
+ def get_car_images(
130
+ departure_date: str,
131
+ departure_time: str,
132
+ train_number: str,
133
+ car_number: str,
134
+ car_sub_type: str,
135
+ service_class: str,
136
+ carrier: str,
137
+ car_numeration: str = "FromHead",
138
+ ) -> dict[str, Any]:
139
+ """Get carriage image metadata."""
140
+ with RzdClient() as client:
141
+ return client.get_car_images(
142
+ departure_date,
143
+ departure_time,
144
+ train_number,
145
+ car_number,
146
+ car_sub_type,
147
+ service_class,
148
+ carrier,
149
+ car_numeration=car_numeration,
150
+ ).to_dict()
151
+
152
+
153
+ def get_route_stations(
154
+ from_station: str,
155
+ to_station: str,
156
+ departure_date: str,
157
+ departure_time: str,
158
+ train_number: str,
159
+ provider: str = "P1",
160
+ ) -> dict[str, Any]:
161
+ """Get all stations for a train and direction."""
88
162
  with RzdClient() as client:
89
- return client.get_route_stations(object_id).to_dict()
163
+ return client.get_route_stations(
164
+ from_station,
165
+ to_station,
166
+ departure_date,
167
+ departure_time,
168
+ train_number,
169
+ provider=provider,
170
+ ).to_dict()
90
171
 
91
172
 
92
173
  def create_mcp_app(*, host: str = "127.0.0.1", port: int = 8000) -> Any:
@@ -115,11 +196,15 @@ def create_mcp_app(*, host: str = "127.0.0.1", port: int = 8000) -> Any:
115
196
  app.tool()(search_tickets)
116
197
  app.tool()(find_stations)
117
198
  app.tool()(get_carriages)
199
+ app.tool()(get_train_availability)
200
+ app.tool()(get_minimal_prices)
201
+ app.tool()(get_car_scheme)
202
+ app.tool()(get_car_images)
118
203
  app.tool()(get_route_stations)
119
204
 
120
205
  @app.custom_route("/health", methods=["GET"], include_in_schema=False)
121
206
  async def health(_: Request) -> JSONResponse:
122
- return JSONResponse({"status": "ok", "service": "rzd-api", "version": "2.0.0"})
207
+ return JSONResponse({"status": "ok", "service": "rzd-api", "version": "3.0.0"})
123
208
 
124
209
  return app
125
210
 
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "rzd-api"
7
- version = "2.0.0"
7
+ version = "3.0.0"
8
8
  description = "Typed Python client and MCP server for the unofficial ticket.rzd.ru API"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.10"
@@ -12,20 +12,32 @@ from .exceptions import (
12
12
  )
13
13
  from .models import (
14
14
  CarGroup,
15
+ CarImage,
16
+ CarImagesResult,
15
17
  Carriage,
16
18
  CarriageResult,
19
+ CarScheme,
20
+ MinimalPrice,
21
+ MinimalPricingResult,
17
22
  RoundTripResult,
18
23
  RouteStation,
19
24
  RouteStationsResult,
20
25
  Station,
26
+ TrainAvailability,
27
+ TrainAvailabilityResult,
21
28
  TrainRoute,
22
29
  )
23
30
 
24
31
  __all__ = [
25
32
  "CarGroup",
33
+ "CarImage",
34
+ "CarImagesResult",
35
+ "CarScheme",
26
36
  "Carriage",
27
37
  "CarriageResult",
28
38
  "Config",
39
+ "MinimalPrice",
40
+ "MinimalPricingResult",
29
41
  "RoundTripResult",
30
42
  "RouteStation",
31
43
  "RouteStationsResult",
@@ -39,5 +51,7 @@ __all__ = [
39
51
  "RzdTransportError",
40
52
  "RzdValidationError",
41
53
  "Station",
54
+ "TrainAvailability",
55
+ "TrainAvailabilityResult",
42
56
  "TrainRoute",
43
57
  ]