continuous-labs 0.1.3__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 (84) hide show
  1. continuous/__init__.py +17 -0
  2. continuous/_hooks/__init__.py +5 -0
  3. continuous/_hooks/registration.py +13 -0
  4. continuous/_hooks/sdkhooks.py +76 -0
  5. continuous/_hooks/types.py +124 -0
  6. continuous/_version.py +15 -0
  7. continuous/basesdk.py +396 -0
  8. continuous/errors/__init__.py +39 -0
  9. continuous/errors/continuousdefaulterror.py +40 -0
  10. continuous/errors/continuouserror.py +30 -0
  11. continuous/errors/error.py +27 -0
  12. continuous/errors/no_response_error.py +17 -0
  13. continuous/errors/responsevalidationerror.py +27 -0
  14. continuous/httpclient.py +125 -0
  15. continuous/models/__init__.py +294 -0
  16. continuous/models/build_simulatorop.py +84 -0
  17. continuous/models/buildsimulatorrequest.py +81 -0
  18. continuous/models/buildworldrequest.py +38 -0
  19. continuous/models/cancel_simulator_buildop.py +18 -0
  20. continuous/models/cancel_world_buildop.py +18 -0
  21. continuous/models/createdsimulation.py +83 -0
  22. continuous/models/createsimulationrequest.py +38 -0
  23. continuous/models/delete_simulationop.py +18 -0
  24. continuous/models/delete_simulatorop.py +18 -0
  25. continuous/models/delete_worldop.py +18 -0
  26. continuous/models/fork_simulationop.py +25 -0
  27. continuous/models/forksimulationrequest.py +38 -0
  28. continuous/models/get_simulationop.py +18 -0
  29. continuous/models/get_simulatorop.py +18 -0
  30. continuous/models/get_worldop.py +18 -0
  31. continuous/models/list_simulation_stepsop.py +52 -0
  32. continuous/models/list_simulationsop.py +69 -0
  33. continuous/models/list_simulatorsop.py +70 -0
  34. continuous/models/list_worldsop.py +45 -0
  35. continuous/models/listsimulationsresponse.py +37 -0
  36. continuous/models/listsimulationstepsresponse.py +37 -0
  37. continuous/models/listsimulatorsresponse.py +37 -0
  38. continuous/models/listworldsresponse.py +37 -0
  39. continuous/models/mint_simulation_tokenop.py +28 -0
  40. continuous/models/mintsimulationtokenrequest.py +15 -0
  41. continuous/models/resourceerror.py +20 -0
  42. continuous/models/security.py +42 -0
  43. continuous/models/simulation.py +73 -0
  44. continuous/models/simulationtoken.py +21 -0
  45. continuous/models/simulator.py +83 -0
  46. continuous/models/start_simulationop.py +18 -0
  47. continuous/models/start_worldop.py +18 -0
  48. continuous/models/step.py +20 -0
  49. continuous/models/stop_simulationop.py +18 -0
  50. continuous/models/stop_worldop.py +18 -0
  51. continuous/models/world.py +76 -0
  52. continuous/models/worldsimulation.py +20 -0
  53. continuous/py.typed +1 -0
  54. continuous/sdk.py +189 -0
  55. continuous/sdkconfiguration.py +49 -0
  56. continuous/simulations.py +1915 -0
  57. continuous/simulators.py +1057 -0
  58. continuous/types/__init__.py +24 -0
  59. continuous/types/base64fileinput.py +43 -0
  60. continuous/types/basemodel.py +77 -0
  61. continuous/utils/__init__.py +180 -0
  62. continuous/utils/annotations.py +79 -0
  63. continuous/utils/datetimes.py +37 -0
  64. continuous/utils/dynamic_imports.py +54 -0
  65. continuous/utils/enums.py +134 -0
  66. continuous/utils/eventstreaming.py +326 -0
  67. continuous/utils/forms.py +239 -0
  68. continuous/utils/headers.py +136 -0
  69. continuous/utils/logger.py +27 -0
  70. continuous/utils/metadata.py +119 -0
  71. continuous/utils/queryparams.py +217 -0
  72. continuous/utils/requestbodies.py +67 -0
  73. continuous/utils/retries.py +372 -0
  74. continuous/utils/security.py +215 -0
  75. continuous/utils/serializers.py +306 -0
  76. continuous/utils/unmarshal_json_response.py +38 -0
  77. continuous/utils/url.py +155 -0
  78. continuous/utils/values.py +139 -0
  79. continuous/worlds.py +1425 -0
  80. continuous_labs-0.1.3.dist-info/METADATA +562 -0
  81. continuous_labs-0.1.3.dist-info/RECORD +84 -0
  82. continuous_labs-0.1.3.dist-info/WHEEL +5 -0
  83. continuous_labs-0.1.3.dist-info/licenses/LICENSE +21 -0
  84. continuous_labs-0.1.3.dist-info/top_level.txt +1 -0
