autonomize-core 0.1.4__tar.gz → 0.1.6__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: autonomize-core
3
- Version: 0.1.4
3
+ Version: 0.1.6
4
4
  Summary: Autonomize Core contains the unified authentication source to access platform.
5
5
  License: Proprietary
6
6
  Author: Varun Prakash
@@ -19,7 +19,7 @@ Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
19
19
  Classifier: Topic :: Software Development :: Libraries :: Python Modules
20
20
  Classifier: Topic :: Text Processing
21
21
  Classifier: Typing :: Typed
22
- Requires-Dist: httpx (>=0.27.0,<0.28.0)
22
+ Requires-Dist: httpx (>=0.28.1,<0.29.0)
23
23
  Project-URL: Documentation, https://github.com/autonomize-ai/autonomize-core
24
24
  Project-URL: Homepage, https://github.com/autonomize-ai/autonomize-core
25
25
  Project-URL: Repository, https://github.com/autonomize-ai/autonomize-core
@@ -0,0 +1,14 @@
1
+ """
2
+ This module provides the core functionality for the ModelHub SDK.
3
+
4
+ Classes:
5
+ - BaseClient: The base client class for interacting with the ModelHub API.
6
+ - ModelHubException: Custom exception class for ModelHub-related errors.
7
+
8
+ Functions:
9
+ - handle_response: Helper function for handling API responses.
10
+ """
11
+
12
+ from .base_client import BaseClient, ahandle_response, handle_response
13
+
14
+ __all__ = ["BaseClient", "handle_response", "ahandle_response"]
@@ -0,0 +1,480 @@
1
+ """
2
+ This module contains the BaseClient class for handling common HTTP operations
3
+ and token management using a simplified, credential-focused approach.
4
+ """
5
+
6
+ # pylint: disable=C0301
7
+
8
+ import os
9
+ import ssl
10
+ from typing import Any, Dict, Optional
11
+
12
+ import httpx
13
+
14
+ from autonomize.core.credential import ModelhubCredential
15
+ from autonomize.exceptions.core.credentials import (
16
+ ModelHubAPIException,
17
+ ModelHubBadRequestException,
18
+ ModelHubConflictException,
19
+ ModelhubMissingCredentialsException,
20
+ ModelHubResourceNotFoundException,
21
+ ModelhubUnauthorizedException,
22
+ )
23
+ from autonomize.types.core.base_client import VerifySSLTypes
24
+ from autonomize.utils.logger import setup_logger
25
+
26
+ logger = setup_logger(__name__)
27
+
28
+
29
+ class BaseClient:
30
+ """Base client for handling common HTTP operations with ModelhubCredential integration."""
31
+
32
+ def __init__(
33
+ self,
34
+ credential: ModelhubCredential,
35
+ client_id: Optional[str] = None,
36
+ copilot_id: Optional[str] = None,
37
+ timeout: int = 10,
38
+ verify_ssl: VerifySSLTypes = True,
39
+ ):
40
+ """
41
+ Initialize a new instance of the BaseClient class.
42
+
43
+ Args:
44
+ credential (ModelhubCredential): Credential object for token management and base URL.
45
+ client_id (Optional[str]): Client ID for API URL construction.
46
+ Defaults to CLIENT_ID env var if not provided.
47
+ copilot_id (Optional[str]): Copilot ID for API URL construction.
48
+ Defaults to COPILOT_ID env var if not provided.
49
+ timeout (int, optional): Request timeout in seconds. Defaults to 10.
50
+ verify_ssl (VerifySSLTypes): Whether to verify SSL certificates. Defaults to True.
51
+
52
+ Raises:
53
+ ModelhubMissingCredentialsException: If required credential information is missing.
54
+ """
55
+ # Store the credential
56
+ self.credential = credential
57
+
58
+ # Get client and copilot IDs from args or environment
59
+ self.client_id = client_id or os.getenv("CLIENT_ID")
60
+ self.copilot_id = copilot_id or os.getenv("COPILOT_ID")
61
+
62
+ # Other configuration
63
+ self.timeout = timeout
64
+
65
+ # SSL configuration
66
+ self.verify_ssl = verify_ssl
67
+ if isinstance(self.verify_ssl, str):
68
+ if os.path.isdir(self.verify_ssl):
69
+ self.verify_ssl = ssl.create_default_context(capath=self.verify_ssl)
70
+ self.verify_ssl = ssl.create_default_context(cafile=self.verify_ssl) # type: ignore[arg-type]
71
+
72
+ # Create HTTP clients with retry configured
73
+ self.client = self._setup_client()
74
+ self.async_client = self._setup_async_client()
75
+
76
+ # Validate we can construct API URL
77
+ try:
78
+ api_url = self.api_url
79
+ logger.debug("Initializing client with API URL: %s", api_url)
80
+ except Exception as e:
81
+ logger.error("Failed to construct API URL: %s", str(e))
82
+ raise ModelhubMissingCredentialsException(
83
+ "Unable to construct API URL. Ensure ModelhubCredential has a valid modelhub_url."
84
+ ) from e
85
+
86
+ @property
87
+ def api_url(self) -> str:
88
+ """
89
+ Get the complete API URL by combining the base URL with client and copilot IDs.
90
+
91
+ Returns:
92
+ str: The complete API URL.
93
+
94
+ Raises:
95
+ ModelhubMissingCredentialsException: If required IDs are missing.
96
+ """
97
+ # Get the base URL from the credential
98
+ base_url = getattr(self.credential, "_modelhub_url", None)
99
+ if not base_url:
100
+ raise ModelhubMissingCredentialsException(
101
+ "ModelhubCredential must have a valid modelhub_url."
102
+ )
103
+
104
+ # Check if we have client and copilot IDs
105
+ if not self.client_id or not self.copilot_id:
106
+ raise ModelhubMissingCredentialsException(
107
+ "Client ID and Copilot ID are required for API URL construction."
108
+ )
109
+
110
+ # Construct the full API URL
111
+ return (
112
+ f"{base_url}/modelhub/api/v1/client/{self.client_id}/"
113
+ f"copilot/{self.copilot_id}"
114
+ )
115
+
116
+ def _setup_client(self) -> httpx.Client:
117
+ """
118
+ Set up a synchronous HTTPX client with retry configuration.
119
+
120
+ Returns:
121
+ httpx.Client: Configured client object.
122
+ """
123
+ transport = httpx.HTTPTransport(
124
+ retries=3, # Total number of retries
125
+ )
126
+
127
+ return httpx.Client(
128
+ transport=transport,
129
+ timeout=self.timeout,
130
+ follow_redirects=True,
131
+ verify=self.verify_ssl,
132
+ )
133
+
134
+ def _setup_async_client(self) -> httpx.AsyncClient:
135
+ """
136
+ Set up an asynchronous HTTPX client with retry configuration.
137
+
138
+ Returns:
139
+ httpx.AsyncClient: Configured async client object.
140
+ """
141
+ transport = httpx.AsyncHTTPTransport(
142
+ retries=3, # Total number of retries
143
+ )
144
+
145
+ return httpx.AsyncClient(
146
+ transport=transport,
147
+ timeout=self.timeout,
148
+ follow_redirects=True,
149
+ verify=self.verify_ssl,
150
+ )
151
+
152
+ def _get_auth_headers(self) -> Dict[str, str]:
153
+ """
154
+ Get authentication headers using the credential.
155
+
156
+ Returns:
157
+ Dict[str, str]: Headers dictionary with authorization token.
158
+ """
159
+ token = self.credential.get_token()
160
+ return {"Content-Type": "application/json", "Authorization": f"Bearer {token}"}
161
+
162
+ async def _aget_auth_headers(self) -> Dict[str, str]:
163
+ """
164
+ Asynchronously get authentication headers using the credential.
165
+
166
+ Returns:
167
+ Dict[str, str]: Headers dictionary with authorization token.
168
+ """
169
+ token = await self.credential.aget_token()
170
+ return {"Content-Type": "application/json", "Authorization": f"Bearer {token}"}
171
+
172
+ def _handle_error_status(self, response: httpx.Response) -> None:
173
+ """
174
+ Handle common HTTP error status codes.
175
+
176
+ Args:
177
+ response (httpx.Response): The HTTP response.
178
+
179
+ Raises:
180
+ ModelHubResourceNotFoundException: For 404 errors.
181
+ ModelHubBadRequestException: For 400 errors.
182
+ ModelhubUnauthorizedException: For 401/403 errors.
183
+ ModelHubConflictException: For 409 errors.
184
+ ModelHubAPIException: For other HTTP errors.
185
+ """
186
+ if response.status_code == 404:
187
+ raise ModelHubResourceNotFoundException(
188
+ f"Resource not found: {response.url}"
189
+ )
190
+ if response.status_code == 400:
191
+ raise ModelHubBadRequestException(f"Bad request: {response.text}")
192
+ if response.status_code in (401, 403):
193
+ raise ModelhubUnauthorizedException(f"Unauthorized: {response.text}")
194
+ if response.status_code == 409:
195
+ raise ModelHubConflictException(f"Conflict: {response.text}")
196
+ if response.status_code >= 400:
197
+ raise ModelHubAPIException(
198
+ f"API error {response.status_code}: {response.text}"
199
+ )
200
+
201
+ def request(
202
+ self,
203
+ method: str,
204
+ endpoint: str,
205
+ retry_auth: bool = True,
206
+ headers: Optional[Dict[str, str]] = None,
207
+ **kwargs: Any,
208
+ ) -> Dict[str, Any]:
209
+ """
210
+ Send a request with automatic token handling and optional retry.
211
+
212
+ Args:
213
+ method (str): The HTTP method for the request.
214
+ endpoint (str): The endpoint to send the request to.
215
+ retry_auth (bool, optional): Whether to retry on auth failure. Defaults to True.
216
+ headers (Optional[Dict[str, str]], optional): Additional headers. Defaults to None.
217
+ **kwargs: Additional keyword arguments for the request.
218
+
219
+ Returns:
220
+ Dict[str, Any]: The response data.
221
+
222
+ Raises:
223
+ ModelHubResourceNotFoundException: If the resource is not found.
224
+ ModelHubBadRequestException: If the request is invalid.
225
+ ModelhubUnauthorizedException: If unauthorized.
226
+ ModelHubAPIException: For other API errors.
227
+ """
228
+ url = f"{self.api_url}/{endpoint.lstrip('/')}"
229
+ logger.debug("Making %s request to: %s", method, url)
230
+
231
+ # Prepare headers with auth token
232
+ request_headers = headers or {}
233
+ auth_headers = self._get_auth_headers()
234
+
235
+ # If files are being uploaded, don't include Content-Type in auth_headers
236
+ if "files" in kwargs:
237
+ auth_headers = {"Authorization": auth_headers["Authorization"]}
238
+
239
+ merged_headers = {**auth_headers, **request_headers}
240
+
241
+ try:
242
+ # Make the initial request
243
+ response = self.client.request(
244
+ method, url, headers=merged_headers, **kwargs
245
+ )
246
+
247
+ # If we get a 401, retry with a fresh token
248
+ if response.status_code == 401 and retry_auth:
249
+ logger.debug("Received 401, refreshing token and retrying")
250
+ # Force credential to get a new token
251
+ self.credential.reset_token() # Use the proper method instead of direct access
252
+ auth_headers = self._get_auth_headers()
253
+ merged_headers = {**auth_headers, **request_headers}
254
+
255
+ # Retry the request with the new token
256
+ response = self.client.request(
257
+ method, url, headers=merged_headers, **kwargs
258
+ )
259
+
260
+ # If still unauthorized, handle the error
261
+ if response.status_code == 401:
262
+ self._handle_error_status(response)
263
+
264
+ # Handle any error status codes
265
+ if response.status_code >= 400:
266
+ self._handle_error_status(response)
267
+
268
+ # Parse and return the response
269
+ return handle_response(response)
270
+
271
+ except httpx.HTTPError as e:
272
+ logger.error("Request failed: %s", str(e))
273
+ if isinstance(e, httpx.HTTPStatusError):
274
+ self._handle_error_status(e.response)
275
+ raise ModelHubAPIException(f"Request failed: {str(e)}") from e
276
+
277
+ async def arequest(
278
+ self,
279
+ method: str,
280
+ endpoint: str,
281
+ retry_auth: bool = True,
282
+ headers: Optional[Dict[str, str]] = None,
283
+ **kwargs: Any,
284
+ ) -> Dict[str, Any]:
285
+ """
286
+ Send an asynchronous request with automatic token handling and optional retry.
287
+
288
+ Args:
289
+ method (str): The HTTP method for the request.
290
+ endpoint (str): The endpoint to send the request to.
291
+ retry_auth (bool, optional): Whether to retry on auth failure. Defaults to True.
292
+ headers (Optional[Dict[str, str]], optional): Additional headers. Defaults to None.
293
+ **kwargs: Additional keyword arguments for the request.
294
+
295
+ Returns:
296
+ Dict[str, Any]: The response data.
297
+
298
+ Raises:
299
+ ModelHubResourceNotFoundException: If the resource is not found.
300
+ ModelHubBadRequestException: If the request is invalid.
301
+ ModelhubUnauthorizedException: If unauthorized.
302
+ ModelHubAPIException: For other API errors.
303
+ """
304
+ url = f"{self.api_url}/{endpoint.lstrip('/')}"
305
+ logger.debug("Making async %s request to: %s", method, url)
306
+
307
+ # Prepare headers with auth token
308
+ request_headers = headers or {}
309
+ auth_headers = await self._aget_auth_headers()
310
+ merged_headers = {**auth_headers, **request_headers}
311
+
312
+ try:
313
+ # Make the initial request
314
+ response = await self.async_client.request(
315
+ method, url, headers=merged_headers, **kwargs
316
+ )
317
+
318
+ # If we get a 401, retry with a fresh token
319
+ if response.status_code == 401 and retry_auth:
320
+ logger.debug("Received 401, refreshing token and retrying (async)")
321
+ # Force credential to get a new token
322
+ self.credential.reset_token() # Use the proper method instead of direct access
323
+ auth_headers = await self._aget_auth_headers()
324
+ merged_headers = {**auth_headers, **request_headers}
325
+
326
+ # Retry the request with the new token
327
+ response = await self.async_client.request(
328
+ method, url, headers=merged_headers, **kwargs
329
+ )
330
+
331
+ # If still unauthorized, handle the error
332
+ if response.status_code == 401:
333
+ self._handle_error_status(response)
334
+
335
+ # Handle any error status codes
336
+ if response.status_code >= 400:
337
+ self._handle_error_status(response)
338
+
339
+ # Parse and return the response
340
+ return await ahandle_response(response)
341
+
342
+ except httpx.HTTPError as e:
343
+ logger.error("Async request failed: %s", str(e))
344
+ if isinstance(e, httpx.HTTPStatusError):
345
+ self._handle_error_status(e.response)
346
+ raise ModelHubAPIException(f"Request failed: {str(e)}") from e
347
+
348
+ # Convenience methods for common HTTP operations
349
+
350
+ def get(
351
+ self, endpoint: str, params: Optional[Dict[str, Any]] = None, **kwargs: Any
352
+ ) -> Dict[str, Any]:
353
+ """Send a GET request to the specified endpoint."""
354
+ return self.request("GET", endpoint, params=params, **kwargs)
355
+
356
+ def post(
357
+ self,
358
+ endpoint: str,
359
+ json: Optional[Dict[str, Any]] = None,
360
+ data: Optional[Any] = None,
361
+ files: Optional[Dict[str, Any]] = None,
362
+ **kwargs: Any,
363
+ ) -> Dict[str, Any]:
364
+ """Send a POST request to the specified endpoint."""
365
+ return self.request(
366
+ "POST", endpoint, json=json, data=data, files=files, **kwargs
367
+ )
368
+
369
+ def put(
370
+ self, endpoint: str, json: Optional[Dict[str, Any]] = None, **kwargs: Any
371
+ ) -> Dict[str, Any]:
372
+ """Send a PUT request to the specified endpoint."""
373
+ return self.request("PUT", endpoint, json=json, **kwargs)
374
+
375
+ def patch(
376
+ self, endpoint: str, json: Optional[Dict[str, Any]] = None, **kwargs: Any
377
+ ) -> Dict[str, Any]:
378
+ """Send a PATCH request to the specified endpoint."""
379
+ return self.request("PATCH", endpoint, json=json, **kwargs)
380
+
381
+ def delete(self, endpoint: str, **kwargs: Any) -> Dict[str, Any]:
382
+ """Send a DELETE request to the specified endpoint."""
383
+ return self.request("DELETE", endpoint, **kwargs)
384
+
385
+ # Asynchronous convenience methods
386
+
387
+ async def aget(
388
+ self, endpoint: str, params: Optional[Dict[str, Any]] = None, **kwargs: Any
389
+ ) -> Dict[str, Any]:
390
+ """Send an asynchronous GET request to the specified endpoint."""
391
+ return await self.arequest("GET", endpoint, params=params, **kwargs)
392
+
393
+ async def apost(
394
+ self,
395
+ endpoint: str,
396
+ json: Optional[Dict[str, Any]] = None,
397
+ data: Optional[Any] = None,
398
+ files: Optional[Dict[str, Any]] = None,
399
+ **kwargs: Any,
400
+ ) -> Dict[str, Any]:
401
+ """Send an asynchronous POST request to the specified endpoint."""
402
+ return await self.arequest(
403
+ "POST", endpoint, json=json, data=data, files=files, **kwargs
404
+ )
405
+
406
+ async def aput(
407
+ self, endpoint: str, json: Optional[Dict[str, Any]] = None, **kwargs: Any
408
+ ) -> Dict[str, Any]:
409
+ """Send an asynchronous PUT request to the specified endpoint."""
410
+ return await self.arequest("PUT", endpoint, json=json, **kwargs)
411
+
412
+ async def apatch(
413
+ self, endpoint: str, json: Optional[Dict[str, Any]] = None, **kwargs: Any
414
+ ) -> Dict[str, Any]:
415
+ """Send an asynchronous PATCH request to the specified endpoint."""
416
+ return await self.arequest("PATCH", endpoint, json=json, **kwargs)
417
+
418
+ async def adelete(self, endpoint: str, **kwargs: Any) -> Dict[str, Any]:
419
+ """Send an asynchronous DELETE request to the specified endpoint."""
420
+ return await self.arequest("DELETE", endpoint, **kwargs)
421
+
422
+ def close(self) -> None:
423
+ """Close the HTTPX clients when done."""
424
+ self.client.close()
425
+
426
+ async def aclose(self) -> None:
427
+ """Asynchronously close the HTTPX async client when done."""
428
+ await self.async_client.aclose()
429
+
430
+
431
+ def handle_response(response: httpx.Response) -> Dict[str, Any]:
432
+ """
433
+ Synchronously handle the response from an HTTP request.
434
+
435
+ Args:
436
+ response (httpx.Response): The response object from the HTTP request.
437
+
438
+ Returns:
439
+ dict: The JSON response from the HTTP request.
440
+
441
+ Raises:
442
+ httpx.HTTPError: If the HTTP response status code is an error.
443
+ ValueError: If the response is not a valid JSON.
444
+ """
445
+ try:
446
+ response.raise_for_status()
447
+ return response.json()
448
+ except httpx.HTTPError as e:
449
+ logger.error("HTTP error: %s", str(e))
450
+ raise
451
+ except ValueError as e:
452
+ logger.error("Invalid JSON response: %s", str(e))
453
+ raise
454
+
455
+
456
+ async def ahandle_response(response: httpx.Response) -> Dict[str, Any]:
457
+ """
458
+ Asynchronously handles the response from an HTTP request.
459
+
460
+ Args:
461
+ response (httpx.Response): The response object from the HTTP request.
462
+
463
+ Returns:
464
+ dict: The JSON response from the HTTP request.
465
+
466
+ Raises:
467
+ httpx.HTTPError: If the HTTP response status code is an error.
468
+ ValueError: If the response is not a valid JSON.
469
+ """
470
+ try:
471
+ response.raise_for_status()
472
+ # Use sync version for simplicity - httpx.Response.json()
473
+ # is not a coroutine in current versions
474
+ return response.json()
475
+ except httpx.HTTPError as e:
476
+ logger.error("HTTP error: %s", str(e))
477
+ raise
478
+ except ValueError as e:
479
+ logger.error("Invalid JSON response: %s", str(e))
480
+ raise
@@ -1,10 +1,11 @@
1
1
  """ModelhubCredential Implementation"""
