redis-agent-memory 0.0.2__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 (101) hide show
  1. redis_agent_memory/__init__.py +11 -0
  2. redis_agent_memory/_hooks/__init__.py +6 -0
  3. redis_agent_memory/_hooks/registration.py +13 -0
  4. redis_agent_memory/_hooks/sdkhooks.py +77 -0
  5. redis_agent_memory/_hooks/types.py +113 -0
  6. redis_agent_memory/_version.py +15 -0
  7. redis_agent_memory/basesdk.py +396 -0
  8. redis_agent_memory/errors/__init__.py +115 -0
  9. redis_agent_memory/errors/agentmemoryerror.py +31 -0
  10. redis_agent_memory/errors/apierror.py +41 -0
  11. redis_agent_memory/errors/authenticationerrorresponsecontent.py +43 -0
  12. redis_agent_memory/errors/badrequesterrorresponsecontent.py +45 -0
  13. redis_agent_memory/errors/faileddependencyerrorresponsecontent.py +43 -0
  14. redis_agent_memory/errors/forbiddenerrorresponsecontent.py +41 -0
  15. redis_agent_memory/errors/no_response_error.py +18 -0
  16. redis_agent_memory/errors/notfounderrorresponsecontent.py +41 -0
  17. redis_agent_memory/errors/notimplementederrorresponsecontent.py +43 -0
  18. redis_agent_memory/errors/payloadtoolargeerrorresponsecontent.py +43 -0
  19. redis_agent_memory/errors/responsevalidationerror.py +28 -0
  20. redis_agent_memory/errors/timeouterrorresponsecontent.py +41 -0
  21. redis_agent_memory/errors/toomanyrequestserrorresponsecontent.py +43 -0
  22. redis_agent_memory/errors/unexpectederrorresponsecontent.py +41 -0
  23. redis_agent_memory/httpclient.py +126 -0
  24. redis_agent_memory/models/__init__.py +376 -0
  25. redis_agent_memory/models/addsessioneventop.py +38 -0
  26. redis_agent_memory/models/addsessioneventrequestcontent.py +78 -0
  27. redis_agent_memory/models/addsessioneventresponsecontent.py +17 -0
  28. redis_agent_memory/models/authenticationerrortype.py +9 -0
  29. redis_agent_memory/models/badrequesterrortype.py +9 -0
  30. redis_agent_memory/models/bulkcreatelongtermmemoriesop.py +38 -0
  31. redis_agent_memory/models/bulkcreatelongtermmemoriesrequestcontent.py +18 -0
  32. redis_agent_memory/models/bulkcreatelongtermmemoriesresponsecontent.py +40 -0
  33. redis_agent_memory/models/bulkdeletelongtermmemoriesop.py +38 -0
  34. redis_agent_memory/models/bulkdeletelongtermmemoriesrequestcontent.py +24 -0
  35. redis_agent_memory/models/bulkdeletelongtermmemoriesresponsecontent.py +40 -0
  36. redis_agent_memory/models/bulkoperationerror.py +25 -0
  37. redis_agent_memory/models/content.py +24 -0
  38. redis_agent_memory/models/creatememoryrecord.py +90 -0
  39. redis_agent_memory/models/deletesessioneventop.py +61 -0
  40. redis_agent_memory/models/deletesessionmemoryop.py +52 -0
  41. redis_agent_memory/models/faileddependencyerrortype.py +11 -0
  42. redis_agent_memory/models/fielderror.py +20 -0
  43. redis_agent_memory/models/filterconjunction.py +12 -0
  44. redis_agent_memory/models/forbiddenerrortype.py +9 -0
  45. redis_agent_memory/models/getlongtermmemoryop.py +52 -0
  46. redis_agent_memory/models/getlongtermmemoryresponsecontent.py +100 -0
  47. redis_agent_memory/models/getsessioneventop.py +61 -0
  48. redis_agent_memory/models/getsessioneventresponsecontent.py +17 -0
  49. redis_agent_memory/models/getsessionmemoryop.py +52 -0
  50. redis_agent_memory/models/getsessionmemoryresponsecontent.py +39 -0
  51. redis_agent_memory/models/healthresponsecontent.py +20 -0
  52. redis_agent_memory/models/internal/__init__.py +26 -0
  53. redis_agent_memory/models/internal/globals.py +38 -0
  54. redis_agent_memory/models/listsessionsop.py +79 -0
  55. redis_agent_memory/models/listsessionsresponsecontent.py +22 -0
  56. redis_agent_memory/models/longtermmemoryfilter.py +78 -0
  57. redis_agent_memory/models/memoryrecord.py +100 -0
  58. redis_agent_memory/models/memorytype.py +14 -0
  59. redis_agent_memory/models/messagerole.py +14 -0
  60. redis_agent_memory/models/notfounderrortype.py +9 -0
  61. redis_agent_memory/models/notimplementederrortype.py +9 -0
  62. redis_agent_memory/models/numericfilter.py +58 -0
  63. redis_agent_memory/models/payloadtoolargeerrortype.py +9 -0
  64. redis_agent_memory/models/searchlongtermmemoryop.py +38 -0
  65. redis_agent_memory/models/searchlongtermmemoryrequestcontent.py +76 -0
  66. redis_agent_memory/models/searchlongtermmemoryresponsecontent.py +49 -0
  67. redis_agent_memory/models/security.py +43 -0
  68. redis_agent_memory/models/sessionevent.py +87 -0
  69. redis_agent_memory/models/tagfilter.py +60 -0
  70. redis_agent_memory/models/timeouterrortype.py +9 -0
  71. redis_agent_memory/models/toomanyrequestserrortype.py +9 -0
  72. redis_agent_memory/models/unexpectederrortype.py +9 -0
  73. redis_agent_memory/models/updatelongtermmemoryop.py +78 -0
  74. redis_agent_memory/models/updatelongtermmemoryrequestcontent.py +81 -0
  75. redis_agent_memory/models/updatelongtermmemoryresponsecontent.py +100 -0
  76. redis_agent_memory/py.typed +1 -0
  77. redis_agent_memory/sdk.py +3889 -0
  78. redis_agent_memory/sdkconfiguration.py +32 -0
  79. redis_agent_memory/types/__init__.py +22 -0
  80. redis_agent_memory/types/basemodel.py +78 -0
  81. redis_agent_memory/utils/__init__.py +179 -0
  82. redis_agent_memory/utils/annotations.py +80 -0
  83. redis_agent_memory/utils/datetimes.py +24 -0
  84. redis_agent_memory/utils/dynamic_imports.py +55 -0
  85. redis_agent_memory/utils/enums.py +135 -0
  86. redis_agent_memory/utils/eventstreaming.py +310 -0
  87. redis_agent_memory/utils/forms.py +235 -0
  88. redis_agent_memory/utils/headers.py +137 -0
  89. redis_agent_memory/utils/logger.py +28 -0
  90. redis_agent_memory/utils/metadata.py +120 -0
  91. redis_agent_memory/utils/queryparams.py +218 -0
  92. redis_agent_memory/utils/requestbodies.py +67 -0
  93. redis_agent_memory/utils/retries.py +272 -0
  94. redis_agent_memory/utils/security.py +216 -0
  95. redis_agent_memory/utils/serializers.py +226 -0
  96. redis_agent_memory/utils/unmarshal_json_response.py +39 -0
  97. redis_agent_memory/utils/url.py +156 -0
  98. redis_agent_memory/utils/values.py +138 -0
  99. redis_agent_memory-0.0.2.dist-info/METADATA +666 -0
  100. redis_agent_memory-0.0.2.dist-info/RECORD +101 -0
  101. redis_agent_memory-0.0.2.dist-info/WHEEL +4 -0
