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
File without changes
File without changes
File without changes
@@ -0,0 +1,50 @@
1
+ from typing import Any
2
+ from requests import Response, Session # type: ignore
3
+
4
+ from navitia_client.client.exceptions import (
5
+ NavitiaAccessTokenMissingError,
6
+ NavitiaForbiddenAccessError,
7
+ NavitiaNotFoundError,
8
+ NavitiaUnknownObjectError,
9
+ NavitiaUnableToParseError,
10
+ )
11
+
12
+
13
+ class ApiBaseClient:
14
+ """Common base client for API calls."""
15
+
16
+ def __init__(self, auth_token: str, base_navitia_url: str) -> None:
17
+ self.base_navitia_url = base_navitia_url
18
+ self.session = Session()
19
+ self.session.headers.update({"Authorization": auth_token})
20
+
21
+ @staticmethod
22
+ def _check_response_for_exception(response: Response) -> Response:
23
+ json_payload = response.json()
24
+ if "error" in json_payload:
25
+ error_message = json_payload["error"]["message"]
26
+ match json_payload["error"]["id"]:
27
+ case "unable_to_parse":
28
+ raise NavitiaUnableToParseError(error_message)
29
+ case "unknown_object":
30
+ raise NavitiaUnknownObjectError(error_message)
31
+ case "no_solution":
32
+ raise NavitiaNotFoundError(error_message)
33
+
34
+ if "message" in json_payload:
35
+ error_message = json_payload["message"]
36
+ if "no token" in error_message:
37
+ raise NavitiaAccessTokenMissingError(error_message)
38
+ if " either read-protected or not readable" in error_message:
39
+ raise NavitiaForbiddenAccessError(error_message)
40
+
41
+ return response
42
+
43
+ @staticmethod
44
+ def _generate_filter_query(filters: dict[str, Any]) -> str:
45
+ """Generate query string regarding provided filters"""
46
+ filter_query = "&".join([f"{key}={value}" for key, value in filters.items()])
47
+ return "?" + filter_query if filter_query else ""
48
+
49
+ def get_navitia_api(self, endpoint: str) -> Response:
50
+ return self._check_response_for_exception(self.session.get(endpoint))
@@ -0,0 +1,191 @@
1
+ from datetime import datetime
2
+ from typing import Any, Optional, Sequence, Tuple
3
+ from navitia_client.client.apis.api_base_client import ApiBaseClient
4
+ from navitia_client.entities.pagination import Pagination
5
+ from navitia_client.entities.arrival import Arrival
6
+
7
+
8
+ class ArrivalApiClient(ApiBaseClient):
9
+ """
10
+ A client class to interact with the Navitia API for fetching arrival information.
11
+
12
+ See https://doc.navitia.io/#arrivals
13
+
14
+ Methods
15
+ -------
16
+ _get_departure_objects_from_response(response: Any) -> Sequence[Arrival]
17
+ A static method to transform raw API response data into a list of Arrival objects.
18
+
19
+ _get_departures(url: str, filters: dict) -> Tuple[Sequence[Arrival], Pagination]
20
+ Internal method to fetch departures based on a given URL and filters.
21
+
22
+ list_arrivals_by_region_id_and_path(region_id: str, resource_path: str, from_datetime: datetime = datetime.now(), duration: int = 86400, depth: int = 1, forbidden_uris: Optional[Sequence[str]] = None, data_freshness: str = "realtime", disable_geojson: bool = False, direction_type: str = "all") -> Tuple[Sequence[Arrival], Pagination]
23
+ Retrieves a list of arrivals for a specific region and resource path.
24
+
25
+ list_arrivals_by_coordinates(region_lon: float, region_lat: float, lon: float, lat: float, from_datetime: datetime = datetime.now(), duration: int = 86400, depth: int = 1, forbidden_uris: Optional[Sequence[str]] = None, data_freshness: str = "realtime", disable_geojson: bool = False, direction_type: str = "all") -> Tuple[Sequence[Arrival], Pagination]
26
+ Retrieves a list of arrivals for specific coordinates.
27
+ """
28
+
29
+ @staticmethod
30
+ def _get_arrival_objects_from_response(
31
+ response: Any,
32
+ ) -> Sequence[Arrival]:
33
+ """
34
+ Converts raw response data into a list of Arrival objects.
35
+
36
+ Parameters
37
+ ----------
38
+ response : Any
39
+ The raw response data from the API containing arrivals' information.
40
+
41
+ Returns
42
+ -------
43
+ Sequence[Arrival]
44
+ A list of Arrival objects created from the raw response data.
45
+ """
46
+
47
+ arrivals = []
48
+ for arrival_data in response:
49
+ arrivals.append(Arrival.from_payload(arrival_data))
50
+
51
+ return arrivals
52
+
53
+ def _get_arrivals(
54
+ self, url: str, filters: dict
55
+ ) -> Tuple[Sequence[Arrival], Pagination]:
56
+ """
57
+ Internal method to fetch departures based on a given URL and filters.
58
+
59
+ Parameters
60
+ ----------
61
+ url : str
62
+ The URL for the API request.
63
+ filters : dict
64
+ The filters to apply to the API request.
65
+
66
+ Returns
67
+ -------
68
+ Tuple[Sequence[Arrival], Pagination]
69
+ A tuple containing a list of Arrival objects and a Pagination object for managing result pages.
70
+ """
71
+ results = self.get_navitia_api(url + self._generate_filter_query(filters))
72
+ raw_results = results.json()["arrivals"]
73
+ pagination = Pagination.from_payload(results.json()["pagination"])
74
+ return self._get_arrival_objects_from_response(raw_results), pagination
75
+
76
+ def list_arrivals_by_region_id_and_path(
77
+ self,
78
+ region_id: str,
79
+ resource_path: str,
80
+ from_datetime: datetime = datetime.now(),
81
+ duration: int = 86400,
82
+ depth: int = 1,
83
+ forbidden_uris: Optional[Sequence[str]] = None,
84
+ data_freshness: str = "realtime",
85
+ disable_geojson: bool = False,
86
+ direction_type: str = "all",
87
+ ) -> Tuple[Sequence[Arrival], Pagination]:
88
+ """
89
+ Retrieves a list of arrivals for a specific region and resource path.
90
+
91
+ Parameters
92
+ ----------
93
+ region_id : str
94
+ The identifier of the region to fetch arrivals from.
95
+ resource_path : str
96
+ The resource path within the region to fetch arrivals for.
97
+ from_datetime : datetime, optional
98
+ The starting datetime for fetching arrivals (default is current datetime).
99
+ duration : int, optional
100
+ The duration in seconds for which to fetch arrivals (default is 86400 seconds).
101
+ depth : int, optional
102
+ The depth of the search (default is 1).
103
+ forbidden_uris : Optional[Sequence[str]], optional
104
+ A list of URIs to exclude from the search (default is None).
105
+ data_freshness : str, optional
106
+ The freshness of the data to fetch, either "realtime" or "base_schedule" (default is "realtime").
107
+ disable_geojson : bool, optional
108
+ Whether to disable geoJSON in the response (default is False).
109
+ direction_type : str, optional
110
+ The direction type of the arrivals to fetch, e.g., "all", "forward", "backward" (default is "all").
111
+
112
+ Returns
113
+ -------
114
+ Tuple[Sequence[Arrival], Pagination]
115
+ A tuple containing a list of Arrival objects and a Pagination object for managing result pages.
116
+ """
117
+ request_url = f"{self.base_navitia_url}/coverage/{region_id}/{resource_path}/terminus_schedules"
118
+
119
+ filters = {
120
+ "from_datetime": from_datetime,
121
+ "duration": duration,
122
+ "depth": depth,
123
+ "disable_geojson": disable_geojson,
124
+ "forbidden_uris[]": forbidden_uris,
125
+ "data_freshness": data_freshness,
126
+ "direction_type": direction_type,
127
+ }
128
+
129
+ return self._get_arrivals(request_url, filters)
130
+
131
+ def list_arrivals_by_coordinates(
132
+ self,
133
+ region_lon: float,
134
+ region_lat: float,
135
+ lon: float,
136
+ lat: float,
137
+ from_datetime: datetime = datetime.now(),
138
+ duration: int = 86400,
139
+ depth: int = 1,
140
+ forbidden_uris: Optional[Sequence[str]] = None,
141
+ data_freshness: str = "realtime",
142
+ disable_geojson: bool = False,
143
+ direction_type: str = "all",
144
+ ) -> Tuple[Sequence[Arrival], Pagination]:
145
+ """
146
+ Retrieves a list of arrivals for specific coordinates.
147
+
148
+ Parameters
149
+ ----------
150
+ region_lon : float
151
+ The longitude of the region to fetch arrivals from.
152
+ region_lat : float
153
+ The latitude of the region to fetch arrivals from.
154
+ lon : float
155
+ The longitude of the specific location to fetch arrivals for.
156
+ lat : float
157
+ The latitude of the specific location to fetch arrivals for.
158
+ from_datetime : datetime, optional
159
+ The starting datetime for fetching arrivals (default is current datetime).
160
+ duration : int, optional
161
+ The duration in seconds for which to fetch arrivals (default is 86400 seconds).
162
+ depth : int, optional
163
+ The depth of the search (default is 1).
164
+ forbidden_uris : Optional[Sequence[str]], optional
165
+ A list of URIs to exclude from the search (default is None).
166
+ data_freshness : str, optional
167
+ The freshness of the data to fetch, either "realtime" or "base_schedule" (default is "realtime").
168
+ disable_geojson : bool, optional
169
+ Whether to disable geoJSON in the response (default is False).
170
+ direction_type : str, optional
171
+ The direction type of the arrivals to fetch, e.g., "all", "forward", "backward" (default is "all").
172
+
173
+ Returns
174
+ -------
175
+ Tuple[Sequence[Arrival], Pagination]
176
+ A tuple containing a list of Arrival objects and a Pagination object for managing result pages.
177
+ """
178
+ # List of objects near the resource, navitia guesses the region from coordinates
179
+ request_url = f"{self.base_navitia_url}/coverage/{region_lon};{region_lat}/coords/{lon};{lat}/terminus_schedules"
180
+
181
+ filters = {
182
+ "from_datetime": from_datetime,
183
+ "duration": duration,
184
+ "depth": depth,
185
+ "disable_geojson": disable_geojson,
186
+ "forbidden_uris[]": forbidden_uris,
187
+ "data_freshness": data_freshness,
188
+ "direction_type": direction_type,
189
+ }
190
+
191
+ return self._get_arrivals(request_url, filters)
@@ -0,0 +1,107 @@
1
+ from typing import Any, Sequence, Tuple
2
+
3
+ from navitia_client.client.apis.api_base_client import ApiBaseClient
4
+ from navitia_client.entities.contributor import Contributor
5
+ from navitia_client.entities.pagination import Pagination
6
+
7
+
8
+ class ContributorsApiClient(ApiBaseClient):
9
+ """
10
+ A client class to interact with the Navitia API for fetching contributors APIs.
11
+
12
+ See https://doc.navitia.io/#contributors
13
+
14
+ Methods
15
+ -------
16
+ _get_contributors_from_response(raw_contributors_response: Any) -> Sequence[Contributor]
17
+ A static method to transform raw API response data into a list of Contributor objects.
18
+
19
+ list_contributors(region_id: str, start_page: int = 0, count: int = 25) -> Tuple[Sequence[Contributor], Pagination]
20
+ Retrieves a list of contributors for a specified region from the Navitia API.
21
+
22
+ get_contributor_on_dataset(region_id: str, dataset_id: str, start_page: int = 0, count: int = 25) -> Tuple[Sequence[Contributor], Pagination]
23
+ Retrieves a list of contributors for a specified dataset in a region from the Navitia API.
24
+ """
25
+
26
+ @staticmethod
27
+ def _get_contributors_from_response(
28
+ raw_contributors_response: Any,
29
+ ) -> Sequence[Contributor]:
30
+ """
31
+ Converts raw response data into a list of Contributor objects.
32
+
33
+ Parameters
34
+ ----------
35
+ raw_contributors_response : Any
36
+ The raw response data from the API containing contributors' information.
37
+
38
+ Returns
39
+ -------
40
+ Sequence[Contributor]
41
+ A list of Contributor objects created from the raw response data.
42
+ """
43
+ contributors = []
44
+ for contributor_data in raw_contributors_response:
45
+ contributors.append(Contributor.from_payload(contributor_data))
46
+
47
+ return contributors
48
+
49
+ def list_contributors(
50
+ self, region_id: str, start_page: int = 0, count: int = 25
51
+ ) -> Tuple[Sequence[Contributor], Pagination]:
52
+ """
53
+ Retrieves a list of contributors for a specific region.
54
+
55
+ Parameters
56
+ ----------
57
+ region_id : str
58
+ The identifier of the region to fetch contributors from.
59
+ start_page : int, optional
60
+ The starting page for pagination (default is 0).
61
+ count : int, optional
62
+ The number of contributors to fetch per page (default is 25).
63
+
64
+ Returns
65
+ -------
66
+ Tuple[Sequence[Contributor], Pagination]
67
+ A tuple containing a list of Contributor objects and a Pagination object for managing result pages.
68
+ """
69
+ results = self.get_navitia_api(
70
+ f"{self.base_navitia_url}/coverage/{region_id}/contributors?start_page={start_page}&count={count}"
71
+ )
72
+ raw_results = results.json()["contributors"]
73
+ pagination = Pagination.from_payload(results.json()["pagination"])
74
+ return ContributorsApiClient._get_contributors_from_response(
75
+ raw_results
76
+ ), pagination
77
+
78
+ def get_contributor_on_dataset(
79
+ self, region_id: str, dataset_id: str, start_page: int = 0, count: int = 25
80
+ ) -> Tuple[Sequence[Contributor], Pagination]:
81
+ """
82
+ Retrieves a list of contributors for a specific dataset in a region.
83
+
84
+ Parameters
85
+ ----------
86
+ region_id : str
87
+ The identifier of the region to fetch contributors from.
88
+ dataset_id : str
89
+ The identifier of the dataset to fetch contributors for.
90
+ start_page : int, optional
91
+ The starting page for pagination (default is 0).
92
+ count : int, optional
93
+ The number of contributors to fetch per page (default is 25).
94
+
95
+ Returns
96
+ -------
97
+ Tuple[Sequence[Contributor], Pagination]
98
+ A tuple containing a list of Contributor objects and a Pagination object for managing result pages.
99
+ """
100
+ results = self.get_navitia_api(
101
+ f"{self.base_navitia_url}/coverage/{region_id}/contributors/{dataset_id}?start_page={start_page}&count={count}"
102
+ )
103
+ raw_results = results.json()["contributors"]
104
+ pagination = Pagination.from_payload(results.json()["pagination"])
105
+ return ContributorsApiClient._get_contributors_from_response(
106
+ raw_results
107
+ ), pagination
@@ -0,0 +1,131 @@
1
+ from typing import Any, Sequence, Tuple
2
+
3
+ from navitia_client.client.apis.api_base_client import ApiBaseClient
4
+ from navitia_client.entities.administrative_region import Region
5
+ from navitia_client.entities.pagination import Pagination
6
+
7
+
8
+ class CoverageApiClient(ApiBaseClient):
9
+ """
10
+ A client class to interact with the Navitia API for fetching coverage area information.
11
+
12
+ See https://doc.navitia.io/#coverage
13
+
14
+ Methods
15
+ -------
16
+ _get_regions_from_response(raw_regions_response: Any) -> Sequence[Region]
17
+ A static method to transform raw API response data into a list of Region objects.
18
+
19
+ list_covered_areas(start_page: int = 0, count: int = 25) -> Tuple[Sequence[Region], Pagination]
20
+ Retrieves a list of covered areas from the Navitia API.
21
+
22
+ get_coverage_by_region_id(region_id: str, start_page: int = 0, count: int = 25) -> Tuple[Sequence[Region], Pagination]
23
+ Retrieves information about a specific region by its ID.
24
+
25
+ get_coverage_by_region_coordinates_and_coordinates(lon: float, lat: float, start_page: int = 0, count: int = 25) -> Tuple[Sequence[Region], Pagination]
26
+ Retrieves information about a region based on coordinates.
27
+ """
28
+
29
+ @staticmethod
30
+ def _get_regions_from_response(raw_regions_response: Any) -> Sequence[Region]:
31
+ """
32
+ Converts raw response data into a list of Region objects.
33
+
34
+ Parameters
35
+ ----------
36
+ raw_regions_response : Any
37
+ The raw response data from the API containing regions' information.
38
+
39
+ Returns
40
+ -------
41
+ Sequence[Region]
42
+ A list of Region objects created from the raw response data.
43
+ """
44
+ regions = []
45
+ for region_data in raw_regions_response:
46
+ regions.append(Region.from_payload(region_data))
47
+ return regions
48
+
49
+ def list_covered_areas(
50
+ self, start_page: int = 0, count: int = 25
51
+ ) -> Tuple[Sequence[Region], Pagination]:
52
+ """
53
+ Retrieves a list of covered areas from the Navitia API.
54
+
55
+ Parameters
56
+ ----------
57
+ start_page : int, optional
58
+ The starting page for pagination (default is 0).
59
+ count : int, optional
60
+ The number of regions to fetch per page (default is 25).
61
+
62
+ Returns
63
+ -------
64
+ Tuple[Sequence[Region], Pagination]
65
+ A tuple containing a list of Region objects and a Pagination object for managing result pages.
66
+ """
67
+ results = self.get_navitia_api(
68
+ f"{self.base_navitia_url}/coverage?start_page={start_page}&count={count}"
69
+ )
70
+ result_regions = results.json()["regions"]
71
+ regions = CoverageApiClient._get_regions_from_response(result_regions)
72
+ pagination = Pagination.from_payload(results.json()["pagination"])
73
+ return regions, pagination
74
+
75
+ def get_coverage_by_region_id(
76
+ self, region_id: str, start_page: int = 0, count: int = 25
77
+ ) -> Tuple[Sequence[Region], Pagination]:
78
+ """
79
+ Retrieves information about a specific region by its ID.
80
+
81
+ Parameters
82
+ ----------
83
+ region_id : str
84
+ The identifier of the region to fetch information about.
85
+ start_page : int, optional
86
+ The starting page for pagination (default is 0).
87
+ count : int, optional
88
+ The number of regions to fetch per page (default is 25).
89
+
90
+ Returns
91
+ -------
92
+ Tuple[Sequence[Region], Pagination]
93
+ A tuple containing a list of Region objects and a Pagination object for managing result pages.
94
+ """
95
+ results = self.get_navitia_api(
96
+ f"{self.base_navitia_url}/coverage/{region_id}?start_page={start_page}&count={count}"
97
+ )
98
+ result_regions = results.json()["regions"]
99
+ regions = CoverageApiClient._get_regions_from_response(result_regions)
100
+ pagination = Pagination.from_payload(results.json()["pagination"])
101
+ return regions, pagination
102
+
103
+ def get_coverage_by_region_coordinates_and_coordinates(
104
+ self, lon: float, lat: float, start_page: int = 0, count: int = 25
105
+ ) -> Tuple[Sequence[Region], Pagination]:
106
+ """
107
+ Retrieves information about a region based on coordinates.
108
+
109
+ Parameters
110
+ ----------
111
+ lon : float
112
+ The longitude of the location to fetch information about.
113
+ lat : float
114
+ The latitude of the location to fetch information about.
115
+ start_page : int, optional
116
+ The starting page for pagination (default is 0).
117
+ count : int, optional
118
+ The number of regions to fetch per page (default is 25).
119
+
120
+ Returns
121
+ -------
122
+ Tuple[Sequence[Region], Pagination]
123
+ A tuple containing a list of Region objects and a Pagination object for managing result pages.
124
+ """
125
+ results = self.get_navitia_api(
126
+ f"{self.base_navitia_url}/coverage/{lon};{lat}?start_page={start_page}&count={count}"
127
+ )
128
+ result_regions = results.json()["regions"]
129
+ regions = CoverageApiClient._get_regions_from_response(result_regions)
130
+ pagination = Pagination.from_payload(results.json()["pagination"])
131
+ return regions, pagination
@@ -0,0 +1,105 @@
1
+ from typing import Any, Sequence, Tuple
2
+
3
+ from navitia_client.client.apis.api_base_client import ApiBaseClient
4
+ from navitia_client.entities.dataset import Dataset
5
+ from navitia_client.entities.pagination import Pagination
6
+
7
+
8
+ class DatasetsApiClient(ApiBaseClient):
9
+ """
10
+ A client class to interact with the Navitia API for fetching dataset information.
11
+
12
+ See https://doc.navitia.io/#datasets
13
+
14
+ Methods
15
+ -------
16
+ _get_datasets_from_response(raw_datasets_response: Any) -> Sequence[Dataset]
17
+ A static method to transform raw API response data into a list of Dataset objects.
18
+
19
+ list_datasets(region_id: str, start_page: int = 0, count: int = 25) -> Tuple[Sequence[Dataset], Pagination]
20
+ Retrieves a list of datasets for a specified region from the Navitia API.
21
+
22
+ get_dataset_by_id(region_id: str, dataset_id: str, start_page: int = 0, count: int = 25) -> Tuple[Sequence[Dataset], Pagination]
23
+ Retrieves information about a specific dataset by its ID within a region.
24
+ """
25
+
26
+ @staticmethod
27
+ def _get_datasets_from_response(raw_datasets_response: Any) -> Sequence[Dataset]:
28
+ """
29
+ Converts raw response data into a list of Dataset objects.
30
+
31
+ Parameters
32
+ ----------
33
+ raw_datasets_response : Any
34
+ The raw response data from the API containing datasets' information.
35
+
36
+ Returns
37
+ -------
38
+ Sequence[Dataset]
39
+ A list of Dataset objects created from the raw response data.
40
+ """
41
+ datasets = []
42
+ for dataset in raw_datasets_response:
43
+ dataset_contributor = dataset.get("contributor")
44
+ if not dataset_contributor:
45
+ continue
46
+
47
+ datasets.append(Dataset.from_payload(dataset))
48
+
49
+ return datasets
50
+
51
+ def list_datasets(
52
+ self, region_id: str, start_page: int = 0, count: int = 25
53
+ ) -> Tuple[Sequence[Dataset], Pagination]:
54
+ """
55
+ Retrieves a list of datasets for a specified region from the Navitia API.
56
+
57
+ Parameters
58
+ ----------
59
+ region_id : str
60
+ The identifier of the region to fetch datasets from.
61
+ start_page : int, optional
62
+ The starting page for pagination (default is 0).
63
+ count : int, optional
64
+ The number of datasets to fetch per page (default is 25).
65
+
66
+ Returns
67
+ -------
68
+ Tuple[Sequence[Dataset], Pagination]
69
+ A tuple containing a list of Dataset objects and a Pagination object for managing result pages.
70
+ """
71
+ results = self.get_navitia_api(
72
+ f"{self.base_navitia_url}/coverage/{region_id}/datasets?start_page={start_page}&count={count}"
73
+ )
74
+ raw_results = results.json()["datasets"]
75
+ pagination = Pagination.from_payload(results.json()["pagination"])
76
+ return DatasetsApiClient._get_datasets_from_response(raw_results), pagination
77
+
78
+ def get_dataset_by_id(
79
+ self, region_id: str, dataset_id: str, start_page: int = 0, count: int = 25
80
+ ) -> Tuple[Sequence[Dataset], Pagination]:
81
+ """
82
+ Retrieves information about a specific dataset by its ID within a region.
83
+
84
+ Parameters
85
+ ----------
86
+ region_id : str
87
+ The identifier of the region to fetch the dataset from.
88
+ dataset_id : str
89
+ The identifier of the dataset to fetch.
90
+ start_page : int, optional
91
+ The starting page for pagination (default is 0).
92
+ count : int, optional
93
+ The number of datasets to fetch per page (default is 25).
94
+
95
+ Returns
96
+ -------
97
+ Tuple[Sequence[Dataset], Pagination]
98
+ A tuple containing a list of Dataset objects and a Pagination object for managing result pages.
99
+ """
100
+ results = self.get_navitia_api(
101
+ f"{self.base_navitia_url}/coverage/{region_id}/datasets/{dataset_id}?start_page={start_page}&count={count}"
102
+ )
103
+ raw_results = results.json()["datasets"]
104
+ pagination = Pagination.from_payload(results.json()["pagination"])
105
+ return DatasetsApiClient._get_datasets_from_response(raw_results), pagination