python-navitia-client 1.1.0__py3-none-any.whl

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 (83) hide show
  1. navitia_client/__init__.py +0 -0
  2. navitia_client/client/__init__.py +0 -0
  3. navitia_client/client/apis/__init__.py +0 -0
  4. navitia_client/client/apis/api_base_client.py +50 -0
  5. navitia_client/client/apis/arrival_apis.py +191 -0
  6. navitia_client/client/apis/contributors_apis.py +107 -0
  7. navitia_client/client/apis/coverage_apis.py +131 -0
  8. navitia_client/client/apis/datasets_apis.py +105 -0
  9. navitia_client/client/apis/departure_apis.py +211 -0
  10. navitia_client/client/apis/inverted_geocoding_apis.py +199 -0
  11. navitia_client/client/apis/isochrone_apis.py +196 -0
  12. navitia_client/client/apis/journeys_apis.py +629 -0
  13. navitia_client/client/apis/line_report_apis.py +106 -0
  14. navitia_client/client/apis/place_apis.py +74 -0
  15. navitia_client/client/apis/places_nearby_apis.py +354 -0
  16. navitia_client/client/apis/public_transport_objects_apis.py +88 -0
  17. navitia_client/client/apis/public_transportation_apis/__init__.py +10 -0
  18. navitia_client/client/apis/public_transportation_apis/commercial_mode_apis.py +251 -0
  19. navitia_client/client/apis/public_transportation_apis/company_apis.py +303 -0
  20. navitia_client/client/apis/public_transportation_apis/disruption_apis.py +305 -0
  21. navitia_client/client/apis/public_transportation_apis/entity_apis.py +330 -0
  22. navitia_client/client/apis/public_transportation_apis/line_apis.py +303 -0
  23. navitia_client/client/apis/public_transportation_apis/network_apis.py +303 -0
  24. navitia_client/client/apis/public_transportation_apis/physical_mode_apis.py +303 -0
  25. navitia_client/client/apis/public_transportation_apis/route_apis.py +303 -0
  26. navitia_client/client/apis/public_transportation_apis/stop_area_apis.py +303 -0
  27. navitia_client/client/apis/public_transportation_apis/stop_point_apis.py +303 -0
  28. navitia_client/client/apis/public_transportation_apis/vehicle_journey_apis.py +304 -0
  29. navitia_client/client/apis/route_schedules_apis.py +177 -0
  30. navitia_client/client/apis/stop_schedules_apis.py +181 -0
  31. navitia_client/client/apis/terminus_schedules_apis.py +186 -0
  32. navitia_client/client/apis/traffic_report_apis.py +106 -0
  33. navitia_client/client/exceptions.py +18 -0
  34. navitia_client/client/navitia_client.py +302 -0
  35. navitia_client/client/raw/__init__.py +0 -0
  36. navitia_client/client/raw/raw_client.py +58 -0
  37. navitia_client/entities/__init__.py +23 -0
  38. navitia_client/entities/access_point.py +10 -0
  39. navitia_client/entities/address.py +28 -0
  40. navitia_client/entities/administrative_region.py +59 -0
  41. navitia_client/entities/arrival.py +21 -0
  42. navitia_client/entities/base_entity.py +7 -0
  43. navitia_client/entities/company.py +16 -0
  44. navitia_client/entities/context.py +10 -0
  45. navitia_client/entities/contributor.py +19 -0
  46. navitia_client/entities/coord.py +15 -0
  47. navitia_client/entities/dataset.py +32 -0
  48. navitia_client/entities/departure.py +21 -0
  49. navitia_client/entities/direction.py +24 -0
  50. navitia_client/entities/display_information.py +43 -0
  51. navitia_client/entities/disruption.py +233 -0
  52. navitia_client/entities/equipment.py +42 -0
  53. navitia_client/entities/equipment_reports.py +10 -0
  54. navitia_client/entities/isochrones.py +30 -0
  55. navitia_client/entities/journey.py +133 -0
  56. navitia_client/entities/line_and_route.py +76 -0
  57. navitia_client/entities/line_report.py +18 -0
  58. navitia_client/entities/link.py +44 -0
  59. navitia_client/entities/network.py +16 -0
  60. navitia_client/entities/note.py +7 -0
  61. navitia_client/entities/pagination.py +19 -0
  62. navitia_client/entities/path.py +30 -0
  63. navitia_client/entities/pathway.py +11 -0
  64. navitia_client/entities/physical_mode.py +92 -0
  65. navitia_client/entities/place.py +40 -0
  66. navitia_client/entities/poi.py +16 -0
  67. navitia_client/entities/pt_datetime.py +31 -0
  68. navitia_client/entities/pt_object.py +57 -0
  69. navitia_client/entities/route_schedule.py +19 -0
  70. navitia_client/entities/schedule_table.py +59 -0
  71. navitia_client/entities/stand.py +16 -0
  72. navitia_client/entities/stop_area.py +82 -0
  73. navitia_client/entities/stop_datetime.py +39 -0
  74. navitia_client/entities/stop_schedule.py +59 -0
  75. navitia_client/entities/ticket.py +49 -0
  76. navitia_client/entities/traffic_report.py +21 -0
  77. navitia_client/entities/trip.py +13 -0
  78. navitia_client/entities/vehicle_journey.py +163 -0
  79. python_navitia_client-1.1.0.dist-info/LICENSE +21 -0
  80. python_navitia_client-1.1.0.dist-info/METADATA +114 -0
  81. python_navitia_client-1.1.0.dist-info/RECORD +83 -0
  82. python_navitia_client-1.1.0.dist-info/WHEEL +5 -0
  83. python_navitia_client-1.1.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,106 @@
