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