2
2
 
3
- # pylint: disable=line-too-long, invalid-name
3
+ # pylint: disable=line-too-long, invalid-name, duplicate-code
4
4
 
5
5
  import base64
6
6
  import json
7
7
  import os
8
+ import ssl
8
9
  import time
9
10
  from typing import Optional
10
11
 
@@ -16,6 +17,7 @@ from autonomize.exceptions.core import (
16
17
  ModelhubTokenRetrievalException,
17
18
  ModelhubUnauthorizedException,
18
19
  )
20
+ from autonomize.types.core.base_client import VerifySSLTypes
19
21
  from autonomize.utils.logger import setup_logger
20
22
 
21
23
  logger = setup_logger(__name__)
@@ -30,7 +32,7 @@ class ModelhubCredential:
30
32
  Example:
31
33
  .. code-block:: python
32
34
 
33
- from autonomize.core import ModelhubCredential
35
+ from autonomize.core.credential import ModelhubCredential
34
36
 
35
37
  # Using modelhub_url (recommended)
36
38
  modelhub_credential = ModelhubCredential(
@@ -52,6 +54,7 @@ class ModelhubCredential:
52
54
  client_secret: Optional[str] = None,
53
55
  token: Optional[str] = None,
54
56
  auth_url: Optional[str] = None, # Kept for backward compatibility
57
+ verify_ssl: VerifySSLTypes = True,
55
58
  ):