1
+ from datetime import datetime
2
+ from typing import Optional, Sequence, Tuple
3
+ from navitia_client.client.apis.api_base_client import ApiBaseClient
4
+ from navitia_client.entities.disruption import Disruption
5
+ from navitia_client.entities.line_report import LineReport
6
+
7
+
8
+ class LineReportsApiClient(ApiBaseClient):
9
+ """
10
+ A client class to interact with the Navitia API for fetching line reports.
11
+
12
+ See https://doc.navitia.io/#line-reports
13
+
14
+ Methods
15
+ -------
16
+ _get_line_reports(url: str, filters: dict) -> Tuple[Sequence[Disruption], Sequence[LineReport]]:
17
+ Retrieves line reports from the specified URL with the provided filters.
18
+
19
+ list_line_reports(region_id: Optional[str] = None, resource_path: Optional[str] = None, since: Optional[datetime] = None, until: Optional[datetime] = None, count: int = 25, depth: int = 1, forbidden_uris: Optional[Sequence[str]] = None, disable_geojson: bool = False) -> Tuple[Sequence[Disruption], Sequence[LineReport]]:
20
+ Lists line reports based on specified criteria.
21
+ """
22
+
23
+ def _get_line_reports(
24
+ self, url: str, filters: dict
25
+ ) -> Tuple[Sequence[Disruption], Sequence[LineReport]]:
26
+ """
27
+ Retrieves line reports from the specified URL with the provided filters.
28
+
29
+ Parameters
30
+ ----------
31
+ url : str
32
+ The URL to fetch line reports from.
33
+ filters : dict
34
+ Filters to apply to the API request.
35
+
36
+ Returns
37
+ -------
38
+ Tuple[Sequence[Disruption], Sequence[LineReport]]
39
+ A tuple containing sequences of Disruption and LineReport objects.
40
+ """
41
+ results = self.get_navitia_api(url + self._generate_filter_query(filters))
42
+ line_reports = [
43
+ LineReport.from_payload(data) for data in results.json()["line_reports"]
44
+ ]
45
+ disruptions = [
46
+ Disruption.from_payload(data) for data in results.json()["disruptions"]
47
+ ]
48
+ return disruptions, line_reports
49
+
50
+ def list_line_reports(
51
+ self,
52
+ region_id: Optional[str] = None,
53
+ resource_path: Optional[str] = None,
54
+ since: Optional[datetime] = None,
55
+ until: Optional[datetime] = None,
56
+ count: int = 25,
57
+ depth: int = 1,
58
+ forbidden_uris: Optional[Sequence[str]] = None,
59
+ disable_geojson: bool = False,
60
+ ) -> Tuple[Sequence[Disruption], Sequence[LineReport]]:
61
+ """
62
+ Lists line reports based on specified criteria.
63
+
64
+ Parameters
65
+ ----------
66
+ region_id : Optional[str], optional
67
+ The ID of the region for which to fetch line reports, by default None.
68
+ resource_path : Optional[str], optional
69
+ The resource path for line reports, by default None.
70
+ since : Optional[datetime], optional
71
+ Filter line reports since this date and time, by default None.
72
+ until : Optional[datetime], optional
73
+ Filter line reports until this date and time, by default None.
74
+ count : int, optional
75
+ The number of line reports to retrieve, by default 25.
76
+ depth : int, optional
77
+ The depth of the query, by default 1.
78
+ forbidden_uris : Optional[Sequence[str]], optional
79
+ List of URIs to forbid, by default None.
80
+ disable_geojson : bool, optional
81
+ Whether to disable GeoJSON output, by default False.
82
+
83
+ Returns
84
+ -------
85
+ Tuple[Sequence[Disruption], Sequence[LineReport]]
86
+ A tuple containing sequences of Disruption and LineReport objects.
87
+ """
88
+ if resource_path:
89
+ request_url = f"{self.base_navitia_url}/coverage/{region_id}/{resource_path}/line_reports"
90
+ else:
91
+ request_url = f"{self.base_navitia_url}/coverage/{region_id}/line_reports"
92
+
93
+ filters = {
94
+ "count": count,
95
+ "depth": depth,
96
+ "disable_geojson": disable_geojson,
97
+ "forbidden_uris[]": forbidden_uris,
98
+ }
99
+
100
+ if since:
101
+ filters["since"] = since.isoformat()
102
+
103
+ if until:
104
+ filters["until"] = until.isoformat()
105
+
106
+ return self._get_line_reports(request_url, filters)
@@ -0,0 +1,74 @@
1
+ from typing import Any, Optional, Sequence, Tuple
2
+ from navitia_client.client.apis.api_base_client import ApiBaseClient
3
+ from navitia_client.entities.place import Place
4
+
5
+
6
+ class PlacesApiClient(ApiBaseClient):
7
+ """
8
+ A client class to interact with the Navitia API for fetching place information.
9
+
10
+ See https://doc.navitia.io/#places
11
+
12
+ Methods
13
+ -------
14
+ _get_pt_objects_from_response(response: Any) -> Sequence[Place]
15
+ A static method to transform raw API response data into a list of Place objects.
16
+
17
+ list_places(
18
+ region_id: str, query: str,
19
+ type: Sequence[str] = ["stop_area", "address", "poi", "administrative_region"],
20
+ disable_geojson: bool = False, depth: int = 1,
21
+ from_lon_lat: Optional[Tuple[float, float]] = None
22
+ ) -> Sequence[Place]
23
+ Retrieves a list of places based on the provided query and region ID from the Navitia API.
24
+ """
25
+
26
+ @staticmethod
27
+ def _get_pt_objects_from_response(response: Any) -> Sequence[Place]:
28
+ """
29
+ Transform raw API response data into a list of Place objects.
30
+
31
+ Parameters:
32
+ response (Any): The raw API response data.
33
+
34
+ Returns:
35
+ Sequence[Place]: A list of Place objects.
36
+ """
37
+ entities = []
38
+ for entity_data in response:
39
+ entities.append(Place.from_payload(entity_data))
40
+ return entities
41
+
42
+ def list_places(
43
+ self,
44
+ region_id: str,
45
+ query: str,
46
+ type: Sequence[str] = ["stop_area", "address", "poi", "administrative_region"],
47
+ disable_geojson: bool = False,
48
+ depth: int = 1,
49
+ from_lon_lat: Optional[Tuple[float, float]] = None,
50
+ ) -> Sequence[Place]:
51
+ """
52
+ Retrieves a list of places based on the provided query and region ID from the Navitia API.
53
+
54
+ Parameters:
55
+ region_id (str): The region ID.
56
+ query (str): The query string to search for places.
57
+ type (Sequence[str], optional): The types of places to include in the search.
58
+ Defaults to ["stop_area", "address", "poi", "administrative_region"].
59
+ disable_geojson (bool, optional): Whether to disable GeoJSON format in the response.
60
+ Defaults to False.
61
+ depth (int, optional): The depth of data to retrieve. Defaults to 1.
62
+ from_lon_lat (Optional[Tuple[float, float]], optional): The longitude and latitude
63
+ from which to search for places. Defaults to None.
64
+
65
+ Returns:
66
+ Sequence[Place]: A list of Place objects matching the query.
67
+ """
68
+ request_url = f"{self.base_navitia_url}/coverage/{region_id}/places?q={query}&type={type}&disable_geojson={disable_geojson}&depth={depth}"
69
+ if from_lon_lat:
70
+ request_url += f"&filter={from_lon_lat[0]};{from_lon_lat[1]}"
71
+
72
+ results = self.get_navitia_api(request_url)
73
+ raw_results = results.json()["places"]
74
+ return self._get_pt_objects_from_response(raw_results)
@@ -0,0 +1,354 @@
1
+ from typing import Any, Optional, Sequence, Tuple
2
+ from navitia_client.client.apis.api_base_client import ApiBaseClient
3
+ from navitia_client.entities.pagination import Pagination
4
+ from navitia_client.entities.place import Place
5
+
6
+
7
+ class PlacesNearbyApiClient(ApiBaseClient):
8
+ """
9
+ A client class to interact with the Navitia API for fetching nearby places information.
10
+
11
+ See https://doc.navitia.io/#places_nearby
12
+
13
+ Methods
14
+ -------
15
+ _get_pt_objects_from_response(response: Any) -> Sequence[Place]
16
+ A static method to transform raw API response data into a list of Place objects.
17
+
18
+ list_objects_by_region_id_and_path(
19
+ region_id: str, resource_path: str,
20
+ distance: int = 500, type: Sequence[str] = ["stop_area", "stop_point", "poi"],
21
+ admin_uri: Optional[Sequence[str]] = None, filter: Optional[str] = None,
22
+ disable_geojson: bool = False, disable_disruption: bool = False,
23
+ depth: int = 1, start_page: int = 0, count: int = 25,
24
+ add_poi_infos: Sequence[str] = ["bss_stands", "car_park"]
25
+ ) -> Tuple[Sequence[Place], Pagination]
26
+ Retrieves a list of places nearby based on the region ID and resource path from the Navitia API.
27
+
28
+ list_objects_by_region_id_and_coordinates(
29
+ region_id: str, lon: float, lat: float,
30
+ distance: int = 500, type: Sequence[str] = ["stop_area", "stop_point", "poi"],
31
+ admin_uri: Optional[Sequence[str]] = None, filter: Optional[str] = None,
32
+ disable_geojson: bool = False, disable_disruption: bool = False,
33
+ depth: int = 1, start_page: int = 0, count: int = 25,
34
+ add_poi_infos: Sequence[str] = ["bss_stands", "car_park"]
35
+ ) -> Tuple[Sequence[Place], Pagination]
36
+ Retrieves a list of places nearby based on the region ID and coordinates from the Navitia API.
37
+
38
+ list_objects_by_coordinates(
39
+ region_lon: float, region_lat: float, lon: float, lat: float,
40
+ distance: int = 500, type: Sequence[str] = ["stop_area", "stop_point", "poi"],
41
+ admin_uri: Optional[Sequence[str]] = None, filter: Optional[str] = None,
42
+ disable_geojson: bool = False, disable_disruption: bool = False,
43
+ depth: int = 1, start_page: int = 0, count: int = 25,
44
+ add_poi_infos: Sequence[str] = ["bss_stands", "car_park"]
45
+ ) -> Tuple[Sequence[Place], Pagination]
46
+ Retrieves a list of places nearby based on the coordinates from the Navitia API.
47
+
48
+ list_objects_by_object_coordinates_only(
49
+ lon: float, lat: float, distance: int = 500,
50
+ type: Sequence[str] = ["stop_area", "stop_point", "poi"],
51
+ admin_uri: Optional[Sequence[str]] = None, filter: Optional[str] = None,
52
+ disable_geojson: bool = False, disable_disruption: bool = False,
53
+ depth: int = 1, start_page: int = 0, count: int = 25,
54
+ add_poi_infos: Sequence[str] = ["bss_stands", "car_park"]
55
+ ) -> Tuple[Sequence[Place], Pagination]
56
+ Retrieves a list of places nearby based on the coordinates only from the Navitia API.
57
+ """
58
+
59
+ @staticmethod
60
+ def _get_pt_objects_from_response(response: Any) -> Sequence[Place]:
61
+ """
62
+ Transform raw API response data into a list of Place objects.
63
+
64
+ Parameters:
65
+ response (Any): The raw API response data.
66
+
67
+ Returns:
68
+ Sequence[Place]: A list of Place objects.
69
+ """
70
+ entities = []
71
+ for entity_data in response:
72
+ entities.append(Place.from_payload(entity_data))
73
+
74
+ return entities
75
+
76
+ def _get_places_nearby(
77
+ self, url: str, filters: dict
78
+ ) -> Tuple[Sequence[Place], Pagination]:
79
+ """
80
+ Fetches nearby places based on the provided URL and filters.
81
+
82
+ Parameters:
83
+ url (str): The URL for the API request.
84
+ filters (dict): Filters to be applied to the API request.
85
+
86
+ Returns:
87
+ Tuple[Sequence[Place], Pagination]: A tuple containing a list of nearby Place objects
88
+ and pagination information.
89
+ """
90
+ results = self.get_navitia_api(url + self._generate_filter_query(filters))
91
+ raw_results = results.json()["places_nearby"]
92
+ pagination = Pagination.from_payload(results.json()["pagination"])
93
+ return self._get_pt_objects_from_response(raw_results), pagination
94
+
95
+ def list_objects_by_region_id_and_path(
96
+ self,
97
+ region_id: str,
98
+ resource_path: str,
99
+ distance: int = 500,
100
+ type: Sequence[str] = ["stop_area", "stop_point", "poi"],
101
+ admin_uri: Optional[Sequence[str]] = None,
102
+ filter: Optional[str] = None,
103
+ disable_geojson: bool = False,
104
+ disable_disruption: bool = False,
105
+ depth: int = 1,
106
+ start_page: int = 0,
107
+ count: int = 25,
108
+ add_poi_infos: Sequence[str] = ["bss_stands", "car_park"],
109
+ ) -> Tuple[Sequence[Place], Pagination]:
110
+ """
111
+ Retrieves a list of places nearby based on the region ID and resource path from the Navitia API.
112
+
113
+ Parameters:
114
+ region_id (str): The region ID.
115
+ resource_path (str): The resource path.
116
+ distance (int, optional): The distance for nearby search. Defaults to 500.
117
+ type (Sequence[str], optional): The types of places to include in the search.
118
+ Defaults to ["stop_area", "stop_point", "poi"].
119
+ admin_uri (Optional[Sequence[str]], optional): The administrative URIs to filter by.
120
+ Defaults to None.
121
+ filter (Optional[str], optional): Additional filtering criteria. Defaults to None.
122
+ disable_geojson (bool, optional): Whether to disable GeoJSON format in the response.
123
+ Defaults to False.
124
+ disable_disruption (bool, optional): Whether to disable disruption information.
125
+ Defaults to False.
126
+ depth (int, optional): The depth of data to retrieve. Defaults to 1.
127
+ start_page (int, optional): The starting page for pagination. Defaults to 0.
128
+ count (int, optional): The number of items per page. Defaults to 25.
129
+ add_poi_infos (Sequence[str], optional): Additional POI information to include.
130
+ Defaults to ["bss_stands", "car_park"].
131
+
132
+ Returns:
133
+ Tuple[Sequence[Place], Pagination]: A tuple containing a list of nearby Place objects
134
+ and pagination information.
135
+ """
136
+ request_url = f"{self.base_navitia_url}/coverage/{region_id}/{resource_path}/places_nearby"
137
+
138
+ filters = {
139
+ "start_page": start_page,
140
+ "count": count,
141
+ "depth": depth,
142
+ "type[]": type,
143
+ "distance": distance,
144
+ "disable_geojson": disable_geojson,
145
+ "disable_disruption": disable_disruption,
146
+ "add_poi_infos[]": add_poi_infos,
147
+ }
148
+
149
+ if admin_uri:
150
+ filters["admin_uris[]"] = admin_uri
151
+
152
+ if filter:
153
+ filters["filter"] = filter
154
+
155
+ return self._get_places_nearby(request_url, filters)
156
+
157
+ def list_objects_by_region_id_and_coordinates(
158
+ self,
159
+ region_id: str,
160
+ lon: float,
161
+ lat: float,
162
+ distance: int = 500,
163
+ type: Sequence[str] = ["stop_area", "stop_point", "poi"],
164
+ admin_uri: Optional[Sequence[str]] = None,
165
+ filter: Optional[str] = None,
166
+ disable_geojson: bool = False,
167
+ disable_disruption: bool = False,
168
+ depth: int = 1,
169
+ start_page: int = 0,
170
+ count: int = 25,
171
+ add_poi_infos: Sequence[str] = ["bss_stands", "car_park"],
172
+ ) -> Tuple[Sequence[Place], Pagination]:
173
+ """
174
+ Retrieves a list of places nearby based on the region ID and coordinates from the Navitia API.
175
+
176
+ Parameters:
177
+ region_id (str): The region ID.
178
+ lon (float): The longitude coordinate.
179
+ lat (float): The latitude coordinate.
180
+ distance (int, optional): The distance for nearby search. Defaults to 500.
181
+ type (Sequence[str], optional): The types of places to include in the search.
182
+ Defaults to ["stop_area", "stop_point", "poi"].
183
+ admin_uri (Optional[Sequence[str]], optional): The administrative URIs to filter by.
184
+ Defaults to None.
185
+ filter (Optional[str], optional): Additional filtering criteria. Defaults to None.
186
+ disable_geojson (bool, optional): Whether to disable GeoJSON format in the response.
187
+ Defaults to False.
188
+ disable_disruption (bool, optional): Whether to disable disruption information.
189
+ Defaults to False.
190
+ depth (int, optional): The depth of data to retrieve. Defaults to 1.
191
+ start_page (int, optional): The starting page for pagination. Defaults to 0.
192
+ count (int, optional): The number of items per page. Defaults to 25.
193
+ add_poi_infos (Sequence[str], optional): Additional POI information to include.
194
+ Defaults to ["bss_stands", "car_park"].
195
+
196
+ Returns:
197
+ Tuple[Sequence[Place], Pagination]: A tuple containing a list of nearby Place objects
198
+ and pagination information.
199
+ """
200
+ request_url = (
201
+ f"{self.base_navitia_url}/coverage/{region_id}/{lon};{lat}/places_nearby"
202
+ )
203
+
204
+ filters = {
205
+ "start_page": start_page,
206
+ "count": count,
207
+ "depth": depth,
208
+ "type[]": type,
209
+ "distance": distance,
210
+ "disable_geojson": disable_geojson,
211
+ "disable_disruption": disable_disruption,
212
+ "add_poi_infos[]": add_poi_infos,
213
+ }
214
+
215
+ if admin_uri:
216
+ filters["admin_uris[]"] = admin_uri
217
+
218
+ if filter:
219
+ filters["filter"] = filter
220
+
221
+ return self._get_places_nearby(request_url, filters)
222
+
223
+ def list_objects_by_coordinates(
224
+ self,
225
+ region_lon: float,
226
+ region_lat: float,
227
+ lon: float,
228
+ lat: float,
229
+ distance: int = 500,
230
+ type: Sequence[str] = ["stop_area", "stop_point", "poi"],
231
+ admin_uri: Optional[Sequence[str]] = None,
232
+ filter: Optional[str] = None,
233
+ disable_geojson: bool = False,
234
+ disable_disruption: bool = False,
235
+ depth: int = 1,
236
+ start_page: int = 0,
237
+ count: int = 25,
238
+ add_poi_infos: Sequence[str] = ["bss_stands", "car_park"],
239
+ ) -> Tuple[Sequence[Place], Pagination]:
240
+ """
241
+ Retrieves a list of places nearby based on the provided coordinates from the Navitia API.
242
+
243
+ Parameters:
244
+ region_lon (float): The longitude coordinate of the region.
245
+ region_lat (float): The latitude coordinate of the region.
246
+ lon (float): The longitude coordinate.
247
+ lat (float): The latitude coordinate.
248
+ distance (int, optional): The distance for nearby search. Defaults to 500.
249
+ type (Sequence[str], optional): The types of places to include in the search.
250
+ Defaults to ["stop_area", "stop_point", "poi"].
251
+ admin_uri (Optional[Sequence[str]], optional): The administrative URIs to filter by.
252
+ Defaults to None.
253
+ filter (Optional[str], optional): Additional filtering criteria. Defaults to None.
254
+ disable_geojson (bool, optional): Whether to disable GeoJSON format in the response.
255
+ Defaults to False.
256
+ disable_disruption (bool, optional): Whether to disable disruption information.
257
+ Defaults to False.
258
+ depth (int, optional): The depth of data to retrieve. Defaults to 1.
259
+ start_page (int, optional): The starting page for pagination. Defaults to 0.
260
+ count (int, optional): The number of items per page. Defaults to 25.
261
+ add_poi_infos (Sequence[str], optional): Additional POI information to include.
262
+ Defaults to ["bss_stands", "car_park"].
263
+
264
+ Returns:
265
+ Tuple[Sequence[Place], Pagination]: A tuple containing a list of nearby Place objects
266
+ and pagination information.
267
+ """
268
+ request_url = f"{self.base_navitia_url}/coverage/{region_lon};{region_lat}/coords/{lon};{lat}/places_nearby"
269
+
270
+ filters = {
271
+ "start_page": start_page,
272
+ "count": count,
273
+ "depth": depth,
274
+ "type[]": type,
275
+ "distance": distance,
276
+ "disable_geojson": disable_geojson,
277
+ "disable_disruption": disable_disruption,
278
+ "add_poi_infos[]": add_poi_infos,
279
+ }
280
+
281
+ if admin_uri:
282
+ filters["admin_uris[]"] = admin_uri
283
+
284
+ if filter:
285
+ filters["filter"] = filter
286
+
287
+ return self._get_places_nearby(request_url, filters)
288
+
289
+ def list_objects_by_object_coordinates_only(
290
+ self,
291
+ lon: float,
292
+ lat: float,
293
+ distance: int = 500,
294
+ type: Sequence[str] = ["stop_area", "stop_point", "poi"],
295
+ admin_uri: Optional[Sequence[str]] = None,
296
+ filter: Optional[str] = None,
297
+ disable_geojson: bool = False,
298
+ disable_disruption: bool = False,
299
+ depth: int = 1,
300
+ start_page: int = 0,
301
+ count: int = 25,
302
+ add_poi_infos: Sequence[str] = ["bss_stands", "car_park"],
303
+ ) -> Tuple[Sequence[Place], Pagination]:
304
+ """
305
+ Retrieves a list of places nearby based on the provided coordinates from the Navitia API.
306
+
307
+ Parameters:
308
+ lon (float): The longitude coordinate.
309
+ lat (float): The latitude coordinate.
310
+ distance (int, optional): The distance for nearby search. Defaults to 500.
311
+ type (Sequence[str], optional): The types of places to include in the search.
312
+ Defaults to ["stop_area", "stop_point", "poi"].
313
+ admin_uri (Optional[Sequence[str]], optional): The administrative URIs to filter by.
314
+ Defaults to None.
315
+ filter (Optional[str], optional): Additional filtering criteria. Defaults to None.
316
+ disable_geojson (bool, optional): Whether to disable GeoJSON format in the response.
317
+ Defaults to False.
318
+ disable_disruption (bool, optional): Whether to disable disruption information.
319
+ Defaults to False.
320
+ depth (int, optional): The depth of data to retrieve. Defaults to 1.
321
+ start_page (int, optional): The starting page for pagination. Defaults to 0.
322
+ count (int, optional): The number of items per page. Defaults to 25.
323
+ add_poi_infos (Sequence[str], optional): Additional POI information to include.
324
+ Defaults to ["bss_stands", "car_park"].
325
+
326
+ Returns:
327
+ Tuple[Sequence[Place], Pagination]: A tuple containing a list of nearby Place objects
328
+ and pagination information.
329
+ """
330
+ request_url = f"{self.base_navitia_url}/coverage/{lon};{lat}/places_nearby"
331
+
332
+ if not request_url:
333
+ raise ValueError(
334
+ "Region id, region coordinates or coordinates must be provided."
335
+ )
336
+
337
+ filters = {
338
+ "start_page": start_page,
339
+ "count": count,
340
+ "depth": depth,
341
+ "type[]": type,
342
+ "distance": distance,
343
+ "disable_geojson": disable_geojson,
344
+ "disable_disruption": disable_disruption,
345
+ "add_poi_infos[]": add_poi_infos,
346
+ }
347
+
348
+ if admin_uri:
349
+ filters["admin_uris[]"] = admin_uri
350
+
351
+ if filter:
352
+ filters["filter"] = filter
353
+
354
+ return self._get_places_nearby(request_url, filters)
@@ -0,0 +1,88 @@
1
+ from typing import Any, Optional, Sequence
2
+ from navitia_client.client.apis.api_base_client import ApiBaseClient
3
+ from navitia_client.entities.pt_object import PtObject
4
+
5
+
6
+ class PublicTransportObjectsApiClient(ApiBaseClient):
7
+ """
8
+ A client class to interact with the Navitia API for fetching public transport objects.
9
+
10
+ See https://doc.navitia.io/#pt-objects
11
+
12
+ Methods
13
+ -------
14
+ _get_pt_objects_from_response(response: Any) -> Sequence[PtObject]:
15
+ A static method to transform raw API response data into a list of PtObject objects.
16
+
17
+ list_public_transport_objects(
18
+ region_id: str,
19
+ query: str,
20
+ type: Sequence[str] = [
21
+ "network",
22
+ "commercial_mode",
23
+ "line",
24
+ "route",
25
+ "stop_area",
26
+ ],
27
+ disable_disruption: bool = False,
28
+ depth: int = 1,
29
+ post_query_filter: Optional[str] = None,
30
+ ) -> Sequence[PtObject]:
31
+ Retrieves a list of public transport objects for a specified region from the Navitia API.
32
+ """
33
+
34
+ @staticmethod
35
+ def _get_pt_objects_from_response(response: Any) -> Sequence[PtObject]:
36
+ """
37
+ Static method to transform raw API response data into a list of PtObject objects.
38
+
39
+ Parameters:
40
+ response (Any): The raw API response data.
41
+
42
+ Returns:
43
+ Sequence[PtObject]: A sequence of PtObject objects.
44
+ """
45
+ pt_objects = []
46
+ for pt_objects_data in response:
47
+ pt_objects.append(PtObject.from_payload(pt_objects_data))
48
+
49
+ return pt_objects
50
+
51
+ def list_public_transport_objects(
52
+ self,
53
+ region_id: str,
54
+ query: str,
55
+ type: Sequence[str] = [
56
+ "network",
57
+ "commercial_mode",
58
+ "line",
59
+ "route",
60
+ "stop_area",
61
+ ],
62
+ disable_disruption: bool = False,
63
+ depth: int = 1,
64
+ post_query_filter: Optional[str] = None,
65
+ ) -> Sequence[PtObject]:
66
+ """
67
+ Retrieves a list of public transport objects for a specified region from the Navitia API.
68
+
69
+ Parameters:
70
+ region_id (str): The region ID.
71
+ query (str): The search query.
72
+ type (Sequence[str], optional): The types of public transport objects to include
73
+ in the search. Defaults to ["network", "commercial_mode", "line", "route", "stop_area"].
74
+ disable_disruption (bool, optional): Whether to disable disruption information in the response.
75
+ Defaults to False.
76
+ depth (int, optional): The depth of data to retrieve. Defaults to 1.
77
+ post_query_filter (Optional[str], optional): Additional filtering criteria. Defaults to None.
78
+
79
+ Returns:
80
+ Sequence[PtObject]: A sequence of PtObject objects.
81
+ """
82
+ request_url = f"{self.base_navitia_url}/coverage/{region_id}/pt_objects?q={query}&type={type}&disable_disruption={disable_disruption}&depth={depth}"
83
+ if post_query_filter:
84
+ request_url += f"&filter={post_query_filter}"
85
+
86
+ results = self.get_navitia_api(request_url)
87
+ raw_results = results.json()["pt_objects"]
88
+ return self._get_pt_objects_from_response(raw_results)
@@ -0,0 +1,10 @@
1
+ from .commercial_mode_apis import CommercialModeApiClient # noqa: F401
2
+ from .company_apis import CompanyApiClient # noqa: F401
3
+ from .disruption_apis import DisruptionApiClient # noqa: F401
4
+ from .line_apis import LineApiClient # noqa: F401
5
+ from .network_apis import NetworkApiClient # noqa: F401
6
+ from .physical_mode_apis import PhysicalModeApiClient # noqa: F401
7
+ from .route_apis import RouteApiClient # noqa: F401
8
+ from .stop_area_apis import StopAreaApiClient # noqa: F401
9
+ from .stop_point_apis import StopPointApiClient # noqa: F401
10
+ from .vehicle_journey_apis import VehicleJourneyApiClient # noqa: F401