runloop-api-client 0.1.0a3__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 (61) hide show
  1. runloop_api_client-0.1.0a3.dist-info/METADATA +334 -0
  2. runloop_api_client-0.1.0a3.dist-info/RECORD +61 -0
  3. runloop_api_client-0.1.0a3.dist-info/WHEEL +4 -0
  4. runloop_api_client-0.1.0a3.dist-info/licenses/LICENSE +7 -0
  5. runloop_minus_api_minus_client/__init__.py +83 -0
  6. runloop_minus_api_minus_client/_base_client.py +2006 -0
  7. runloop_minus_api_minus_client/_client.py +422 -0
  8. runloop_minus_api_minus_client/_compat.py +222 -0
  9. runloop_minus_api_minus_client/_constants.py +14 -0
  10. runloop_minus_api_minus_client/_exceptions.py +108 -0
  11. runloop_minus_api_minus_client/_files.py +127 -0
  12. runloop_minus_api_minus_client/_models.py +739 -0
  13. runloop_minus_api_minus_client/_qs.py +150 -0
  14. runloop_minus_api_minus_client/_resource.py +43 -0
  15. runloop_minus_api_minus_client/_response.py +822 -0
  16. runloop_minus_api_minus_client/_streaming.py +333 -0
  17. runloop_minus_api_minus_client/_types.py +220 -0
  18. runloop_minus_api_minus_client/_utils/__init__.py +52 -0
  19. runloop_minus_api_minus_client/_utils/_logs.py +25 -0
  20. runloop_minus_api_minus_client/_utils/_proxy.py +63 -0
  21. runloop_minus_api_minus_client/_utils/_reflection.py +8 -0
  22. runloop_minus_api_minus_client/_utils/_streams.py +12 -0
  23. runloop_minus_api_minus_client/_utils/_sync.py +81 -0
  24. runloop_minus_api_minus_client/_utils/_transform.py +382 -0
  25. runloop_minus_api_minus_client/_utils/_typing.py +120 -0
  26. runloop_minus_api_minus_client/_utils/_utils.py +402 -0
  27. runloop_minus_api_minus_client/_version.py +4 -0
  28. runloop_minus_api_minus_client/lib/.keep +4 -0
  29. runloop_minus_api_minus_client/py.typed +0 -0
  30. runloop_minus_api_minus_client/resources/__init__.py +47 -0
  31. runloop_minus_api_minus_client/resources/devboxes/__init__.py +33 -0
  32. runloop_minus_api_minus_client/resources/devboxes/devboxes.py +560 -0
  33. runloop_minus_api_minus_client/resources/devboxes/logs.py +143 -0
  34. runloop_minus_api_minus_client/resources/functions/__init__.py +33 -0
  35. runloop_minus_api_minus_client/resources/functions/functions.py +376 -0
  36. runloop_minus_api_minus_client/resources/functions/invocations/__init__.py +33 -0
  37. runloop_minus_api_minus_client/resources/functions/invocations/invocations.py +310 -0
  38. runloop_minus_api_minus_client/resources/functions/invocations/spans.py +147 -0
  39. runloop_minus_api_minus_client/resources/projects/__init__.py +33 -0
  40. runloop_minus_api_minus_client/resources/projects/logs.py +143 -0
  41. runloop_minus_api_minus_client/resources/projects/projects.py +155 -0
  42. runloop_minus_api_minus_client/types/__init__.py +14 -0
  43. runloop_minus_api_minus_client/types/devbox_create_params.py +30 -0
  44. runloop_minus_api_minus_client/types/devbox_execution_detail_view.py +21 -0
  45. runloop_minus_api_minus_client/types/devbox_list_params.py +12 -0
  46. runloop_minus_api_minus_client/types/devbox_list_view.py +13 -0
  47. runloop_minus_api_minus_client/types/devbox_view.py +21 -0
  48. runloop_minus_api_minus_client/types/devboxes/__init__.py +5 -0
  49. runloop_minus_api_minus_client/types/devboxes/devbox_logs_list_view.py +23 -0
  50. runloop_minus_api_minus_client/types/function_invoke_async_params.py +23 -0
  51. runloop_minus_api_minus_client/types/function_invoke_sync_params.py +23 -0
  52. runloop_minus_api_minus_client/types/function_list_view.py +20 -0
  53. runloop_minus_api_minus_client/types/functions/__init__.py +5 -0
  54. runloop_minus_api_minus_client/types/functions/function_invocation_list_view.py +26 -0
  55. runloop_minus_api_minus_client/types/functions/invocations/__init__.py +5 -0
  56. runloop_minus_api_minus_client/types/functions/invocations/invocation_span_list_view.py +16 -0
  57. runloop_minus_api_minus_client/types/project_list_view.py +149 -0
  58. runloop_minus_api_minus_client/types/projects/__init__.py +3 -0
  59. runloop_minus_api_minus_client/types/shared/__init__.py +4 -0
  60. runloop_minus_api_minus_client/types/shared/function_invocation_detail_view.py +25 -0
  61. runloop_minus_api_minus_client/types/shared/project_logs_view.py +22 -0