56
59
  """
57
60
  Initialize the ModelhubCredential instance.
@@ -62,6 +65,7 @@ class ModelhubCredential:
62
65
  client_secret (Optional[str]): The client secret for authentication.
63
66
  token (Optional[str]): An existing JWT token for authentication.
64
67
  auth_url (Optional[str]): The direct authentication URL (legacy parameter).
68
+ verify_ssl (VerifySSLTypes): Either `True` to use an SSL context with the default CA bundle, False to disable verification, or an instance of `ssl.SSLContext` to use a custom context.
65
69
 
66
70
  Raises:
67
71
  ModelhubMissingCredentialsException: If neither (client_id and client_secret) nor token is provided.
@@ -91,6 +95,13 @@ class ModelhubCredential:
91
95
  # Default URL as a fallback
92
96
  self._auth_url = "https://auth.sprint.autonomize.dev/realms/autonomize/protocol/openid-connect/token"
93
97
 
98
+ # SSL Config
99
+ self.verify_ssl = verify_ssl
100
+ if isinstance(self.verify_ssl, str):
101
+ if os.path.isdir(self.verify_ssl):
102
+ self.verify_ssl = ssl.create_default_context(capath=self.verify_ssl)
103
+ self.verify_ssl = ssl.create_default_context(cafile=self.verify_ssl) # type: ignore[arg-type]
104
+
94
105
  # Validate credentials
95
106
  if self._client_id is None or self._client_secret is None:
96
107
  if self._token is None:
@@ -164,8 +175,7 @@ class ModelhubCredential:
164
175
  "client_id and client_secret must be provided to fetch JWT token."
165
176
  )
166
177
 
167
- # Setting verify=False, so our client doesn't check for SSL certificate.
168
- with httpx.Client(verify=False, timeout=None) as client:
178
+ with httpx.Client(timeout=None, verify=self.verify_ssl) as client:
169
179
  response = client.post(
170
180
  self.auth_url,
171
181
  headers={"Content-Type": "application/x-www-form-urlencoded"},
@@ -219,7 +229,9 @@ class ModelhubCredential:
219
229
  "client_id and client_secret must be provided to fetch JWT token."
220
230
  )
221
231
 
222
- async with httpx.AsyncClient(verify=False, timeout=None) as client:
232
+ async with httpx.AsyncClient(
233
+ timeout=None, verify=self.verify_ssl
234
+ ) as client:
223
235
  response = await client.post(
224
236
  self.auth_url,
225
237
  headers={"Content-Type": "application/x-www-form-urlencoded"},
@@ -0,0 +1,49 @@
1
+ """Exceptions for the modelhub module."""
2
+
3
+
4
+ # Original Exceptions
5
+ class ModelhubCredentialException(Exception):
6
+ """Base exception for ModelhubCredential exceptions."""
7
+
8
+
9
+ class ModelhubMissingCredentialsException(ModelhubCredentialException):
10
+ """Raised when modelhub credentials are not provided."""
11
+
12
+
13
+ class ModelhubInvalidTokenException(ModelhubCredentialException):
14
+ """Raised when an ill-formatted or invalid token is provided."""
15
+
16
+
17
+ class ModelhubTokenRetrievalException(ModelhubCredentialException):
18
+ """Raised when the token could not be retrieved."""
19
+
20
+
21
+ class ModelhubUnauthorizedException(ModelhubCredentialException):
22
+ """Raised when the modelhub credentials are invalid."""
23
+
24
+
25
+ # Base exception for ModelHub client
26
+ class ModelHubException(Exception):
27
+ """Base exception for all ModelHub client exceptions."""
28
+
29
+
30
+ # API exceptions
31
+ class ModelHubAPIException(ModelHubException):
32
+ """Base exception for API-related errors."""
33
+
34
+
35
+ class ModelHubResourceNotFoundException(ModelHubAPIException):
36
+ """Raised when a requested resource is not found."""
37
+
38
+
39
+ class ModelHubBadRequestException(ModelHubAPIException):
40
+ """Raised when the API request is malformed or invalid."""
41
+
42
+
43
+ class ModelHubConflictException(ModelHubAPIException):
44
+ """Raised when there's a conflict with the current state of the resource."""
45
+
46
+
47
+ # Parsing exceptions
48
+ class ModelHubParsingException(ModelHubException):
49
+ """Raised when response parsing fails."""
@@ -0,0 +1,8 @@
1
+ """Core type aliases shared by the client layer."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import ssl
6
+ from typing import TypeAlias, Union
7
+
8
+ VerifySSLTypes: TypeAlias = Union[ssl.SSLContext, str, bool] # pylint: disable=C0103
File without changes
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "autonomize-core"
3
- version = "0.1.4"
3
+ version = "0.1.6"
4
4
  description = "Autonomize Core contains the unified authentication source to access platform."
5
5
  authors = ["Varun Prakash <varun.prakash@autonomize.ai>"]
6
6
  readme = "README.md"
@@ -29,7 +29,7 @@ documentation = "https://github.com/autonomize-ai/autonomize-core"
29
29
 
30
30
  [tool.poetry.dependencies]
31
31
  python = "^3.12"
32
- httpx = ">=0.27.0,<0.28.0"
32
+ httpx = "^0.28.1"
33
33
 
34
34
  [tool.poetry.group.dev]
35
35
  optional = true
@@ -1,21 +0,0 @@
1
- """Exceptions for the modelhub module."""
2
-
3
-
4
- class ModelhubCredentialException(Exception):
5
- """Base exception for ModelhubCredential exceptions."""
6
-
7
-
8
- class ModelhubMissingCredentialsException(ModelhubCredentialException):
9
- """Raised when modelhub credentials are not provided."""
10
-
11
-
12
- class ModelhubInvalidTokenException(ModelhubCredentialException):
13
- """Raised when an ill-formatted or invalid token is provided."""
14
-
15
-
16
- class ModelhubTokenRetrievalException(ModelhubCredentialException):
17
- """Raised when the token could not be retrieved."""
18
-
19
-
20
- class ModelhubUnauthorizedException(ModelhubCredentialException):
21
- """Raised when the modelhub credentials are invalid."""
File without changes