python-navitia-client 1.1.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 (89) hide show
  1. python_navitia_client-1.1.0/LICENSE +21 -0
  2. python_navitia_client-1.1.0/PKG-INFO +114 -0
  3. python_navitia_client-1.1.0/README.md +99 -0
  4. python_navitia_client-1.1.0/navitia_client/__init__.py +0 -0
  5. python_navitia_client-1.1.0/navitia_client/client/__init__.py +0 -0
  6. python_navitia_client-1.1.0/navitia_client/client/apis/__init__.py +0 -0
  7. python_navitia_client-1.1.0/navitia_client/client/apis/api_base_client.py +50 -0
  8. python_navitia_client-1.1.0/navitia_client/client/apis/arrival_apis.py +191 -0
  9. python_navitia_client-1.1.0/navitia_client/client/apis/contributors_apis.py +107 -0
  10. python_navitia_client-1.1.0/navitia_client/client/apis/coverage_apis.py +131 -0
  11. python_navitia_client-1.1.0/navitia_client/client/apis/datasets_apis.py +105 -0
  12. python_navitia_client-1.1.0/navitia_client/client/apis/departure_apis.py +211 -0
  13. python_navitia_client-1.1.0/navitia_client/client/apis/inverted_geocoding_apis.py +199 -0
  14. python_navitia_client-1.1.0/navitia_client/client/apis/isochrone_apis.py +196 -0
  15. python_navitia_client-1.1.0/navitia_client/client/apis/journeys_apis.py +629 -0
  16. python_navitia_client-1.1.0/navitia_client/client/apis/line_report_apis.py +106 -0
  17. python_navitia_client-1.1.0/navitia_client/client/apis/place_apis.py +74 -0
  18. python_navitia_client-1.1.0/navitia_client/client/apis/places_nearby_apis.py +354 -0
  19. python_navitia_client-1.1.0/navitia_client/client/apis/public_transport_objects_apis.py +88 -0
  20. python_navitia_client-1.1.0/navitia_client/client/apis/public_transportation_apis/__init__.py +10 -0
  21. python_navitia_client-1.1.0/navitia_client/client/apis/public_transportation_apis/commercial_mode_apis.py +251 -0
  22. python_navitia_client-1.1.0/navitia_client/client/apis/public_transportation_apis/company_apis.py +303 -0
  23. python_navitia_client-1.1.0/navitia_client/client/apis/public_transportation_apis/disruption_apis.py +305 -0
  24. python_navitia_client-1.1.0/navitia_client/client/apis/public_transportation_apis/entity_apis.py +330 -0
  25. python_navitia_client-1.1.0/navitia_client/client/apis/public_transportation_apis/line_apis.py +303 -0
  26. python_navitia_client-1.1.0/navitia_client/client/apis/public_transportation_apis/network_apis.py +303 -0
  27. python_navitia_client-1.1.0/navitia_client/client/apis/public_transportation_apis/physical_mode_apis.py +303 -0
  28. python_navitia_client-1.1.0/navitia_client/client/apis/public_transportation_apis/route_apis.py +303 -0
  29. python_navitia_client-1.1.0/navitia_client/client/apis/public_transportation_apis/stop_area_apis.py +303 -0
  30. python_navitia_client-1.1.0/navitia_client/client/apis/public_transportation_apis/stop_point_apis.py +303 -0
  31. python_navitia_client-1.1.0/navitia_client/client/apis/public_transportation_apis/vehicle_journey_apis.py +304 -0
  32. python_navitia_client-1.1.0/navitia_client/client/apis/route_schedules_apis.py +177 -0
  33. python_navitia_client-1.1.0/navitia_client/client/apis/stop_schedules_apis.py +181 -0
  34. python_navitia_client-1.1.0/navitia_client/client/apis/terminus_schedules_apis.py +186 -0
  35. python_navitia_client-1.1.0/navitia_client/client/apis/traffic_report_apis.py +106 -0
  36. python_navitia_client-1.1.0/navitia_client/client/exceptions.py +18 -0
  37. python_navitia_client-1.1.0/navitia_client/client/navitia_client.py +302 -0
  38. python_navitia_client-1.1.0/navitia_client/client/raw/__init__.py +0 -0
  39. python_navitia_client-1.1.0/navitia_client/client/raw/raw_client.py +58 -0
  40. python_navitia_client-1.1.0/navitia_client/entities/__init__.py +23 -0
  41. python_navitia_client-1.1.0/navitia_client/entities/access_point.py +10 -0
  42. python_navitia_client-1.1.0/navitia_client/entities/address.py +28 -0
  43. python_navitia_client-1.1.0/navitia_client/entities/administrative_region.py +59 -0
  44. python_navitia_client-1.1.0/navitia_client/entities/arrival.py +21 -0
  45. python_navitia_client-1.1.0/navitia_client/entities/base_entity.py +7 -0
  46. python_navitia_client-1.1.0/navitia_client/entities/company.py +16 -0
  47. python_navitia_client-1.1.0/navitia_client/entities/context.py +10 -0
  48. python_navitia_client-1.1.0/navitia_client/entities/contributor.py +19 -0
  49. python_navitia_client-1.1.0/navitia_client/entities/coord.py +15 -0
  50. python_navitia_client-1.1.0/navitia_client/entities/dataset.py +32 -0
  51. python_navitia_client-1.1.0/navitia_client/entities/departure.py +21 -0
  52. python_navitia_client-1.1.0/navitia_client/entities/direction.py +24 -0
  53. python_navitia_client-1.1.0/navitia_client/entities/display_information.py +43 -0
  54. python_navitia_client-1.1.0/navitia_client/entities/disruption.py +233 -0
  55. python_navitia_client-1.1.0/navitia_client/entities/equipment.py +42 -0
  56. python_navitia_client-1.1.0/navitia_client/entities/equipment_reports.py +10 -0
  57. python_navitia_client-1.1.0/navitia_client/entities/isochrones.py +30 -0
  58. python_navitia_client-1.1.0/navitia_client/entities/journey.py +133 -0
  59. python_navitia_client-1.1.0/navitia_client/entities/line_and_route.py +76 -0
  60. python_navitia_client-1.1.0/navitia_client/entities/line_report.py +18 -0
  61. python_navitia_client-1.1.0/navitia_client/entities/link.py +44 -0
  62. python_navitia_client-1.1.0/navitia_client/entities/network.py +16 -0
  63. python_navitia_client-1.1.0/navitia_client/entities/note.py +7 -0
  64. python_navitia_client-1.1.0/navitia_client/entities/pagination.py +19 -0
  65. python_navitia_client-1.1.0/navitia_client/entities/path.py +30 -0
  66. python_navitia_client-1.1.0/navitia_client/entities/pathway.py +11 -0
  67. python_navitia_client-1.1.0/navitia_client/entities/physical_mode.py +92 -0
  68. python_navitia_client-1.1.0/navitia_client/entities/place.py +40 -0
  69. python_navitia_client-1.1.0/navitia_client/entities/poi.py +16 -0
  70. python_navitia_client-1.1.0/navitia_client/entities/pt_datetime.py +31 -0
  71. python_navitia_client-1.1.0/navitia_client/entities/pt_object.py +57 -0
  72. python_navitia_client-1.1.0/navitia_client/entities/route_schedule.py +19 -0
  73. python_navitia_client-1.1.0/navitia_client/entities/schedule_table.py +59 -0
  74. python_navitia_client-1.1.0/navitia_client/entities/stand.py +16 -0
  75. python_navitia_client-1.1.0/navitia_client/entities/stop_area.py +82 -0
  76. python_navitia_client-1.1.0/navitia_client/entities/stop_datetime.py +39 -0
  77. python_navitia_client-1.1.0/navitia_client/entities/stop_schedule.py +59 -0
  78. python_navitia_client-1.1.0/navitia_client/entities/ticket.py +49 -0
  79. python_navitia_client-1.1.0/navitia_client/entities/traffic_report.py +21 -0
  80. python_navitia_client-1.1.0/navitia_client/entities/trip.py +13 -0
  81. python_navitia_client-1.1.0/navitia_client/entities/vehicle_journey.py +163 -0
  82. python_navitia_client-1.1.0/pyproject.toml +28 -0
  83. python_navitia_client-1.1.0/python_navitia_client.egg-info/PKG-INFO +114 -0
  84. python_navitia_client-1.1.0/python_navitia_client.egg-info/SOURCES.txt +87 -0
  85. python_navitia_client-1.1.0/python_navitia_client.egg-info/dependency_links.txt +1 -0
  86. python_navitia_client-1.1.0/python_navitia_client.egg-info/requires.txt +1 -0
  87. python_navitia_client-1.1.0/python_navitia_client.egg-info/top_level.txt +1 -0
  88. python_navitia_client-1.1.0/setup.cfg +4 -0
  89. python_navitia_client-1.1.0/tests/test_navitia_client.py +154 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Jonathan Perron
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,114 @@
1
+ Metadata-Version: 2.1
2
+ Name: python-navitia-client
3
+ Version: 1.1.0
4
+ Summary: Python library to use with Navitia APIs
5
+ Author-email: Jonathan Perron <jonathan@perron.bzh>
6
+ License: MIT License
7
+ Project-URL: Source, https://github.com/jonperron/python-navitia-client
8
+ Classifier: Development Status :: 3 - Alpha
9
+ Classifier: Intended Audience :: Developers
10
+ Classifier: Programming Language :: Python :: 3.10
11
+ Requires-Python: >=3.10
12
+ Description-Content-Type: text/markdown
13
+ License-File: LICENSE
14
+ Requires-Dist: requests<3,>=2.31
15
+
16
+ # navitia-client
17
+
18
+ This repository provides a unofficial Python wrapper to use [navitia.io APIs](https://doc.navitia.io).
19
+
20
+ ##  Pre-requisites
21
+
22
+ To use this library, you will need an access token from [navitia.io](https://navitia.io/tarifs/).
23
+
24
+ ##  API support
25
+
26
+ The library supports the following [APIs](https://doc.navitia.io/#api-catalog):
27
+
28
+ | API | Supported ? | Comment |
29
+ | ----------------------------------------- | ----------- | -------------------------------------------- |
30
+ | Coverage | ✅ | |
31
+ | Datasets | ✅ | |
32
+ | Contributors | ✅ | |
33
+ | Inverted geocoding | ✅ | |
34
+ | Public transportation Objects exploration | ✅ | |
35
+ | Autocomplete on Public Transport objects | ✅ | |
36
+ | Autocomplete on geographical objects | ✅ | |
37
+ | Places nearby | ✅ | |
38
+ | Journeys | ✅ | |
39
+ | Isochrones | ✅ | Beta endpoint according to API response |
40
+ | Route Schedules | ✅ | |
41
+ | Stop Schedules | ✅ | |
42
+ | Terminus Schedules | ✅ | |
43
+ | Departures | ✅ | |
44
+ | Arrivals | ✅ | |
45
+ | Line reports | ✅ | Beta endpoint according to API response |
46
+ | Traffic reports | ✅ | Beta endpoint according to API response |
47
+ | Equipment reports | ❌ | Beta service, not available to all providers |
48
+
49
+ ##  Installation
50
+
51
+ The package is not yet available on pip.
52
+
53
+ For development purpose, you can install it using
54
+
55
+ ```bash
56
+ pip install -e .
57
+ ```
58
+
59
+ ## Usage
60
+
61
+ To use this library, you need an authentication token provided by Navitia.io.
62
+
63
+ ### Create client instance
64
+
65
+ Once created, you will create an instance of the NavitiaClient class with the following:
66
+
67
+ ```python
68
+ from navitia_client.client import NavitiaClient
69
+ client = NavitiaClient(auth=<YOUR_TOKEN_HERE>)
70
+ ```
71
+
72
+ A base URL for Navitia IO is hardcoded and provided to NavitiaClient by default. It can be updated using the base_navitia_url parameter.
73
+
74
+ ###  Access APIs data
75
+
76
+ URLs are mapped as property in the class `NavitiaClient`. You can find the mapping [here](docs/api_support/).
77
+
78
+ For example, if you want to have the list of datasets in a given region, use:
79
+
80
+ ```python
81
+ datasets, pagination = client.datasets.list_datasets(region_id=<REGION_ID>)
82
+ ```
83
+
84
+ ### Pagination
85
+
86
+ A couple of APIs are paginated, in particular the public transporations APIs.. In such case, you can navigate in the response using the parameters `start_page` and `count`.
87
+
88
+ An object `Pagination` will be provided by the impacted methods to help you navigatig.
89
+
90
+ ### Tips
91
+
92
+ Few tips on how to use the Navitia APIs are available [here](docs/few_tips.md)
93
+
94
+ ##  Dependencies
95
+
96
+ * Python >= 3.10
97
+ * requests>=2.31
98
+
99
+ Additional dependencies are described in the [pyproject.toml file](pyproject.toml).
100
+
101
+ ##  Contributing
102
+
103
+ You are free to contribute to the repo. Please read [Contributing.md](docs/CONTRIBUTING.md).
104
+
105
+ ##  Additional questions
106
+
107
+ * Are you affiliated with Navitia ?
108
+ No. This is an unofficial wrapper for the Navitia.io APIs.
109
+
110
+ * Is this client asynchronous ?
111
+ No, and it is not planned to. If you want to add async support, feel free to contribute.
112
+
113
+ * Is this client production ready ?
114
+ Yes and no. For my own purpose, it is, but I cannot guarantee that everything will behave well. If you spot a bug, please open an issue in the repo.
@@ -0,0 +1,99 @@
1
+ # navitia-client
2
+
3
+ This repository provides a unofficial Python wrapper to use [navitia.io APIs](https://doc.navitia.io).
4
+
5
+ ##  Pre-requisites
6
+
7
+ To use this library, you will need an access token from [navitia.io](https://navitia.io/tarifs/).
8
+
9
+ ##  API support
10
+
11
+ The library supports the following [APIs](https://doc.navitia.io/#api-catalog):
12
+
13
+ | API | Supported ? | Comment |
14
+ | ----------------------------------------- | ----------- | -------------------------------------------- |
15
+ | Coverage | ✅ | |
16
+ | Datasets | ✅ | |
17
+ | Contributors | ✅ | |
18
+ | Inverted geocoding | ✅ | |
19
+ | Public transportation Objects exploration | ✅ | |
20
+ | Autocomplete on Public Transport objects | ✅ | |
21
+ | Autocomplete on geographical objects | ✅ | |
22
+ | Places nearby | ✅ | |
23
+ | Journeys | ✅ | |
24
+ | Isochrones | ✅ | Beta endpoint according to API response |
25
+ | Route Schedules | ✅ | |
26
+ | Stop Schedules | ✅ | |
27
+ | Terminus Schedules | ✅ | |
28
+ | Departures | ✅ | |
29
+ | Arrivals | ✅ | |
30
+ | Line reports | ✅ | Beta endpoint according to API response |
31
+ | Traffic reports | ✅ | Beta endpoint according to API response |
32
+ | Equipment reports | ❌ | Beta service, not available to all providers |
33
+
34
+ ##  Installation
35
+
36
+ The package is not yet available on pip.
37
+
38
+ For development purpose, you can install it using
39
+
40
+ ```bash
41
+ pip install -e .
42
+ ```
43
+
44
+ ## Usage
45
+
46
+ To use this library, you need an authentication token provided by Navitia.io.
47
+
48
+ ### Create client instance
49
+
50
+ Once created, you will create an instance of the NavitiaClient class with the following:
51
+
52
+ ```python
53
+ from navitia_client.client import NavitiaClient
54
+ client = NavitiaClient(auth=<YOUR_TOKEN_HERE>)
55
+ ```
56
+
57
+ A base URL for Navitia IO is hardcoded and provided to NavitiaClient by default. It can be updated using the base_navitia_url parameter.
58
+
59
+ ###  Access APIs data
60
+
61
+ URLs are mapped as property in the class `NavitiaClient`. You can find the mapping [here](docs/api_support/).
62
+
63
+ For example, if you want to have the list of datasets in a given region, use:
64
+
65
+ ```python
66
+ datasets, pagination = client.datasets.list_datasets(region_id=<REGION_ID>)
67
+ ```
68
+
69
+ ### Pagination
70
+
71
+ A couple of APIs are paginated, in particular the public transporations APIs.. In such case, you can navigate in the response using the parameters `start_page` and `count`.
72
+
73
+ An object `Pagination` will be provided by the impacted methods to help you navigatig.
74
+
75
+ ### Tips
76
+
77
+ Few tips on how to use the Navitia APIs are available [here](docs/few_tips.md)
78
+
79
+ ##  Dependencies
80
+
81
+ * Python >= 3.10
82
+ * requests>=2.31
83
+
84
+ Additional dependencies are described in the [pyproject.toml file](pyproject.toml).
85
+
86
+ ##  Contributing
87
+
88
+ You are free to contribute to the repo. Please read [Contributing.md](docs/CONTRIBUTING.md).
89
+
90
+ ##  Additional questions
91
+
92
+ * Are you affiliated with Navitia ?
93
+ No. This is an unofficial wrapper for the Navitia.io APIs.
94
+
95
+ * Is this client asynchronous ?
96
+ No, and it is not planned to. If you want to add async support, feel free to contribute.
97
+
98
+ * Is this client production ready ?
99
+ Yes and no. For my own purpose, it is, but I cannot guarantee that everything will behave well. If you spot a bug, please open an issue in the repo.
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