continuous/__init__.py ADDED
@@ -0,0 +1,17 @@
1
+ """Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
2
+
3
+ from ._version import (
4
+ __title__,
5
+ __version__,
6
+ __openapi_doc_version__,
7
+ __gen_version__,
8
+ __user_agent__,
9
+ )
10
+ from .sdk import *
11
+ from .sdkconfiguration import *
12
+
13
+
14
+ VERSION: str = __version__
15
+ OPENAPI_DOC_VERSION = __openapi_doc_version__
16
+ SPEAKEASY_GENERATOR_VERSION = __gen_version__
17
+ USER_AGENT = __user_agent__
@@ -0,0 +1,5 @@
1
+ """Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
2
+
3
+ from .sdkhooks import *
4
+ from .types import *
5
+ 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,76 @@
1
+ """Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
2
+
3
+ import httpx
4
+ from .types import (
5
+ SDKInitHook,
6
+ BeforeRequestContext,
7
+ BeforeRequestHook,
8
+ AfterSuccessContext,
9
+ AfterSuccessHook,
10
+ AfterErrorContext,
11
+ AfterErrorHook,
12
+ Hooks,
13
+ )
14
+ from .registration import init_hooks
15
+ from typing import List, Optional, Tuple
16
+ from continuous.sdkconfiguration import SDKConfiguration
17
+
18
+
19
+ class SDKHooks(Hooks):
20
+ def __init__(self) -> None:
21
+ self.sdk_init_hooks: List[SDKInitHook] = []
22
+ self.before_request_hooks: List[BeforeRequestHook] = []
23
+ self.after_success_hooks: List[AfterSuccessHook] = []
24
+ self.after_error_hooks: List[AfterErrorHook] = []
25
+ init_hooks(self)
26
+
27
+ def register_sdk_init_hook(self, hook: SDKInitHook) -> None:
28
+ self.sdk_init_hooks.append(hook)
29
+
30
+ def register_before_request_hook(self, hook: BeforeRequestHook) -> None:
31
+ self.before_request_hooks.append(hook)
32
+
33
+ def register_after_success_hook(self, hook: AfterSuccessHook) -> None:
34
+ self.after_success_hooks.append(hook)
35
+
36
+ def register_after_error_hook(self, hook: AfterErrorHook) -> None:
37
+ self.after_error_hooks.append(hook)
38
+
39
+ def sdk_init(self, config: SDKConfiguration) -> SDKConfiguration:
40
+ for hook in self.sdk_init_hooks:
41
+ config = hook.sdk_init(config)
42
+ return config
43
+
44
+ def before_request(
45
+ self, hook_ctx: BeforeRequestContext, request: httpx.Request
46
+ ) -> httpx.Request:
47
+ for hook in self.before_request_hooks:
48
+ out = hook.before_request(hook_ctx, request)
49
+ if isinstance(out, Exception):
50
+ raise out
51
+ request = out
52
+
53
+ return request
54
+
55
+ def after_success(
56
+ self, hook_ctx: AfterSuccessContext, response: httpx.Response
57
+ ) -> httpx.Response:
58
+ for hook in self.after_success_hooks:
59
+ out = hook.after_success(hook_ctx, response)
60
+ if isinstance(out, Exception):
61
+ raise out
62
+ response = out
63
+ return response
64
+
65
+ def after_error(
66
+ self,
67
+ hook_ctx: AfterErrorContext,
68
+ response: Optional[httpx.Response],
69
+ error: Optional[Exception],
70
+ ) -> Tuple[Optional[httpx.Response], Optional[Exception]]:
71
+ for hook in self.after_error_hooks:
72
+ result = hook.after_error(hook_ctx, response, error)
73
+ if isinstance(result, Exception):
74
+ raise result
75
+ response, error = result
76
+ return response, error
@@ -0,0 +1,124 @@
1
+ """Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
2
+
3
+ from abc import ABC, abstractmethod
4
+ from continuous.sdkconfiguration import SDKConfiguration
5
+ import httpx
6
+ from typing import Any, Callable, Dict, List, Optional, Tuple, Union
7
+
8
+
9
+ class HookContext:
10
+ config: SDKConfiguration
11
+ base_url: str
12
+ operation_id: str
13
+ oauth2_scopes: Optional[List[str]] = None
14
+ security_source: Optional[Union[Any, Callable[[], Any]]] = None
15
+ tags: Optional[List[str]] = None
16
+ extensions: Optional[Dict[str, Any]] = None
17
+
18
+ def __init__(
19
+ self,
20
+ config: SDKConfiguration,
21
+ base_url: str,
22
+ operation_id: str,
23
+ oauth2_scopes: Optional[List[str]],
24
+ security_source: Optional[Union[Any, Callable[[], Any]]],
25
+ tags: Optional[List[str]],
26
+ extensions: Optional[Dict[str, Any]],
27
+ ):
28
+ self.config = config
29
+ self.base_url = base_url
30
+ self.operation_id = operation_id
31
+ self.oauth2_scopes = oauth2_scopes
32
+ self.security_source = security_source
33
+ self.tags = tags
34
+ self.extensions = extensions
35
+
36
+
37
+ class BeforeRequestContext(HookContext):
38
+ def __init__(self, hook_ctx: HookContext):
39
+ super().__init__(
40
+ hook_ctx.config,
41
+ hook_ctx.base_url,
42
+ hook_ctx.operation_id,
43
+ hook_ctx.oauth2_scopes,
44
+ hook_ctx.security_source,
45
+ hook_ctx.tags,
46
+ hook_ctx.extensions,
47
+ )
48
+
49
+
50
+ class AfterSuccessContext(HookContext):
51
+ def __init__(self, hook_ctx: HookContext):
52
+ super().__init__(
53
+ hook_ctx.config,
54
+ hook_ctx.base_url,
55
+ hook_ctx.operation_id,
56
+ hook_ctx.oauth2_scopes,
57
+ hook_ctx.security_source,
58
+ hook_ctx.tags,
59
+ hook_ctx.extensions,
60
+ )
61
+
62
+
63
+ class AfterErrorContext(HookContext):
64
+ def __init__(self, hook_ctx: HookContext):
65
+ super().__init__(
66
+ hook_ctx.config,
67
+ hook_ctx.base_url,
68
+ hook_ctx.operation_id,
69
+ hook_ctx.oauth2_scopes,
70
+ hook_ctx.security_source,
71
+ hook_ctx.tags,
72
+ hook_ctx.extensions,
73
+ )
74
+
75
+
76
+ class SDKInitHook(ABC):
77
+ @abstractmethod
78
+ def sdk_init(self, config: SDKConfiguration) -> SDKConfiguration:
79
+ pass
80
+
81
+
82
+ class BeforeRequestHook(ABC):
83
+ @abstractmethod
84
+ def before_request(
85
+ self, hook_ctx: BeforeRequestContext, request: httpx.Request
86
+ ) -> Union[httpx.Request, Exception]:
87
+ pass
88
+
89
+
90
+ class AfterSuccessHook(ABC):
91
+ @abstractmethod
92
+ def after_success(
93
+ self, hook_ctx: AfterSuccessContext, response: httpx.Response
94
+ ) -> Union[httpx.Response, Exception]:
95
+ pass
96
+
97
+
98
+ class AfterErrorHook(ABC):
99
+ @abstractmethod
100
+ def after_error(
101
+ self,
102
+ hook_ctx: AfterErrorContext,
103
+ response: Optional[httpx.Response],
104
+ error: Optional[Exception],
105
+ ) -> Union[Tuple[Optional[httpx.Response], Optional[Exception]], Exception]:
106
+ pass
107
+
108
+
109
+ class Hooks(ABC):
110
+ @abstractmethod
111
+ def register_sdk_init_hook(self, hook: SDKInitHook):
112
+ pass
113
+
114
+ @abstractmethod
115
+ def register_before_request_hook(self, hook: BeforeRequestHook):
116
+ pass
117
+
118
+ @abstractmethod
119
+ def register_after_success_hook(self, hook: AfterSuccessHook):
120
+ pass
121
+
122
+ @abstractmethod
123
+ def register_after_error_hook(self, hook: AfterErrorHook):
124
+ pass
continuous/_version.py ADDED
@@ -0,0 +1,15 @@
1
+ """Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
2
+
3
+ import importlib.metadata
4
+
5
+ __title__: str = "continuous-labs"
6
+ __version__: str = "0.1.3"
7
+ __openapi_doc_version__: str = "v1"
8
+ __gen_version__: str = "2.935.1"
9
+ __user_agent__: str = "speakeasy-sdk/python 0.1.3 2.935.1 v1 continuous-labs"
10
+
11
+ try:
12
+ if __package__ is not None:
13
+ __version__ = importlib.metadata.version(__package__)
14
+ except importlib.metadata.PackageNotFoundError:
15
+ pass
continuous/basesdk.py ADDED
@@ -0,0 +1,396 @@
1
+ """Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
2
+
3
+ from .sdkconfiguration import SDKConfiguration
4
+ from continuous import errors, models, utils
5
+ from continuous._hooks import (
6
+ AfterErrorContext,
7
+ AfterSuccessContext,
8
+ BeforeRequestContext,
9
+ HookContext,
10
+ )
11
+ from continuous.utils import (
12
+ RetryConfig,
13
+ SerializedRequestBody,
14
+ get_body_content,
15
+ run_sync_in_thread,
16
+ )
17
+ import httpx
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: HookContext,
242
+ request: httpx.Request,
243
+ is_error_status_code: Callable[[int], bool],
244
+ stream: bool = 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
+ return http_res
289
+
290
+ if retry_config is not None:
291
+ http_res = utils.retry(do, utils.Retries(retry_config[0], retry_config[1]))
292
+ else:
293
+ http_res = do()
294
+
295
+ if is_error_status_code(http_res.status_code):
296
+ result, err = hooks.after_error(AfterErrorContext(hook_ctx), http_res, None)
297
+ if err is not None:
298
+ logger.debug("Request Exception", exc_info=True)
299
+ raise err
300
+ if result is not None:
301
+ http_res = result
302
+ else:
303
+ logger.debug("Raising unexpected SDK error")
304
+ raise errors.ContinuousDefaultError(
305
+ "Unexpected error occurred", http_res
306
+ )
307
+ else:
308
+ http_res = hooks.after_success(AfterSuccessContext(hook_ctx), http_res)
309
+
310
+ return http_res
311
+
312
+ async def do_request_async(
313
+ self,
314
+ hook_ctx: HookContext,
315
+ request: httpx.Request,
316
+ is_error_status_code: Callable[[int], bool],
317
+ stream: bool = False,
318
+ retry_config: Optional[Tuple[RetryConfig, List[str]]] = None,
319
+ ) -> httpx.Response:
320
+ client = self.sdk_configuration.async_client
321
+ logger = self.sdk_configuration.debug_logger
322
+
323
+ hooks = self.sdk_configuration.__dict__["_hooks"]
324
+
325
+ async def do():
326
+ http_res = None
327
+ try:
328
+ req = await run_sync_in_thread(
329
+ hooks.before_request, BeforeRequestContext(hook_ctx), request
330
+ )
331
+
332
+ if "timeout" in request.extensions and "timeout" not in req.extensions:
333
+ req.extensions["timeout"] = request.extensions["timeout"]
334
+ logger.debug(
335
+ "Request:\nMethod: %s\nURL: %s\nHeaders: %s\nBody: %s",
336
+ req.method,
337
+ req.url,
338
+ req.headers,
339
+ get_body_content(req),
340
+ )
341
+
342
+ if client is None:
343
+ raise ValueError("client is required")
344
+
345
+ http_res = await client.send(req, stream=stream)
346
+ except Exception as e:
347
+ _, e = await run_sync_in_thread(
348
+ hooks.after_error, AfterErrorContext(hook_ctx), None, e
349
+ )
350
+
351
+ if e is not None:
352
+ logger.debug("Request Exception", exc_info=True)
353
+ raise e
354
+
355
+ if http_res is None:
356
+ logger.debug("Raising no response SDK error")
357
+ raise errors.NoResponseError("No response received")
358
+
359
+ logger.debug(
360
+ "Response:\nStatus Code: %s\nURL: %s\nHeaders: %s\nBody: %s",
361
+ http_res.status_code,
362
+ http_res.url,
363
+ http_res.headers,
364
+ "<streaming response>" if stream else http_res.text,
365
+ )
366
+
367
+ return http_res
368
+
369
+ if retry_config is not None:
370
+ http_res = await utils.retry_async(
371
+ do, utils.Retries(retry_config[0], retry_config[1])
372
+ )
373
+ else:
374
+ http_res = await do()
375
+
376
+ if is_error_status_code(http_res.status_code):
377
+ result, err = await run_sync_in_thread(
378
+ hooks.after_error, AfterErrorContext(hook_ctx), http_res, None
379
+ )
380
+
381
+ if err is not None:
382
+ logger.debug("Request Exception", exc_info=True)
383
+ raise err
384
+ if result is not None:
385
+ http_res = result
386
+ else:
387
+ logger.debug("Raising unexpected SDK error")
388
+ raise errors.ContinuousDefaultError(
389
+ "Unexpected error occurred", http_res
390
+ )
391
+ else:
392
+ http_res = await run_sync_in_thread(
393
+ hooks.after_success, AfterSuccessContext(hook_ctx), http_res
394
+ )
395
+
396
+ return http_res
@@ -0,0 +1,39 @@
1
+ """Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
2
+
3
+ from .continuouserror import ContinuousError
4
+ from typing import Any, TYPE_CHECKING
5
+
6
+ from continuous.utils.dynamic_imports import lazy_getattr, lazy_dir
7
+
8
+ if TYPE_CHECKING:
9
+ from .continuousdefaulterror import ContinuousDefaultError
10
+ from .error import Error, ErrorData
11
+ from .no_response_error import NoResponseError
12
+ from .responsevalidationerror import ResponseValidationError
13
+
14
+ __all__ = [
15
+ "ContinuousDefaultError",
16
+ "ContinuousError",
17
+ "Error",
18
+ "ErrorData",
19
+ "NoResponseError",
20
+ "ResponseValidationError",
21
+ ]
22
+
23
+ _dynamic_imports: dict[str, str] = {
24
+ "ContinuousDefaultError": ".continuousdefaulterror",
25
+ "Error": ".error",
26
+ "ErrorData": ".error",
27
+ "NoResponseError": ".no_response_error",
28
+ "ResponseValidationError": ".responsevalidationerror",
29
+ }
30
+
31
+
32
+ def __getattr__(attr_name: str) -> Any:
33
+ return lazy_getattr(
34
+ attr_name, package=__package__, dynamic_imports=_dynamic_imports
35
+ )
36
+
37
+
38
+ def __dir__():
39
+ return lazy_dir(dynamic_imports=_dynamic_imports)