@@ -0,0 +1,422 @@
1
+ # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ from __future__ import annotations
4
+
5
+ import os
6
+ from typing import Any, Union, Mapping
7
+ from typing_extensions import Self, override
8
+
9
+ import httpx
10
+
11
+ from . import resources, _exceptions
12
+ from ._qs import Querystring
13
+ from ._types import (
14
+ NOT_GIVEN,
15
+ Omit,
16
+ Timeout,
17
+ NotGiven,
18
+ Transport,
19
+ ProxiesTypes,
20
+ RequestOptions,
21
+ )
22
+ from ._utils import (
23
+ is_given,
24
+ get_async_library,
25
+ )
26
+ from ._version import __version__
27
+ from ._streaming import Stream as Stream, AsyncStream as AsyncStream
28
+ from ._exceptions import RunloopError, APIStatusError
29
+ from ._base_client import (
30
+ DEFAULT_MAX_RETRIES,
31
+ SyncAPIClient,
32
+ AsyncAPIClient,
33
+ )
34
+
35
+ __all__ = [
36
+ "Timeout",
37
+ "Transport",
38
+ "ProxiesTypes",
39
+ "RequestOptions",
40
+ "resources",
41
+ "Runloop",
42
+ "AsyncRunloop",
43
+ "Client",
44
+ "AsyncClient",
45
+ ]
46
+
47
+
48
+ class Runloop(SyncAPIClient):
49
+ devboxes: resources.DevboxesResource
50
+ functions: resources.FunctionsResource
51
+ projects: resources.ProjectsResource
52
+ with_raw_response: RunloopWithRawResponse
53
+ with_streaming_response: RunloopWithStreamedResponse
54
+
55
+ # client options
56
+ bearer_token: str
57
+
58
+ def __init__(
59
+ self,
60
+ *,
61
+ bearer_token: str | None = None,
62
+ base_url: str | httpx.URL | None = None,
63
+ timeout: Union[float, Timeout, None, NotGiven] = NOT_GIVEN,
64
+ max_retries: int = DEFAULT_MAX_RETRIES,
65
+ default_headers: Mapping[str, str] | None = None,
66
+ default_query: Mapping[str, object] | None = None,
67
+ # Configure a custom httpx client.
68
+ # We provide a `DefaultHttpxClient` class that you can pass to retain the default values we use for `limits`, `timeout` & `follow_redirects`.
69
+ # See the [httpx documentation](https://www.python-httpx.org/api/#client) for more details.
70
+ http_client: httpx.Client | None = None,
71
+ # Enable or disable schema validation for data returned by the API.
72
+ # When enabled an error APIResponseValidationError is raised
73
+ # if the API responds with invalid data for the expected schema.
74
+ #
75
+ # This parameter may be removed or changed in the future.
76
+ # If you rely on this feature, please open a GitHub issue
77
+ # outlining your use-case to help us decide if it should be
78
+ # part of our public interface in the future.
79
+ _strict_response_validation: bool = False,
80
+ ) -> None:
81
+ """Construct a new synchronous runloop client instance.
82
+
83
+ This automatically infers the `bearer_token` argument from the `RUNLOOP_BEARER_TOKEN` environment variable if it is not provided.
84
+ """
85
+ if bearer_token is None:
86
+ bearer_token = os.environ.get("RUNLOOP_BEARER_TOKEN")
87
+ if bearer_token is None:
88
+ raise RunloopError(
89
+ "The bearer_token client option must be set either by passing bearer_token to the client or by setting the RUNLOOP_BEARER_TOKEN environment variable"
90
+ )
91
+ self.bearer_token = bearer_token
92
+
93
+ if base_url is None:
94
+ base_url = os.environ.get("RUNLOOP_BASE_URL")
95
+ if base_url is None:
96
+ base_url = f"https://api.runloop.pro"
97
+
98
+ super().__init__(
99
+ version=__version__,
100
+ base_url=base_url,
101
+ max_retries=max_retries,
102
+ timeout=timeout,
103
+ http_client=http_client,
104
+ custom_headers=default_headers,
105
+ custom_query=default_query,
106
+ _strict_response_validation=_strict_response_validation,
107
+ )
108
+
109
+ self.devboxes = resources.DevboxesResource(self)
110
+ self.functions = resources.FunctionsResource(self)
111
+ self.projects = resources.ProjectsResource(self)
112
+ self.with_raw_response = RunloopWithRawResponse(self)
113
+ self.with_streaming_response = RunloopWithStreamedResponse(self)
114
+
115
+ @property
116
+ @override
117
+ def qs(self) -> Querystring:
118
+ return Querystring(array_format="comma")
119
+
120
+ @property
121
+ @override
122
+ def auth_headers(self) -> dict[str, str]:
123
+ bearer_token = self.bearer_token
124
+ return {"Authorization": f"Bearer {bearer_token}"}
125
+
126
+ @property
127
+ @override
128
+ def default_headers(self) -> dict[str, str | Omit]:
129
+ return {
130
+ **super().default_headers,
131
+ "X-Stainless-Async": "false",
132
+ **self._custom_headers,
133
+ }
134
+
135
+ def copy(
136
+ self,
137
+ *,
138
+ bearer_token: str | None = None,
139
+ base_url: str | httpx.URL | None = None,
140
+ timeout: float | Timeout | None | NotGiven = NOT_GIVEN,
141
+ http_client: httpx.Client | None = None,
142
+ max_retries: int | NotGiven = NOT_GIVEN,
143
+ default_headers: Mapping[str, str] | None = None,
144
+ set_default_headers: Mapping[str, str] | None = None,
145
+ default_query: Mapping[str, object] | None = None,
146
+ set_default_query: Mapping[str, object] | None = None,
147
+ _extra_kwargs: Mapping[str, Any] = {},
148
+ ) -> Self:
149
+ """
150
+ Create a new client instance re-using the same options given to the current client with optional overriding.
151
+ """
152
+ if default_headers is not None and set_default_headers is not None:
153
+ raise ValueError("The `default_headers` and `set_default_headers` arguments are mutually exclusive")
154
+
155
+ if default_query is not None and set_default_query is not None:
156
+ raise ValueError("The `default_query` and `set_default_query` arguments are mutually exclusive")
157
+
158
+ headers = self._custom_headers
159
+ if default_headers is not None:
160
+ headers = {**headers, **default_headers}
161
+ elif set_default_headers is not None:
162
+ headers = set_default_headers
163
+
164
+ params = self._custom_query
165
+ if default_query is not None:
166
+ params = {**params, **default_query}
167
+ elif set_default_query is not None:
168
+ params = set_default_query
169
+
170
+ http_client = http_client or self._client
171
+ return self.__class__(
172
+ bearer_token=bearer_token or self.bearer_token,
173
+ base_url=base_url or self.base_url,
174
+ timeout=self.timeout if isinstance(timeout, NotGiven) else timeout,
175
+ http_client=http_client,
176
+ max_retries=max_retries if is_given(max_retries) else self.max_retries,
177
+ default_headers=headers,
178
+ default_query=params,
179
+ **_extra_kwargs,
180
+ )
181
+
182
+ # Alias for `copy` for nicer inline usage, e.g.
183
+ # client.with_options(timeout=10).foo.create(...)
184
+ with_options = copy
185
+
186
+ @override
187
+ def _make_status_error(
188
+ self,
189
+ err_msg: str,
190
+ *,
191
+ body: object,
192
+ response: httpx.Response,
193
+ ) -> APIStatusError:
194
+ if response.status_code == 400:
195
+ return _exceptions.BadRequestError(err_msg, response=response, body=body)
196
+
197
+ if response.status_code == 401:
198
+ return _exceptions.AuthenticationError(err_msg, response=response, body=body)
199
+
200
+ if response.status_code == 403:
201
+ return _exceptions.PermissionDeniedError(err_msg, response=response, body=body)
202
+
203
+ if response.status_code == 404:
204
+ return _exceptions.NotFoundError(err_msg, response=response, body=body)
205
+
206
+ if response.status_code == 409:
207
+ return _exceptions.ConflictError(err_msg, response=response, body=body)
208
+
209
+ if response.status_code == 422:
210
+ return _exceptions.UnprocessableEntityError(err_msg, response=response, body=body)
211
+
212
+ if response.status_code == 429:
213
+ return _exceptions.RateLimitError(err_msg, response=response, body=body)
214
+
215
+ if response.status_code >= 500:
216
+ return _exceptions.InternalServerError(err_msg, response=response, body=body)
217
+ return APIStatusError(err_msg, response=response, body=body)
218
+
219
+
220
+ class AsyncRunloop(AsyncAPIClient):
221
+ devboxes: resources.AsyncDevboxesResource
222
+ functions: resources.AsyncFunctionsResource
223
+ projects: resources.AsyncProjectsResource
224
+ with_raw_response: AsyncRunloopWithRawResponse
225
+ with_streaming_response: AsyncRunloopWithStreamedResponse
226
+
227
+ # client options
228
+ bearer_token: str
229
+
230
+ def __init__(
231
+ self,
232
+ *,
233
+ bearer_token: str | None = None,
234
+ base_url: str | httpx.URL | None = None,
235
+ timeout: Union[float, Timeout, None, NotGiven] = NOT_GIVEN,
236
+ max_retries: int = DEFAULT_MAX_RETRIES,
237
+ default_headers: Mapping[str, str] | None = None,
238
+ default_query: Mapping[str, object] | None = None,
239
+ # Configure a custom httpx client.
240
+ # We provide a `DefaultAsyncHttpxClient` class that you can pass to retain the default values we use for `limits`, `timeout` & `follow_redirects`.
241
+ # See the [httpx documentation](https://www.python-httpx.org/api/#asyncclient) for more details.
242
+ http_client: httpx.AsyncClient | None = None,
243
+ # Enable or disable schema validation for data returned by the API.
244
+ # When enabled an error APIResponseValidationError is raised
245
+ # if the API responds with invalid data for the expected schema.
246
+ #
247
+ # This parameter may be removed or changed in the future.
248
+ # If you rely on this feature, please open a GitHub issue
249
+ # outlining your use-case to help us decide if it should be
250
+ # part of our public interface in the future.
251
+ _strict_response_validation: bool = False,
252
+ ) -> None:
253
+ """Construct a new async runloop client instance.
254
+
255
+ This automatically infers the `bearer_token` argument from the `RUNLOOP_BEARER_TOKEN` environment variable if it is not provided.
256
+ """
257
+ if bearer_token is None:
258
+ bearer_token = os.environ.get("RUNLOOP_BEARER_TOKEN")
259
+ if bearer_token is None:
260
+ raise RunloopError(
261
+ "The bearer_token client option must be set either by passing bearer_token to the client or by setting the RUNLOOP_BEARER_TOKEN environment variable"
262
+ )
263
+ self.bearer_token = bearer_token
264
+
265
+ if base_url is None:
266
+ base_url = os.environ.get("RUNLOOP_BASE_URL")
267
+ if base_url is None:
268
+ base_url = f"https://api.runloop.pro"
269
+
270
+ super().__init__(
271
+ version=__version__,
272
+ base_url=base_url,
273
+ max_retries=max_retries,
274
+ timeout=timeout,
275
+ http_client=http_client,
276
+ custom_headers=default_headers,
277
+ custom_query=default_query,
278
+ _strict_response_validation=_strict_response_validation,
279
+ )
280
+
281
+ self.devboxes = resources.AsyncDevboxesResource(self)
282
+ self.functions = resources.AsyncFunctionsResource(self)
283
+ self.projects = resources.AsyncProjectsResource(self)
284
+ self.with_raw_response = AsyncRunloopWithRawResponse(self)
285
+ self.with_streaming_response = AsyncRunloopWithStreamedResponse(self)
286
+
287
+ @property
288
+ @override
289
+ def qs(self) -> Querystring:
290
+ return Querystring(array_format="comma")
291
+
292
+ @property
293
+ @override
294
+ def auth_headers(self) -> dict[str, str]:
295
+ bearer_token = self.bearer_token
296
+ return {"Authorization": f"Bearer {bearer_token}"}
297
+
298
+ @property
299
+ @override
300
+ def default_headers(self) -> dict[str, str | Omit]:
301
+ return {
302
+ **super().default_headers,
303
+ "X-Stainless-Async": f"async:{get_async_library()}",
304
+ **self._custom_headers,
305
+ }
306
+
307
+ def copy(
308
+ self,
309
+ *,
310
+ bearer_token: str | None = None,
311
+ base_url: str | httpx.URL | None = None,
312
+ timeout: float | Timeout | None | NotGiven = NOT_GIVEN,
313
+ http_client: httpx.AsyncClient | None = None,
314
+ max_retries: int | NotGiven = NOT_GIVEN,
315
+ default_headers: Mapping[str, str] | None = None,
316
+ set_default_headers: Mapping[str, str] | None = None,
317
+ default_query: Mapping[str, object] | None = None,
318
+ set_default_query: Mapping[str, object] | None = None,
319
+ _extra_kwargs: Mapping[str, Any] = {},
320
+ ) -> Self:
321
+ """
322
+ Create a new client instance re-using the same options given to the current client with optional overriding.
323
+ """
324
+ if default_headers is not None and set_default_headers is not None:
325
+ raise ValueError("The `default_headers` and `set_default_headers` arguments are mutually exclusive")
326
+
327
+ if default_query is not None and set_default_query is not None:
328
+ raise ValueError("The `default_query` and `set_default_query` arguments are mutually exclusive")
329
+
330
+ headers = self._custom_headers
331
+ if default_headers is not None:
332
+ headers = {**headers, **default_headers}
333
+ elif set_default_headers is not None:
334
+ headers = set_default_headers
335
+
336
+ params = self._custom_query
337
+ if default_query is not None:
338
+ params = {**params, **default_query}
339
+ elif set_default_query is not None:
340
+ params = set_default_query
341
+
342
+ http_client = http_client or self._client
343
+ return self.__class__(
344
+ bearer_token=bearer_token or self.bearer_token,
345
+ base_url=base_url or self.base_url,
346
+ timeout=self.timeout if isinstance(timeout, NotGiven) else timeout,
347
+ http_client=http_client,
348
+ max_retries=max_retries if is_given(max_retries) else self.max_retries,
349
+ default_headers=headers,
350
+ default_query=params,
351
+ **_extra_kwargs,
352
+ )
353
+
354
+ # Alias for `copy` for nicer inline usage, e.g.
355
+ # client.with_options(timeout=10).foo.create(...)
356
+ with_options = copy
357
+
358
+ @override
359
+ def _make_status_error(
360
+ self,
361
+ err_msg: str,
362
+ *,
363
+ body: object,
364
+ response: httpx.Response,
365
+ ) -> APIStatusError:
366
+ if response.status_code == 400:
367
+ return _exceptions.BadRequestError(err_msg, response=response, body=body)
368
+
369
+ if response.status_code == 401:
370
+ return _exceptions.AuthenticationError(err_msg, response=response, body=body)
371
+
372
+ if response.status_code == 403:
373
+ return _exceptions.PermissionDeniedError(err_msg, response=response, body=body)
374
+
375
+ if response.status_code == 404:
376
+ return _exceptions.NotFoundError(err_msg, response=response, body=body)
377
+
378
+ if response.status_code == 409:
379
+ return _exceptions.ConflictError(err_msg, response=response, body=body)
380
+
381
+ if response.status_code == 422:
382
+ return _exceptions.UnprocessableEntityError(err_msg, response=response, body=body)
383
+
384
+ if response.status_code == 429:
385
+ return _exceptions.RateLimitError(err_msg, response=response, body=body)
386
+
387
+ if response.status_code >= 500:
388
+ return _exceptions.InternalServerError(err_msg, response=response, body=body)
389
+ return APIStatusError(err_msg, response=response, body=body)
390
+
391
+
392
+ class RunloopWithRawResponse:
393
+ def __init__(self, client: Runloop) -> None:
394
+ self.devboxes = resources.DevboxesResourceWithRawResponse(client.devboxes)
395
+ self.functions = resources.FunctionsResourceWithRawResponse(client.functions)
396
+ self.projects = resources.ProjectsResourceWithRawResponse(client.projects)
397
+
398
+
399
+ class AsyncRunloopWithRawResponse:
400
+ def __init__(self, client: AsyncRunloop) -> None:
401
+ self.devboxes = resources.AsyncDevboxesResourceWithRawResponse(client.devboxes)
402
+ self.functions = resources.AsyncFunctionsResourceWithRawResponse(client.functions)
403
+ self.projects = resources.AsyncProjectsResourceWithRawResponse(client.projects)
404
+
405
+
406
+ class RunloopWithStreamedResponse:
407
+ def __init__(self, client: Runloop) -> None:
408
+ self.devboxes = resources.DevboxesResourceWithStreamingResponse(client.devboxes)
409
+ self.functions = resources.FunctionsResourceWithStreamingResponse(client.functions)
410
+ self.projects = resources.ProjectsResourceWithStreamingResponse(client.projects)
411
+
412
+
413
+ class AsyncRunloopWithStreamedResponse:
414
+ def __init__(self, client: AsyncRunloop) -> None:
415
+ self.devboxes = resources.AsyncDevboxesResourceWithStreamingResponse(client.devboxes)
416
+ self.functions = resources.AsyncFunctionsResourceWithStreamingResponse(client.functions)
417
+ self.projects = resources.AsyncProjectsResourceWithStreamingResponse(client.projects)
418
+
419
+
420
+ Client = Runloop
421
+
422
+ AsyncClient = AsyncRunloop
@@ -0,0 +1,222 @@
1
+ from __future__ import annotations
2
+
3
+ from typing import TYPE_CHECKING, Any, Union, Generic, TypeVar, Callable, cast, overload
4
+ from datetime import date, datetime
5
+ from typing_extensions import Self
6
+
7
+ import pydantic
8
+ from pydantic.fields import FieldInfo
9
+
10
+ from ._types import StrBytesIntFloat
11
+
12
+ _T = TypeVar("_T")
13
+ _ModelT = TypeVar("_ModelT", bound=pydantic.BaseModel)
14
+
15
+ # --------------- Pydantic v2 compatibility ---------------
16
+
17
+ # Pyright incorrectly reports some of our functions as overriding a method when they don't
18
+ # pyright: reportIncompatibleMethodOverride=false
19
+
20
+ PYDANTIC_V2 = pydantic.VERSION.startswith("2.")
21
+
22
+ # v1 re-exports
23
+ if TYPE_CHECKING:
24
+
25
+ def parse_date(value: date | StrBytesIntFloat) -> date: # noqa: ARG001
26
+ ...
27
+
28
+ def parse_datetime(value: Union[datetime, StrBytesIntFloat]) -> datetime: # noqa: ARG001
29
+ ...
30
+
31
+ def get_args(t: type[Any]) -> tuple[Any, ...]: # noqa: ARG001
32
+ ...
33
+
34
+ def is_union(tp: type[Any] | None) -> bool: # noqa: ARG001
35
+ ...
36
+
37
+ def get_origin(t: type[Any]) -> type[Any] | None: # noqa: ARG001
38
+ ...
39
+
40
+ def is_literal_type(type_: type[Any]) -> bool: # noqa: ARG001
41
+ ...
42
+
43
+ def is_typeddict(type_: type[Any]) -> bool: # noqa: ARG001
44
+ ...
45
+
46
+ else:
47
+ if PYDANTIC_V2:
48
+ from pydantic.v1.typing import (
49
+ get_args as get_args,
50
+ is_union as is_union,
51
+ get_origin as get_origin,
52
+ is_typeddict as is_typeddict,
53
+ is_literal_type as is_literal_type,
54
+ )
55
+ from pydantic.v1.datetime_parse import parse_date as parse_date, parse_datetime as parse_datetime
56
+ else:
57
+ from pydantic.typing import (
58
+ get_args as get_args,
59
+ is_union as is_union,
60
+ get_origin as get_origin,
61
+ is_typeddict as is_typeddict,
62
+ is_literal_type as is_literal_type,
63
+ )
64
+ from pydantic.datetime_parse import parse_date as parse_date, parse_datetime as parse_datetime
65
+
66
+
67
+ # refactored config
68
+ if TYPE_CHECKING:
69
+ from pydantic import ConfigDict as ConfigDict
70
+ else:
71
+ if PYDANTIC_V2:
72
+ from pydantic import ConfigDict
73
+ else:
74
+ # TODO: provide an error message here?
75
+ ConfigDict = None
76
+
77
+
78
+ # renamed methods / properties
79
+ def parse_obj(model: type[_ModelT], value: object) -> _ModelT:
80
+ if PYDANTIC_V2:
81
+ return model.model_validate(value)
82
+ else:
83
+ return cast(_ModelT, model.parse_obj(value)) # pyright: ignore[reportDeprecated, reportUnnecessaryCast]
84
+
85
+
86
+ def field_is_required(field: FieldInfo) -> bool:
87
+ if PYDANTIC_V2:
88
+ return field.is_required()
89
+ return field.required # type: ignore
90
+
91
+
92
+ def field_get_default(field: FieldInfo) -> Any:
93
+ value = field.get_default()
94
+ if PYDANTIC_V2:
95
+ from pydantic_core import PydanticUndefined
96
+
97
+ if value == PydanticUndefined:
98
+ return None
99
+ return value
100
+ return value
101
+
102
+
103
+ def field_outer_type(field: FieldInfo) -> Any:
104
+ if PYDANTIC_V2:
105
+ return field.annotation
106
+ return field.outer_type_ # type: ignore
107
+
108
+
109
+ def get_model_config(model: type[pydantic.BaseModel]) -> Any:
110
+ if PYDANTIC_V2:
111
+ return model.model_config
112
+ return model.__config__ # type: ignore
113
+
114
+
115
+ def get_model_fields(model: type[pydantic.BaseModel]) -> dict[str, FieldInfo]:
116
+ if PYDANTIC_V2:
117
+ return model.model_fields
118
+ return model.__fields__ # type: ignore
119
+
120
+
121
+ def model_copy(model: _ModelT) -> _ModelT:
122
+ if PYDANTIC_V2:
123
+ return model.model_copy()
124
+ return model.copy() # type: ignore
125
+
126
+
127
+ def model_json(model: pydantic.BaseModel, *, indent: int | None = None) -> str:
128
+ if PYDANTIC_V2:
129
+ return model.model_dump_json(indent=indent)
130
+ return model.json(indent=indent) # type: ignore
131
+
132
+
133
+ def model_dump(
134
+ model: pydantic.BaseModel,
135
+ *,
136
+ exclude_unset: bool = False,
137
+ exclude_defaults: bool = False,
138
+ ) -> dict[str, Any]:
139
+ if PYDANTIC_V2:
140
+ return model.model_dump(
141
+ exclude_unset=exclude_unset,
142
+ exclude_defaults=exclude_defaults,
143
+ )
144
+ return cast(
145
+ "dict[str, Any]",
146
+ model.dict( # pyright: ignore[reportDeprecated, reportUnnecessaryCast]
147
+ exclude_unset=exclude_unset,
148
+ exclude_defaults=exclude_defaults,
149
+ ),
150
+ )
151
+
152
+
153
+ def model_parse(model: type[_ModelT], data: Any) -> _ModelT:
154
+ if PYDANTIC_V2:
155
+ return model.model_validate(data)
156
+ return model.parse_obj(data) # pyright: ignore[reportDeprecated]
157
+
158
+
159
+ # generic models
160
+ if TYPE_CHECKING:
161
+
162
+ class GenericModel(pydantic.BaseModel):
163
+ ...
164
+
165
+ else:
166
+ if PYDANTIC_V2:
167
+ # there no longer needs to be a distinction in v2 but
168
+ # we still have to create our own subclass to avoid
169
+ # inconsistent MRO ordering errors
170
+ class GenericModel(pydantic.BaseModel):
171
+ ...
172
+
173
+ else:
174
+ import pydantic.generics
175
+
176
+ class GenericModel(pydantic.generics.GenericModel, pydantic.BaseModel):
177
+ ...
178
+
179
+
180
+ # cached properties
181
+ if TYPE_CHECKING:
182
+ cached_property = property
183
+
184
+ # we define a separate type (copied from typeshed)
185
+ # that represents that `cached_property` is `set`able
186
+ # at runtime, which differs from `@property`.
187
+ #
188
+ # this is a separate type as editors likely special case
189
+ # `@property` and we don't want to cause issues just to have
190
+ # more helpful internal types.
191
+
192
+ class typed_cached_property(Generic[_T]):
193
+ func: Callable[[Any], _T]
194
+ attrname: str | None
195
+
196
+ def __init__(self, func: Callable[[Any], _T]) -> None:
197
+ ...
198
+
199
+ @overload
200
+ def __get__(self, instance: None, owner: type[Any] | None = None) -> Self:
201
+ ...
202
+
203
+ @overload
204
+ def __get__(self, instance: object, owner: type[Any] | None = None) -> _T:
205
+ ...
206
+
207
+ def __get__(self, instance: object, owner: type[Any] | None = None) -> _T | Self:
208
+ raise NotImplementedError()
209
+
210
+ def __set_name__(self, owner: type[Any], name: str) -> None:
211
+ ...
212
+
213
+ # __set__ is not defined at runtime, but @cached_property is designed to be settable
214
+ def __set__(self, instance: object, value: _T) -> None:
215
+ ...
216
+ else:
217
+ try:
218
+ from functools import cached_property as cached_property
219
+ except ImportError:
220
+ from cached_property import cached_property as cached_property
221
+
222
+ typed_cached_property = cached_property
@@ -0,0 +1,14 @@
1
+ # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ import httpx
4
+
5
+ RAW_RESPONSE_HEADER = "X-Stainless-Raw-Response"
6
+ OVERRIDE_CAST_TO_HEADER = "____stainless_override_cast_to"
7
+
8
+ # default timeout is 1 minute
9
+ DEFAULT_TIMEOUT = httpx.Timeout(timeout=60.0, connect=5.0)
10
+ DEFAULT_MAX_RETRIES = 2
11
+ DEFAULT_CONNECTION_LIMITS = httpx.Limits(max_connections=100, max_keepalive_connections=20)
12
+
13
+ INITIAL_RETRY_DELAY = 0.5
14
+ MAX_RETRY_DELAY = 8.0