compass_api_sdk 0.9.36__py3-none-any.whl → 0.9.37__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.

Potentially problematic release.


This version of compass_api_sdk might be problematic. Click here for more details.

@@ -89,31 +89,20 @@ class ERC4626Vaults(BaseSDK):
89
89
 
90
90
  response_data: Any = None
91
91
  if utils.match_response(http_res, "200", "application/json"):
92
- return utils.unmarshal_json(http_res.text, models.VaultGetVaultResponse)
92
+ return utils.unmarshal_json_response(models.VaultGetVaultResponse, http_res)
93
93
  if utils.match_response(http_res, "422", "application/json"):
94
- response_data = utils.unmarshal_json(
95
- http_res.text, errors.HTTPValidationErrorData
94
+ response_data = utils.unmarshal_json_response(
95
+ errors.HTTPValidationErrorData, http_res
96
96
  )
97
- raise errors.HTTPValidationError(data=response_data)
97
+ raise errors.HTTPValidationError(response_data, http_res)
98
98
  if utils.match_response(http_res, "4XX", "*"):
99
99
  http_res_text = utils.stream_to_text(http_res)
100
- raise errors.APIError(
101
- "API error occurred", http_res.status_code, http_res_text, http_res
102
- )
100
+ raise errors.APIError("API error occurred", http_res, http_res_text)
103
101
  if utils.match_response(http_res, "5XX", "*"):
104
102
  http_res_text = utils.stream_to_text(http_res)
105
- raise errors.APIError(
106
- "API error occurred", http_res.status_code, http_res_text, http_res
107
- )
103
+ raise errors.APIError("API error occurred", http_res, http_res_text)
108
104
 
109
- content_type = http_res.headers.get("Content-Type")
110
- http_res_text = utils.stream_to_text(http_res)
111
- raise errors.APIError(
112
- f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
113
- http_res.status_code,
114
- http_res_text,
115
- http_res,
116
- )
105
+ raise errors.APIError("Unexpected response received", http_res)
117
106
 
118
107
  async def vault_async(
119
108
  self,
@@ -196,31 +185,20 @@ class ERC4626Vaults(BaseSDK):
196
185
 
197
186
  response_data: Any = None
198
187
  if utils.match_response(http_res, "200", "application/json"):
199
- return utils.unmarshal_json(http_res.text, models.VaultGetVaultResponse)
188
+ return utils.unmarshal_json_response(models.VaultGetVaultResponse, http_res)
200
189
  if utils.match_response(http_res, "422", "application/json"):
201
- response_data = utils.unmarshal_json(
202
- http_res.text, errors.HTTPValidationErrorData
190
+ response_data = utils.unmarshal_json_response(
191
+ errors.HTTPValidationErrorData, http_res
203
192
  )
204
- raise errors.HTTPValidationError(data=response_data)
193
+ raise errors.HTTPValidationError(response_data, http_res)
205
194
  if utils.match_response(http_res, "4XX", "*"):
206
195
  http_res_text = await utils.stream_to_text_async(http_res)
207
- raise errors.APIError(
208
- "API error occurred", http_res.status_code, http_res_text, http_res
209
- )
196
+ raise errors.APIError("API error occurred", http_res, http_res_text)
210
197
  if utils.match_response(http_res, "5XX", "*"):
211
198
  http_res_text = await utils.stream_to_text_async(http_res)
212
- raise errors.APIError(
213
- "API error occurred", http_res.status_code, http_res_text, http_res
214
- )
199
+ raise errors.APIError("API error occurred", http_res, http_res_text)
215
200
 
216
- content_type = http_res.headers.get("Content-Type")
217
- http_res_text = await utils.stream_to_text_async(http_res)
218
- raise errors.APIError(
219
- f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
220
- http_res.status_code,
221
- http_res_text,
222
- http_res,
223
- )
201
+ raise errors.APIError("Unexpected response received", http_res)
224
202
 
225
203
  def deposit(
226
204
  self,
@@ -313,31 +291,20 @@ class ERC4626Vaults(BaseSDK):
313
291
 
314
292
  response_data: Any = None
315
293
  if utils.match_response(http_res, "200", "application/json"):
316
- return utils.unmarshal_json(http_res.text, models.TxResponse)
294
+ return utils.unmarshal_json_response(models.TxResponse, http_res)
317
295
  if utils.match_response(http_res, "422", "application/json"):
318
- response_data = utils.unmarshal_json(
319
- http_res.text, errors.HTTPValidationErrorData
296
+ response_data = utils.unmarshal_json_response(
297
+ errors.HTTPValidationErrorData, http_res
320
298
  )
321
- raise errors.HTTPValidationError(data=response_data)
299
+ raise errors.HTTPValidationError(response_data, http_res)
322
300
  if utils.match_response(http_res, "4XX", "*"):
323
301
  http_res_text = utils.stream_to_text(http_res)
324
- raise errors.APIError(
325
- "API error occurred", http_res.status_code, http_res_text, http_res
326
- )
302
+ raise errors.APIError("API error occurred", http_res, http_res_text)
327
303
  if utils.match_response(http_res, "5XX", "*"):
328
304
  http_res_text = utils.stream_to_text(http_res)
329
- raise errors.APIError(
330
- "API error occurred", http_res.status_code, http_res_text, http_res
331
- )
305
+ raise errors.APIError("API error occurred", http_res, http_res_text)
332
306
 
333
- content_type = http_res.headers.get("Content-Type")
334
- http_res_text = utils.stream_to_text(http_res)
335
- raise errors.APIError(
336
- f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
337
- http_res.status_code,
338
- http_res_text,
339
- http_res,
340
- )
307
+ raise errors.APIError("Unexpected response received", http_res)
341
308
 
342
309
  async def deposit_async(
343
310
  self,
@@ -430,31 +397,20 @@ class ERC4626Vaults(BaseSDK):
430
397
 
431
398
  response_data: Any = None
432
399
  if utils.match_response(http_res, "200", "application/json"):
433
- return utils.unmarshal_json(http_res.text, models.TxResponse)
400
+ return utils.unmarshal_json_response(models.TxResponse, http_res)
434
401
  if utils.match_response(http_res, "422", "application/json"):
435
- response_data = utils.unmarshal_json(
436
- http_res.text, errors.HTTPValidationErrorData
402
+ response_data = utils.unmarshal_json_response(
403
+ errors.HTTPValidationErrorData, http_res
437
404
  )
438
- raise errors.HTTPValidationError(data=response_data)
405
+ raise errors.HTTPValidationError(response_data, http_res)
439
406
  if utils.match_response(http_res, "4XX", "*"):
440
407
  http_res_text = await utils.stream_to_text_async(http_res)
441
- raise errors.APIError(
442
- "API error occurred", http_res.status_code, http_res_text, http_res
443
- )
408
+ raise errors.APIError("API error occurred", http_res, http_res_text)
444
409
  if utils.match_response(http_res, "5XX", "*"):
445
410
  http_res_text = await utils.stream_to_text_async(http_res)
446
- raise errors.APIError(
447
- "API error occurred", http_res.status_code, http_res_text, http_res
448
- )
411
+ raise errors.APIError("API error occurred", http_res, http_res_text)
449
412
 
450
- content_type = http_res.headers.get("Content-Type")
451
- http_res_text = await utils.stream_to_text_async(http_res)
452
- raise errors.APIError(
453
- f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
454
- http_res.status_code,
455
- http_res_text,
456
- http_res,
457
- )
413
+ raise errors.APIError("Unexpected response received", http_res)
458
414
 
459
415
  def withdraw(
460
416
  self,
@@ -547,31 +503,20 @@ class ERC4626Vaults(BaseSDK):
547
503
 
548
504
  response_data: Any = None
549
505
  if utils.match_response(http_res, "200", "application/json"):
550
- return utils.unmarshal_json(http_res.text, models.TxResponse)
506
+ return utils.unmarshal_json_response(models.TxResponse, http_res)
551
507
  if utils.match_response(http_res, "422", "application/json"):
552
- response_data = utils.unmarshal_json(
553
- http_res.text, errors.HTTPValidationErrorData
508
+ response_data = utils.unmarshal_json_response(
509
+ errors.HTTPValidationErrorData, http_res
554
510
  )
555
- raise errors.HTTPValidationError(data=response_data)
511
+ raise errors.HTTPValidationError(response_data, http_res)
556
512
  if utils.match_response(http_res, "4XX", "*"):
557
513
  http_res_text = utils.stream_to_text(http_res)
558
- raise errors.APIError(
559
- "API error occurred", http_res.status_code, http_res_text, http_res
560
- )
514
+ raise errors.APIError("API error occurred", http_res, http_res_text)
561
515
  if utils.match_response(http_res, "5XX", "*"):
562
516
  http_res_text = utils.stream_to_text(http_res)
563
- raise errors.APIError(
564
- "API error occurred", http_res.status_code, http_res_text, http_res
565
- )
517
+ raise errors.APIError("API error occurred", http_res, http_res_text)
566
518
 
567
- content_type = http_res.headers.get("Content-Type")
568
- http_res_text = utils.stream_to_text(http_res)
569
- raise errors.APIError(
570
- f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
571
- http_res.status_code,
572
- http_res_text,
573
- http_res,
574
- )
519
+ raise errors.APIError("Unexpected response received", http_res)
575
520
 
576
521
  async def withdraw_async(
577
522
  self,
@@ -664,28 +609,17 @@ class ERC4626Vaults(BaseSDK):
664
609
 
665
610
  response_data: Any = None
666
611
  if utils.match_response(http_res, "200", "application/json"):
667
- return utils.unmarshal_json(http_res.text, models.TxResponse)
612
+ return utils.unmarshal_json_response(models.TxResponse, http_res)
668
613
  if utils.match_response(http_res, "422", "application/json"):
669
- response_data = utils.unmarshal_json(
670
- http_res.text, errors.HTTPValidationErrorData
614
+ response_data = utils.unmarshal_json_response(
615
+ errors.HTTPValidationErrorData, http_res
671
616
  )
672
- raise errors.HTTPValidationError(data=response_data)
617
+ raise errors.HTTPValidationError(response_data, http_res)
673
618
  if utils.match_response(http_res, "4XX", "*"):
674
619
  http_res_text = await utils.stream_to_text_async(http_res)
675
- raise errors.APIError(
676
- "API error occurred", http_res.status_code, http_res_text, http_res
677
- )
620
+ raise errors.APIError("API error occurred", http_res, http_res_text)
678
621
  if utils.match_response(http_res, "5XX", "*"):
679
622
  http_res_text = await utils.stream_to_text_async(http_res)
680
- raise errors.APIError(
681
- "API error occurred", http_res.status_code, http_res_text, http_res
682
- )
623
+ raise errors.APIError("API error occurred", http_res, http_res_text)
683
624
 
684
- content_type = http_res.headers.get("Content-Type")
685
- http_res_text = await utils.stream_to_text_async(http_res)
686
- raise errors.APIError(
687
- f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
688
- http_res.status_code,
689
- http_res_text,
690
- http_res,
691
- )
625
+ raise errors.APIError("Unexpected response received", http_res)
@@ -5,14 +5,27 @@ from importlib import import_module
5
5
 
6
6
  if TYPE_CHECKING:
7
7
  from .apierror import APIError
8
+ from .compassapierror import CompassAPIError
8
9
  from .httpvalidationerror import HTTPValidationError, HTTPValidationErrorData
9
-
10
- __all__ = ["APIError", "HTTPValidationError", "HTTPValidationErrorData"]
10
+ from .no_response_error import NoResponseError
11
+ from .responsevalidationerror import ResponseValidationError
12
+
13
+ __all__ = [
14
+ "APIError",
15
+ "CompassAPIError",
16
+ "HTTPValidationError",
17
+ "HTTPValidationErrorData",
18
+ "NoResponseError",
19
+ "ResponseValidationError",
20
+ ]
11
21
 
12
22
  _dynamic_imports: dict[str, str] = {
13
23
  "APIError": ".apierror",
24
+ "CompassAPIError": ".compassapierror",
14
25
  "HTTPValidationError": ".httpvalidationerror",
15
26
  "HTTPValidationErrorData": ".httpvalidationerror",
27
+ "NoResponseError": ".no_response_error",
28
+ "ResponseValidationError": ".responsevalidationerror",
16
29
  }
17
30
 
18
31
 
@@ -1,22 +1,38 @@
1
1
  """Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
2
2
 
3
- from dataclasses import dataclass
4
- from typing import Optional
5
3
  import httpx
4
+ from typing import Optional
5
+
6
+ from compass_api_sdk.errors import CompassAPIError
7
+
8
+ MAX_MESSAGE_LEN = 10_000
9
+
10
+
11
+ class APIError(CompassAPIError):
12
+ """The fallback error class if no more specific error class is matched."""
13
+
14
+ def __init__(
15
+ self, message: str, raw_response: httpx.Response, body: Optional[str] = None
16
+ ):
17
+ body_display = body or raw_response.text or '""'
6
18
 
19
+ if message:
20
+ message += ": "
21
+ message += f"Status {raw_response.status_code}"
7
22
 
8
- @dataclass
9
- class APIError(Exception):
10
- """Represents an error returned by the API."""
23
+ headers = raw_response.headers
24
+ content_type = headers.get("content-type", '""')
25
+ if content_type != "application/json":
26
+ if " " in content_type:
27
+ content_type = f'"{content_type}"'
28
+ message += f" Content-Type {content_type}"
11
29
 
12
- message: str
13
- status_code: int = -1
14
- body: str = ""
15
- raw_response: Optional[httpx.Response] = None
30
+ if len(body_display) > MAX_MESSAGE_LEN:
31
+ truncated = body_display[:MAX_MESSAGE_LEN]
32
+ remaining = len(body_display) - MAX_MESSAGE_LEN
33
+ body_display = f"{truncated}...and {remaining} more chars"
16
34
 
17
- def __str__(self):
18
- body = ""
19
- if len(self.body) > 0:
20
- body = f"\n{self.body}"
35
+ message += f". Body: {body_display}"
36
+ message = message.strip()
21
37
 
22
- return f"{self.message}: Status {self.status_code}{body}"
38
+ super().__init__(message, raw_response, body)
@@ -0,0 +1,26 @@
1
+ """Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
2
+
3
+ import httpx
4
+ from typing import Optional
5
+
6
+
7
+ class CompassAPIError(Exception):
8
+ """The base class for all HTTP error responses."""
9
+
10
+ message: str
11
+ status_code: int
12
+ body: str
13
+ headers: httpx.Headers
14
+ raw_response: httpx.Response
15
+
16
+ def __init__(
17
+ self, message: str, raw_response: httpx.Response, body: Optional[str] = None
18
+ ):
19
+ self.message = message
20
+ self.status_code = raw_response.status_code
21
+ self.body = body if body is not None else raw_response.text
22
+ self.headers = raw_response.headers
23
+ self.raw_response = raw_response
24
+
25
+ def __str__(self):
26
+ return self.message
@@ -1,9 +1,10 @@
1
1
  """Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
2
2
 
3
3
  from __future__ import annotations
4
- from compass_api_sdk import utils
4
+ from compass_api_sdk.errors import CompassAPIError
5
5
  from compass_api_sdk.models import validationerror as models_validationerror
6
6
  from compass_api_sdk.types import BaseModel
7
+ import httpx
7
8
  from typing import List, Optional
8
9
 
9
10
 
@@ -11,11 +12,15 @@ class HTTPValidationErrorData(BaseModel):
11
12
  detail: Optional[List[models_validationerror.ValidationError]] = None
12
13
 
13
14
 
14
- class HTTPValidationError(Exception):
15
+ class HTTPValidationError(CompassAPIError):
15
16
  data: HTTPValidationErrorData
16
17
 
17
- def __init__(self, data: HTTPValidationErrorData):
18
+ def __init__(
19
+ self,
20
+ data: HTTPValidationErrorData,
21
+ raw_response: httpx.Response,
22
+ body: Optional[str] = None,
23
+ ):
24
+ message = body or raw_response.text
25
+ super().__init__(message, raw_response, body)
18
26
  self.data = data
19
-
20
- def __str__(self) -> str:
21
- return utils.marshal_json(self.data, HTTPValidationErrorData)
@@ -0,0 +1,13 @@
1
+ """Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
2
+
3
+ class NoResponseError(Exception):
4
+ """Error raised when no HTTP response is received from the server."""
5
+
6
+ message: str
7
+
8
+ def __init__(self, message: str = "No response received"):
9
+ self.message = message
10
+ super().__init__(message)
11
+
12
+ def __str__(self):
13
+ return self.message
@@ -0,0 +1,25 @@
1
+ """Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
2
+
3
+ import httpx
4
+ from typing import Optional
5
+
6
+ from compass_api_sdk.errors import CompassAPIError
7
+
8
+
9
+ class ResponseValidationError(CompassAPIError):
10
+ """Error raised when there is a type mismatch between the response data and the expected Pydantic model."""
11
+
12
+ def __init__(
13
+ self,
14
+ message: str,
15
+ raw_response: httpx.Response,
16
+ cause: Exception,
17
+ body: Optional[str] = None,
18
+ ):
19
+ message = f"{message}: {cause}"
20
+ super().__init__(message, raw_response, body)
21
+
22
+ @property
23
+ def cause(self):
24
+ """Normally the Pydantic ValidationError"""
25
+ return self.__cause__
@@ -6,12 +6,15 @@ from typing_extensions import TypedDict
6
6
 
7
7
 
8
8
  class ApyTypedDict(TypedDict):
9
+ current: str
9
10
  apy_1_day: str
10
11
  apy_7_day: str
11
12
  apy_30_day: str
12
13
 
13
14
 
14
15
  class Apy(BaseModel):
16
+ current: str
17
+
15
18
  apy_1_day: str
16
19
 
17
20
  apy_7_day: str
@@ -1,30 +1,88 @@
1
1
  """Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
2
2
 
3
3
  from __future__ import annotations
4
- from compass_api_sdk.types import BaseModel
4
+ from compass_api_sdk.types import (
5
+ BaseModel,
6
+ Nullable,
7
+ OptionalNullable,
8
+ UNSET,
9
+ UNSET_SENTINEL,
10
+ )
5
11
  from compass_api_sdk.utils import FieldMetadata, QueryParamMetadata
6
12
  from enum import Enum
7
- from typing_extensions import Annotated, TypedDict
13
+ from pydantic import model_serializer
14
+ from typing_extensions import Annotated, NotRequired, TypedDict
8
15
 
9
16
 
10
17
  class MorphoVaultChain(str, Enum):
11
- ETHEREUM_MAINNET = "ethereum:mainnet"
18
+ r"""The chain to use."""
19
+
12
20
  BASE_MAINNET = "base:mainnet"
21
+ ETHEREUM_MAINNET = "ethereum:mainnet"
22
+ ARBITRUM_MAINNET = "arbitrum:mainnet"
13
23
 
14
24
 
15
25
  class MorphoVaultRequestTypedDict(TypedDict):
16
26
  chain: MorphoVaultChain
27
+ r"""The chain to use."""
28
+ block: NotRequired[Nullable[int]]
29
+ r"""Optional block number (defaults to latest)."""
17
30
  vault_address: str
18
- r"""The vault address of the desired vault data & metrics."""
31
+ r"""The vault address of the desired vault position."""
32
+ user_address: NotRequired[Nullable[str]]
33
+ r"""The user address of the desired vault position. Only include if you would like the user position included in the response. Defaults to `None`."""
19
34
 
20
35
 
21
36
  class MorphoVaultRequest(BaseModel):
22
37
  chain: Annotated[
23
38
  MorphoVaultChain,
24
39
  FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
25
- ] = MorphoVaultChain.BASE_MAINNET
40
+ ] = MorphoVaultChain.ETHEREUM_MAINNET
41
+ r"""The chain to use."""
42
+
43
+ block: Annotated[
44
+ OptionalNullable[int],
45
+ FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
46
+ ] = UNSET
47
+ r"""Optional block number (defaults to latest)."""
26
48
 
27
49
  vault_address: Annotated[
28
50
  str, FieldMetadata(query=QueryParamMetadata(style="form", explode=True))
29
- ] = "0xc1256Ae5FF1cf2719D4937adb3bbCCab2E00A2Ca"
30
- r"""The vault address of the desired vault data & metrics."""
51
+ ] = "0x182863131F9a4630fF9E27830d945B1413e347E8"
52
+ r"""The vault address of the desired vault position."""
53
+
54
+ user_address: Annotated[
55
+ OptionalNullable[str],
56
+ FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
57
+ ] = UNSET
58
+ r"""The user address of the desired vault position. Only include if you would like the user position included in the response. Defaults to `None`."""
59
+
60
+ @model_serializer(mode="wrap")
61
+ def serialize_model(self, handler):
62
+ optional_fields = ["block", "user_address"]
63
+ nullable_fields = ["block", "user_address"]
64
+ null_default_fields = []
65
+
66
+ serialized = handler(self)
67
+
68
+ m = {}
69
+
70
+ for n, f in type(self).model_fields.items():
71
+ k = f.alias or n
72
+ val = serialized.get(k)
73
+ serialized.pop(k, None)
74
+
75
+ optional_nullable = k in optional_fields and k in nullable_fields
76
+ is_set = (
77
+ self.__pydantic_fields_set__.intersection({n})
78
+ or k in null_default_fields
79
+ ) # pylint: disable=no-member
80
+
81
+ if val is not None and val != UNSET_SENTINEL:
82
+ m[k] = val
83
+ elif val != UNSET_SENTINEL and (
84
+ not k in optional_fields or (optional_nullable and is_set)
85
+ ):
86
+ m[k] = val
87
+
88
+ return m