datacosmos 0.0.16__tar.gz → 0.0.17__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.
- {datacosmos-0.0.16 → datacosmos-0.0.17}/PKG-INFO +1 -1
- {datacosmos-0.0.16 → datacosmos-0.0.17}/datacosmos/datacosmos_client.py +43 -2
- {datacosmos-0.0.16 → datacosmos-0.0.17}/datacosmos.egg-info/PKG-INFO +1 -1
- {datacosmos-0.0.16 → datacosmos-0.0.17}/pyproject.toml +1 -1
- {datacosmos-0.0.16 → datacosmos-0.0.17}/LICENSE.md +0 -0
- {datacosmos-0.0.16 → datacosmos-0.0.17}/README.md +0 -0
- {datacosmos-0.0.16 → datacosmos-0.0.17}/datacosmos/__init__.py +0 -0
- {datacosmos-0.0.16 → datacosmos-0.0.17}/datacosmos/auth/__init__.py +0 -0
- {datacosmos-0.0.16 → datacosmos-0.0.17}/datacosmos/auth/base_authenticator.py +0 -0
- {datacosmos-0.0.16 → datacosmos-0.0.17}/datacosmos/auth/local_authenticator.py +0 -0
- {datacosmos-0.0.16 → datacosmos-0.0.17}/datacosmos/auth/local_token_fetcher.py +0 -0
- {datacosmos-0.0.16 → datacosmos-0.0.17}/datacosmos/auth/m2m_authenticator.py +0 -0
- {datacosmos-0.0.16 → datacosmos-0.0.17}/datacosmos/auth/token.py +0 -0
- {datacosmos-0.0.16 → datacosmos-0.0.17}/datacosmos/config/__init__.py +0 -0
- {datacosmos-0.0.16 → datacosmos-0.0.17}/datacosmos/config/auth/__init__.py +0 -0
- {datacosmos-0.0.16 → datacosmos-0.0.17}/datacosmos/config/auth/factory.py +0 -0
- {datacosmos-0.0.16 → datacosmos-0.0.17}/datacosmos/config/config.py +0 -0
- {datacosmos-0.0.16 → datacosmos-0.0.17}/datacosmos/config/constants.py +0 -0
- {datacosmos-0.0.16 → datacosmos-0.0.17}/datacosmos/config/loaders/yaml_source.py +0 -0
- {datacosmos-0.0.16 → datacosmos-0.0.17}/datacosmos/config/models/__init__.py +0 -0
- {datacosmos-0.0.16 → datacosmos-0.0.17}/datacosmos/config/models/authentication_config.py +0 -0
- {datacosmos-0.0.16 → datacosmos-0.0.17}/datacosmos/config/models/local_user_account_authentication_config.py +0 -0
- {datacosmos-0.0.16 → datacosmos-0.0.17}/datacosmos/config/models/m2m_authentication_config.py +0 -0
- {datacosmos-0.0.16 → datacosmos-0.0.17}/datacosmos/config/models/no_authentication_config.py +0 -0
- {datacosmos-0.0.16 → datacosmos-0.0.17}/datacosmos/config/models/url.py +0 -0
- {datacosmos-0.0.16 → datacosmos-0.0.17}/datacosmos/exceptions/__init__.py +0 -0
- {datacosmos-0.0.16 → datacosmos-0.0.17}/datacosmos/exceptions/datacosmos_exception.py +0 -0
- {datacosmos-0.0.16 → datacosmos-0.0.17}/datacosmos/stac/__init__.py +0 -0
- {datacosmos-0.0.16 → datacosmos-0.0.17}/datacosmos/stac/collection/__init__.py +0 -0
- {datacosmos-0.0.16 → datacosmos-0.0.17}/datacosmos/stac/collection/collection_client.py +0 -0
- {datacosmos-0.0.16 → datacosmos-0.0.17}/datacosmos/stac/collection/models/__init__.py +0 -0
- {datacosmos-0.0.16 → datacosmos-0.0.17}/datacosmos/stac/collection/models/collection_update.py +0 -0
- {datacosmos-0.0.16 → datacosmos-0.0.17}/datacosmos/stac/constants/__init__.py +0 -0
- {datacosmos-0.0.16 → datacosmos-0.0.17}/datacosmos/stac/constants/satellite_name_mapping.py +0 -0
- {datacosmos-0.0.16 → datacosmos-0.0.17}/datacosmos/stac/enums/__init__.py +0 -0
- {datacosmos-0.0.16 → datacosmos-0.0.17}/datacosmos/stac/enums/processing_level.py +0 -0
- {datacosmos-0.0.16 → datacosmos-0.0.17}/datacosmos/stac/enums/product_type.py +0 -0
- {datacosmos-0.0.16 → datacosmos-0.0.17}/datacosmos/stac/enums/season.py +0 -0
- {datacosmos-0.0.16 → datacosmos-0.0.17}/datacosmos/stac/item/__init__.py +0 -0
- {datacosmos-0.0.16 → datacosmos-0.0.17}/datacosmos/stac/item/item_client.py +0 -0
- {datacosmos-0.0.16 → datacosmos-0.0.17}/datacosmos/stac/item/models/__init__.py +0 -0
- {datacosmos-0.0.16 → datacosmos-0.0.17}/datacosmos/stac/item/models/asset.py +0 -0
- {datacosmos-0.0.16 → datacosmos-0.0.17}/datacosmos/stac/item/models/catalog_search_parameters.py +0 -0
- {datacosmos-0.0.16 → datacosmos-0.0.17}/datacosmos/stac/item/models/datacosmos_item.py +0 -0
- {datacosmos-0.0.16 → datacosmos-0.0.17}/datacosmos/stac/item/models/eo_band.py +0 -0
- {datacosmos-0.0.16 → datacosmos-0.0.17}/datacosmos/stac/item/models/item_update.py +0 -0
- {datacosmos-0.0.16 → datacosmos-0.0.17}/datacosmos/stac/item/models/raster_band.py +0 -0
- {datacosmos-0.0.16 → datacosmos-0.0.17}/datacosmos/stac/stac_client.py +0 -0
- {datacosmos-0.0.16 → datacosmos-0.0.17}/datacosmos/stac/storage/__init__.py +0 -0
- {datacosmos-0.0.16 → datacosmos-0.0.17}/datacosmos/stac/storage/dataclasses/__init__.py +0 -0
- {datacosmos-0.0.16 → datacosmos-0.0.17}/datacosmos/stac/storage/dataclasses/upload_path.py +0 -0
- {datacosmos-0.0.16 → datacosmos-0.0.17}/datacosmos/stac/storage/storage_base.py +0 -0
- {datacosmos-0.0.16 → datacosmos-0.0.17}/datacosmos/stac/storage/storage_client.py +0 -0
- {datacosmos-0.0.16 → datacosmos-0.0.17}/datacosmos/stac/storage/uploader.py +0 -0
- {datacosmos-0.0.16 → datacosmos-0.0.17}/datacosmos/utils/__init__.py +0 -0
- {datacosmos-0.0.16 → datacosmos-0.0.17}/datacosmos/utils/http_response/__init__.py +0 -0
- {datacosmos-0.0.16 → datacosmos-0.0.17}/datacosmos/utils/http_response/check_api_response.py +0 -0
- {datacosmos-0.0.16 → datacosmos-0.0.17}/datacosmos/utils/http_response/models/__init__.py +0 -0
- {datacosmos-0.0.16 → datacosmos-0.0.17}/datacosmos/utils/http_response/models/datacosmos_error.py +0 -0
- {datacosmos-0.0.16 → datacosmos-0.0.17}/datacosmos/utils/http_response/models/datacosmos_response.py +0 -0
- {datacosmos-0.0.16 → datacosmos-0.0.17}/datacosmos/utils/url.py +0 -0
- {datacosmos-0.0.16 → datacosmos-0.0.17}/datacosmos.egg-info/SOURCES.txt +0 -0
- {datacosmos-0.0.16 → datacosmos-0.0.17}/datacosmos.egg-info/dependency_links.txt +0 -0
- {datacosmos-0.0.16 → datacosmos-0.0.17}/datacosmos.egg-info/requires.txt +0 -0
- {datacosmos-0.0.16 → datacosmos-0.0.17}/datacosmos.egg-info/top_level.txt +0 -0
- {datacosmos-0.0.16 → datacosmos-0.0.17}/setup.cfg +0 -0
- {datacosmos-0.0.16 → datacosmos-0.0.17}/tests/test_pass.py +0 -0
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
"""Client to interact with the Datacosmos API with authentication and request handling."""
|
|
2
2
|
from __future__ import annotations
|
|
3
3
|
|
|
4
|
+
import logging
|
|
4
5
|
import threading
|
|
5
6
|
from datetime import datetime, timedelta, timezone
|
|
6
|
-
from typing import Any, Optional
|
|
7
|
+
from typing import Any, Callable, List, Optional
|
|
7
8
|
|
|
8
9
|
import requests
|
|
9
10
|
from requests.exceptions import ConnectionError, HTTPError, RequestException, Timeout
|
|
@@ -21,6 +22,11 @@ from datacosmos.auth.m2m_authenticator import M2MAuthenticator
|
|
|
21
22
|
from datacosmos.config.config import Config
|
|
22
23
|
from datacosmos.exceptions.datacosmos_exception import DatacosmosException
|
|
23
24
|
|
|
25
|
+
_log = logging.getLogger(__name__)
|
|
26
|
+
|
|
27
|
+
RequestHook = Callable[[str, str, Any, Any], None]
|
|
28
|
+
ResponseHook = Callable[[requests.Response], None]
|
|
29
|
+
|
|
24
30
|
|
|
25
31
|
class DatacosmosClient:
|
|
26
32
|
"""Client to interact with the Datacosmos API with authentication and request handling."""
|
|
@@ -31,18 +37,24 @@ class DatacosmosClient:
|
|
|
31
37
|
self,
|
|
32
38
|
config: Optional[Config | Any] = None,
|
|
33
39
|
http_session: Optional[requests.Session | OAuth2Session] = None,
|
|
40
|
+
request_hooks: Optional[List[RequestHook]] = None,
|
|
41
|
+
response_hooks: Optional[List[ResponseHook]] = None,
|
|
34
42
|
):
|
|
35
43
|
"""Initialize the DatacosmosClient.
|
|
36
44
|
|
|
37
45
|
Args:
|
|
38
46
|
config (Optional[Config]): Configuration object (only needed when SDK creates its own session).
|
|
39
47
|
http_session (Optional[requests.Session]): Pre-authenticated session.
|
|
48
|
+
request_hooks (Optional[List[RequestHook]]): A list of functions to be called before each request.
|
|
49
|
+
response_hooks (Optional[List[ResponseHook]]): A list of functions to be called after each successful response.
|
|
40
50
|
"""
|
|
41
51
|
self.config = self._coerce_config(config)
|
|
42
52
|
self.token: Optional[str] = None
|
|
43
53
|
self.token_expiry: Optional[datetime] = None
|
|
44
54
|
self._refresh_lock = threading.Lock()
|
|
45
55
|
self._authenticator: Optional[BaseAuthenticator] = None
|
|
56
|
+
self._request_hooks = request_hooks or []
|
|
57
|
+
self._response_hooks = response_hooks or []
|
|
46
58
|
|
|
47
59
|
if http_session is not None:
|
|
48
60
|
self._init_with_injected_session(http_session)
|
|
@@ -172,11 +184,40 @@ class DatacosmosClient:
|
|
|
172
184
|
def request(
|
|
173
185
|
self, method: str, url: str, *args: Any, **kwargs: Any
|
|
174
186
|
) -> requests.Response:
|
|
175
|
-
"""Send an HTTP request using the authenticated session (with auto-refresh and retries).
|
|
187
|
+
"""Send an HTTP request using the authenticated session (with auto-refresh and retries).
|
|
188
|
+
|
|
189
|
+
Args:
|
|
190
|
+
method (str): The HTTP method (e.g., "GET", "POST").
|
|
191
|
+
url (str): The URL for the request.
|
|
192
|
+
*args: Positional arguments for requests.request().
|
|
193
|
+
**kwargs: Keyword arguments for requests.request().
|
|
194
|
+
|
|
195
|
+
Returns:
|
|
196
|
+
requests.Response: The HTTP response.
|
|
197
|
+
|
|
198
|
+
Raises:
|
|
199
|
+
DatacosmosException: For any HTTP or request-related errors.
|
|
200
|
+
"""
|
|
176
201
|
self._refresh_token_if_needed()
|
|
202
|
+
|
|
203
|
+
# Call pre-request hooks
|
|
204
|
+
for hook in self._request_hooks:
|
|
205
|
+
try:
|
|
206
|
+
hook(method, url, *args, **kwargs)
|
|
207
|
+
except Exception:
|
|
208
|
+
_log.error("Request hook failed.", exc_info=True)
|
|
209
|
+
|
|
177
210
|
try:
|
|
178
211
|
response = self._http_client.request(method, url, *args, **kwargs)
|
|
179
212
|
response.raise_for_status()
|
|
213
|
+
|
|
214
|
+
# Call post-response hooks on success
|
|
215
|
+
for hook in self._response_hooks:
|
|
216
|
+
try:
|
|
217
|
+
hook(response)
|
|
218
|
+
except Exception:
|
|
219
|
+
_log.error("Response hook failed.", exc_info=True)
|
|
220
|
+
|
|
180
221
|
return response
|
|
181
222
|
except HTTPError as e:
|
|
182
223
|
status = getattr(e.response, "status_code", None)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{datacosmos-0.0.16 → datacosmos-0.0.17}/datacosmos/config/models/m2m_authentication_config.py
RENAMED
|
File without changes
|
{datacosmos-0.0.16 → datacosmos-0.0.17}/datacosmos/config/models/no_authentication_config.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{datacosmos-0.0.16 → datacosmos-0.0.17}/datacosmos/stac/collection/models/collection_update.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{datacosmos-0.0.16 → datacosmos-0.0.17}/datacosmos/stac/item/models/catalog_search_parameters.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{datacosmos-0.0.16 → datacosmos-0.0.17}/datacosmos/utils/http_response/check_api_response.py
RENAMED
|
File without changes
|
|
File without changes
|
{datacosmos-0.0.16 → datacosmos-0.0.17}/datacosmos/utils/http_response/models/datacosmos_error.py
RENAMED
|
File without changes
|
{datacosmos-0.0.16 → datacosmos-0.0.17}/datacosmos/utils/http_response/models/datacosmos_response.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|