@@ -0,0 +1,11 @@
1
+ """Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
2
+ # @generated-id: 113d4d78be09
3
+
4
+ from ._version import __title__, __version__, __gen_version__, __user_agent__
5
+ from .sdk import *
6
+ from .sdkconfiguration import *
7
+
8
+
9
+ VERSION: str = __version__
10
+ SPEAKEASY_GENERATOR_VERSION = __gen_version__
11
+ USER_AGENT = __user_agent__
@@ -0,0 +1,6 @@
1
+ """Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
2
+ # @generated-id: 71e71f5b9e11
3
+
4
+ from .sdkhooks import *
5
+ from .types import *
6
+ from .registration import *
@@ -0,0 +1,13 @@
1
+ from .types import Hooks
2
+
3
+
4
+ # This file is only ever generated once on the first generation and then is free to be modified.
5
+ # Any hooks you wish to add should be registered in the init_hooks function. Feel free to define them
6
+ # in this file or in separate files in the hooks folder.
7
+
8
+
9
+ def init_hooks(hooks: Hooks):
10
+ # pylint: disable=unused-argument
11
+ """Add hooks by calling hooks.register{sdk_init/before_request/after_success/after_error}Hook
12
+ with an instance of a hook that implements that specific Hook interface
13
+ Hooks are registered per SDK instance, and are valid for the lifetime of the SDK instance"""
@@ -0,0 +1,77 @@
1
+ """Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
2
+ # @generated-id: a763535a9572
3
+
4
+ import httpx
5
+ from .types import (
6
+ SDKInitHook,
7
+ BeforeRequestContext,
8
+ BeforeRequestHook,
9
+ AfterSuccessContext,
10
+ AfterSuccessHook,
11
+ AfterErrorContext,
12
+ AfterErrorHook,
13
+ Hooks,
14
+ )
15
+ from .registration import init_hooks
16
+ from typing import List, Optional, Tuple
17
+ from redis_agent_memory.sdkconfiguration import SDKConfiguration
18
+
19
+
20
+ class SDKHooks(Hooks):
21
+ def __init__(self) -> None:
22
+ self.sdk_init_hooks: List[SDKInitHook] = []
23
+ self.before_request_hooks: List[BeforeRequestHook] = []
24
+ self.after_success_hooks: List[AfterSuccessHook] = []
25
+ self.after_error_hooks: List[AfterErrorHook] = []
26
+ init_hooks(self)
27
+
28
+ def register_sdk_init_hook(self, hook: SDKInitHook) -> None:
29
+ self.sdk_init_hooks.append(hook)
30
+
31
+ def register_before_request_hook(self, hook: BeforeRequestHook) -> None:
32
+ self.before_request_hooks.append(hook)
33
+
34
+ def register_after_success_hook(self, hook: AfterSuccessHook) -> None:
35
+ self.after_success_hooks.append(hook)
36
+
37
+ def register_after_error_hook(self, hook: AfterErrorHook) -> None:
38
+ self.after_error_hooks.append(hook)
39
+
40
+ def sdk_init(self, config: SDKConfiguration) -> SDKConfiguration:
41
+ for hook in self.sdk_init_hooks:
42
+ config = hook.sdk_init(config)
43
+ return config
44
+
45
+ def before_request(
46
+ self, hook_ctx: BeforeRequestContext, request: httpx.Request
47
+ ) -> httpx.Request:
48
+ for hook in self.before_request_hooks:
49
+ out = hook.before_request(hook_ctx, request)
50
+ if isinstance(out, Exception):
51
+ raise out
52
+ request = out
53
+
54
+ return request
55
+
56
+ def after_success(
57
+ self, hook_ctx: AfterSuccessContext, response: httpx.Response
58
+ ) -> httpx.Response:
59
+ for hook in self.after_success_hooks:
60
+ out = hook.after_success(hook_ctx, response)
61
+ if isinstance(out, Exception):
62
+ raise out
63
+ response = out
64
+ return response
65
+
66
+ def after_error(
67
+ self,
68
+ hook_ctx: AfterErrorContext,
69
+ response: Optional[httpx.Response],
70
+ error: Optional[Exception],
71
+ ) -> Tuple[Optional[httpx.Response], Optional[Exception]]:
72
+ for hook in self.after_error_hooks:
73
+ result = hook.after_error(hook_ctx, response, error)
74
+ if isinstance(result, Exception):
75
+ raise result
76
+ response, error = result
77
+ return response, error
@@ -0,0 +1,113 @@
1
+ """Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
2
+ # @generated-id: c4965746a7d2
3
+
4
+ from abc import ABC, abstractmethod
5
+ import httpx
6
+ from redis_agent_memory.sdkconfiguration import SDKConfiguration
7
+ from typing import Any, Callable, List, Optional, Tuple, Union
8
+
9
+
10
+ class HookContext:
11
+ config: SDKConfiguration
12
+ base_url: str
13
+ operation_id: str
14
+ oauth2_scopes: Optional[List[str]] = None
15
+ security_source: Optional[Union[Any, Callable[[], Any]]] = None
16
+
17
+ def __init__(
18
+ self,
19
+ config: SDKConfiguration,
20
+ base_url: str,
21
+ operation_id: str,
22
+ oauth2_scopes: Optional[List[str]],
23
+ security_source: Optional[Union[Any, Callable[[], Any]]],
24
+ ):
25
+ self.config = config
26
+ self.base_url = base_url
27
+ self.operation_id = operation_id
28
+ self.oauth2_scopes = oauth2_scopes
29
+ self.security_source = security_source
30
+
31
+
32
+ class BeforeRequestContext(HookContext):
33
+ def __init__(self, hook_ctx: HookContext):
34
+ super().__init__(
35
+ hook_ctx.config,
36
+ hook_ctx.base_url,
37
+ hook_ctx.operation_id,
38
+ hook_ctx.oauth2_scopes,
39
+ hook_ctx.security_source,
40
+ )
41
+
42
+
43
+ class AfterSuccessContext(HookContext):
44
+ def __init__(self, hook_ctx: HookContext):
45
+ super().__init__(
46
+ hook_ctx.config,
47
+ hook_ctx.base_url,
48
+ hook_ctx.operation_id,
49
+ hook_ctx.oauth2_scopes,
50
+ hook_ctx.security_source,
51
+ )
52
+
53
+
54
+ class AfterErrorContext(HookContext):
55
+ def __init__(self, hook_ctx: HookContext):
56
+ super().__init__(
57
+ hook_ctx.config,
58
+ hook_ctx.base_url,
59
+ hook_ctx.operation_id,
60
+ hook_ctx.oauth2_scopes,
61
+ hook_ctx.security_source,
62
+ )
63
+
64
+
65
+ class SDKInitHook(ABC):
66
+ @abstractmethod
67
+ def sdk_init(self, config: SDKConfiguration) -> SDKConfiguration:
68
+ pass
69
+
70
+
71
+ class BeforeRequestHook(ABC):
72
+ @abstractmethod
73
+ def before_request(
74
+ self, hook_ctx: BeforeRequestContext, request: httpx.Request
75
+ ) -> Union[httpx.Request, Exception]:
76
+ pass
77
+
78
+
79
+ class AfterSuccessHook(ABC):
80
+ @abstractmethod
81
+ def after_success(
82
+ self, hook_ctx: AfterSuccessContext, response: httpx.Response
83
+ ) -> Union[httpx.Response, Exception]:
84
+ pass
85
+
86
+
87
+ class AfterErrorHook(ABC):
88
+ @abstractmethod
89
+ def after_error(
90
+ self,
91
+ hook_ctx: AfterErrorContext,
92
+ response: Optional[httpx.Response],
93
+ error: Optional[Exception],
94
+ ) -> Union[Tuple[Optional[httpx.Response], Optional[Exception]], Exception]:
95
+ pass
96
+
97
+
98
+ class Hooks(ABC):
99
+ @abstractmethod
100
+ def register_sdk_init_hook(self, hook: SDKInitHook):
101
+ pass
102
+
103
+ @abstractmethod
104
+ def register_before_request_hook(self, hook: BeforeRequestHook):
105
+ pass
106
+
107
+ @abstractmethod
108
+ def register_after_success_hook(self, hook: AfterSuccessHook):
109
+ pass
110
+
111
+ @abstractmethod
112
+ def register_after_error_hook(self, hook: AfterErrorHook):
113
+ pass
@@ -0,0 +1,15 @@
1
+ """Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
2
+ # @generated-id: 326a5437bf5c
3
+
4
+ import importlib.metadata
5
+
6
+ __title__: str = "redis-agent-memory"
7
+ __version__: str = "0.0.2"
8
+ __gen_version__: str = "2.879.1"
9
+ __user_agent__: str = "speakeasy-sdk/python 0.0.2 2.879.1 redis-agent-memory"
10
+
11
+ try:
12
+ if __package__ is not None:
13
+ __version__ = importlib.metadata.version(__package__)
14
+ except importlib.metadata.PackageNotFoundError:
15
+ pass
@@ -0,0 +1,396 @@
1
+ """Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
2
+ # @generated-id: a05f7527cc78
3
+
4
+ from .sdkconfiguration import SDKConfiguration
5
+ import httpx
6
+ from redis_agent_memory import errors, models, utils
7
+ from redis_agent_memory._hooks import (
8
+ AfterErrorContext,
9
+ AfterSuccessContext,
10
+ BeforeRequestContext,
11
+ )
12
+ from redis_agent_memory.utils import (
13
+ RetryConfig,
14
+ SerializedRequestBody,
15
+ get_body_content,
16
+ run_sync_in_thread,
17
+ )
18
+ from typing import Callable, List, Mapping, Optional, Tuple
19
+ from urllib.parse import parse_qs, urlparse
20
+
21
+
22
+ class BaseSDK:
23
+ sdk_configuration: SDKConfiguration
24
+ parent_ref: Optional[object] = None
25
+ """
26
+ Reference to the root SDK instance, if any. This will prevent it from
27
+ being garbage collected while there are active streams.
28
+ """
29
+
30
+ def __init__(
31
+ self,
32
+ sdk_config: SDKConfiguration,
33
+ parent_ref: Optional[object] = None,
34
+ ) -> None:
35
+ self.sdk_configuration = sdk_config
36
+ self.parent_ref = parent_ref
37
+
38
+ def _get_url(self, base_url, url_variables):
39
+ sdk_url, sdk_variables = self.sdk_configuration.get_server_details()
40
+
41
+ if base_url is None:
42
+ base_url = sdk_url
43
+
44
+ if url_variables is None:
45
+ url_variables = sdk_variables
46
+
47
+ return utils.template_url(base_url, url_variables)
48
+
49
+ def _build_request_async(
50
+ self,
51
+ method,
52
+ path,
53
+ base_url,
54
+ url_variables,
55
+ request,
56
+ request_body_required,
57
+ request_has_path_params,
58
+ request_has_query_params,
59
+ user_agent_header,
60
+ accept_header_value,
61
+ _globals=None,
62
+ security=None,
63
+ timeout_ms: Optional[int] = None,
64
+ get_serialized_body: Optional[
65
+ Callable[[], Optional[SerializedRequestBody]]
66
+ ] = None,
67
+ url_override: Optional[str] = None,
68
+ http_headers: Optional[Mapping[str, str]] = None,
69
+ allow_empty_value: Optional[List[str]] = None,
70
+ allowed_fields: Optional[List[str]] = None,
71
+ ) -> httpx.Request:
72
+ client = self.sdk_configuration.async_client
73
+ return self._build_request_with_client(
74
+ client,
75
+ method,
76
+ path,
77
+ base_url,
78
+ url_variables,
79
+ request,
80
+ request_body_required,
81
+ request_has_path_params,
82
+ request_has_query_params,
83
+ user_agent_header,
84
+ accept_header_value,
85
+ _globals,
86
+ security,
87
+ timeout_ms,
88
+ get_serialized_body,
89
+ url_override,
90
+ http_headers,
91
+ allow_empty_value,
92
+ allowed_fields,
93
+ )
94
+
95
+ def _build_request(
96
+ self,
97
+ method,
98
+ path,
99
+ base_url,
100
+ url_variables,
101
+ request,
102
+ request_body_required,
103
+ request_has_path_params,
104
+ request_has_query_params,
105
+ user_agent_header,
106
+ accept_header_value,
107
+ _globals=None,
108
+ security=None,
109
+ timeout_ms: Optional[int] = None,
110
+ get_serialized_body: Optional[
111
+ Callable[[], Optional[SerializedRequestBody]]
112
+ ] = None,
113
+ url_override: Optional[str] = None,
114
+ http_headers: Optional[Mapping[str, str]] = None,
115
+ allow_empty_value: Optional[List[str]] = None,
116
+ allowed_fields: Optional[List[str]] = None,
117
+ ) -> httpx.Request:
118
+ client = self.sdk_configuration.client
119
+ return self._build_request_with_client(
120
+ client,
121
+ method,
122
+ path,
123
+ base_url,
124
+ url_variables,
125
+ request,
126
+ request_body_required,
127
+ request_has_path_params,
128
+ request_has_query_params,
129
+ user_agent_header,
130
+ accept_header_value,
131
+ _globals,
132
+ security,
133
+ timeout_ms,
134
+ get_serialized_body,
135
+ url_override,
136
+ http_headers,
137
+ allow_empty_value,
138
+ allowed_fields,
139
+ )
140
+
141
+ def _build_request_with_client(
142
+ self,
143
+ client,
144
+ method,
145
+ path,
146
+ base_url,
147
+ url_variables,
148
+ request,
149
+ request_body_required,
150
+ request_has_path_params,
151
+ request_has_query_params,
152
+ user_agent_header,
153
+ accept_header_value,
154
+ _globals=None,
155
+ security=None,
156
+ timeout_ms: Optional[int] = None,
157
+ get_serialized_body: Optional[
158
+ Callable[[], Optional[SerializedRequestBody]]
159
+ ] = None,
160
+ url_override: Optional[str] = None,
161
+ http_headers: Optional[Mapping[str, str]] = None,
162
+ allow_empty_value: Optional[List[str]] = None,
163
+ allowed_fields: Optional[List[str]] = None,
164
+ ) -> httpx.Request:
165
+ query_params = {}
166
+
167
+ url = url_override
168
+ if url is None:
169
+ url = utils.generate_url(
170
+ self._get_url(base_url, url_variables),
171
+ path,
172
+ request if request_has_path_params else None,
173
+ _globals if request_has_path_params else None,
174
+ )
175
+
176
+ query_params = utils.get_query_params(
177
+ request if request_has_query_params else None,
178
+ _globals if request_has_query_params else None,
179
+ allow_empty_value,
180
+ )
181
+ else:
182
+ # Pick up the query parameter from the override so they can be
183
+ # preserved when building the request later on (necessary as of
184
+ # httpx 0.28).
185
+ parsed_override = urlparse(str(url_override))
186
+ query_params = parse_qs(parsed_override.query, keep_blank_values=True)
187
+
188
+ headers = utils.get_headers(request, _globals)
189
+ headers["Accept"] = accept_header_value
190
+ headers[user_agent_header] = self.sdk_configuration.user_agent
191
+
192
+ if security is not None:
193
+ if callable(security):
194
+ security = security()
195
+ security = utils.get_security_from_env(security, models.Security)
196
+ if security is not None:
197
+ security_headers, security_query_params = utils.get_security(
198
+ security, allowed_fields
199
+ )
200
+ headers = {**headers, **security_headers}
201
+ query_params = {**query_params, **security_query_params}
202
+
203
+ serialized_request_body = SerializedRequestBody()
204
+ if get_serialized_body is not None:
205
+ rb = get_serialized_body()
206
+ if request_body_required and rb is None:
207
+ raise ValueError("request body is required")
208
+
209
+ if rb is not None:
210
+ serialized_request_body = rb
211
+
212
+ if (
213
+ serialized_request_body.media_type is not None
214
+ and serialized_request_body.media_type
215
+ not in (
216
+ "multipart/form-data",
217
+ "multipart/mixed",
218
+ )
219
+ ):
220
+ headers["content-type"] = serialized_request_body.media_type
221
+
222
+ if http_headers is not None:
223
+ for header, value in http_headers.items():
224
+ headers[header] = value
225
+
226
+ timeout = timeout_ms / 1000 if timeout_ms is not None else None
227
+
228
+ return client.build_request(
229
+ method,
230
+ url,
231
+ params=query_params,
232
+ content=serialized_request_body.content,
233
+ data=serialized_request_body.data,
234
+ files=serialized_request_body.files,
235
+ headers=headers,
236
+ timeout=timeout if timeout is not None else httpx.USE_CLIENT_DEFAULT,
237
+ )
238
+
239
+ def do_request(
240
+ self,
241
+ hook_ctx,
242
+ request,
243
+ error_status_codes,
244
+ stream=False,
245
+ retry_config: Optional[Tuple[RetryConfig, List[str]]] = None,
246
+ ) -> httpx.Response:
247
+ client = self.sdk_configuration.client
248
+ logger = self.sdk_configuration.debug_logger
249
+
250
+ hooks = self.sdk_configuration.__dict__["_hooks"]
251
+
252
+ def do():
253
+ http_res = None
254
+ try:
255
+ req = hooks.before_request(BeforeRequestContext(hook_ctx), request)
256
+ if "timeout" in request.extensions and "timeout" not in req.extensions:
257
+ req.extensions["timeout"] = request.extensions["timeout"]
258
+ logger.debug(
259
+ "Request:\nMethod: %s\nURL: %s\nHeaders: %s\nBody: %s",
260
+ req.method,
261
+ req.url,
262
+ req.headers,
263
+ get_body_content(req),
264
+ )
265
+
266
+ if client is None:
267
+ raise ValueError("client is required")
268
+
269
+ http_res = client.send(req, stream=stream)
270
+ except Exception as e:
271
+ _, e = hooks.after_error(AfterErrorContext(hook_ctx), None, e)
272
+ if e is not None:
273
+ logger.debug("Request Exception", exc_info=True)
274
+ raise e
275
+
276
+ if http_res is None:
277
+ logger.debug("Raising no response SDK error")
278
+ raise errors.NoResponseError("No response received")
279
+
280
+ logger.debug(
281
+ "Response:\nStatus Code: %s\nURL: %s\nHeaders: %s\nBody: %s",
282
+ http_res.status_code,
283
+ http_res.url,
284
+ http_res.headers,
285
+ "<streaming response>" if stream else http_res.text,
286
+ )
287
+
288
+ if utils.match_status_codes(error_status_codes, http_res.status_code):
289
+ result, err = hooks.after_error(
290
+ AfterErrorContext(hook_ctx), http_res, None
291
+ )
292
+ if err is not None:
293
+ logger.debug("Request Exception", exc_info=True)
294
+ raise err
295
+ if result is not None:
296
+ http_res = result
297
+ else:
298
+ logger.debug("Raising unexpected SDK error")
299
+ raise errors.APIError("Unexpected error occurred", http_res)
300
+
301
+ return http_res
302
+
303
+ if retry_config is not None:
304
+ http_res = utils.retry(do, utils.Retries(retry_config[0], retry_config[1]))
305
+ else:
306
+ http_res = do()
307
+
308
+ if not utils.match_status_codes(error_status_codes, http_res.status_code):
309
+ http_res = hooks.after_success(AfterSuccessContext(hook_ctx), http_res)
310
+
311
+ return http_res
312
+
313
+ async def do_request_async(
314
+ self,
315
+ hook_ctx,
316
+ request,
317
+ error_status_codes,
318
+ stream=False,
319
+ retry_config: Optional[Tuple[RetryConfig, List[str]]] = None,
320
+ ) -> httpx.Response:
321
+ client = self.sdk_configuration.async_client
322
+ logger = self.sdk_configuration.debug_logger
323
+
324
+ hooks = self.sdk_configuration.__dict__["_hooks"]
325
+
326
+ async def do():
327
+ http_res = None
328
+ try:
329
+ req = await run_sync_in_thread(
330
+ hooks.before_request, BeforeRequestContext(hook_ctx), request
331
+ )
332
+
333
+ if "timeout" in request.extensions and "timeout" not in req.extensions:
334
+ req.extensions["timeout"] = request.extensions["timeout"]
335
+ logger.debug(
336
+ "Request:\nMethod: %s\nURL: %s\nHeaders: %s\nBody: %s",
337
+ req.method,
338
+ req.url,
339
+ req.headers,
340
+ get_body_content(req),
341
+ )
342
+
343
+ if client is None:
344
+ raise ValueError("client is required")
345
+
346
+ http_res = await client.send(req, stream=stream)
347
+ except Exception as e:
348
+ _, e = await run_sync_in_thread(
349
+ hooks.after_error, AfterErrorContext(hook_ctx), None, e
350
+ )
351
+
352
+ if e is not None:
353
+ logger.debug("Request Exception", exc_info=True)
354
+ raise e
355
+
356
+ if http_res is None:
357
+ logger.debug("Raising no response SDK error")
358
+ raise errors.NoResponseError("No response received")
359
+
360
+ logger.debug(
361
+ "Response:\nStatus Code: %s\nURL: %s\nHeaders: %s\nBody: %s",
362
+ http_res.status_code,
363
+ http_res.url,
364
+ http_res.headers,
365
+ "<streaming response>" if stream else http_res.text,
366
+ )
367
+
368
+ if utils.match_status_codes(error_status_codes, http_res.status_code):
369
+ result, err = await run_sync_in_thread(
370
+ hooks.after_error, AfterErrorContext(hook_ctx), http_res, None
371
+ )
372
+
373
+ if err is not None:
374
+ logger.debug("Request Exception", exc_info=True)
375
+ raise err
376
+ if result is not None:
377
+ http_res = result
378
+ else:
379
+ logger.debug("Raising unexpected SDK error")
380
+ raise errors.APIError("Unexpected error occurred", http_res)
381
+
382
+ return http_res
383
+
384
+ if retry_config is not None:
385
+ http_res = await utils.retry_async(
386
+ do, utils.Retries(retry_config[0], retry_config[1])
387
+ )
388
+ else:
389
+ http_res = await do()
390
+
391
+ if not utils.match_status_codes(error_status_codes, http_res.status_code):
392
+ http_res = await run_sync_in_thread(
393
+ hooks.after_success, AfterSuccessContext(hook_ctx), http_res
394
+ )
395
+
396
+ return http_res