chunkr-ai 0.1.0__py3-none-any.whl → 0.1.0a2__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. chunkr_ai/__init__.py +89 -2
  2. chunkr_ai/_base_client.py +1995 -0
  3. chunkr_ai/_client.py +403 -0
  4. chunkr_ai/_compat.py +219 -0
  5. chunkr_ai/_constants.py +14 -0
  6. chunkr_ai/_exceptions.py +108 -0
  7. chunkr_ai/_files.py +123 -0
  8. chunkr_ai/_models.py +829 -0
  9. chunkr_ai/_qs.py +150 -0
  10. chunkr_ai/_resource.py +43 -0
  11. chunkr_ai/_response.py +830 -0
  12. chunkr_ai/_streaming.py +333 -0
  13. chunkr_ai/_types.py +219 -0
  14. chunkr_ai/_utils/__init__.py +57 -0
  15. chunkr_ai/_utils/_logs.py +25 -0
  16. chunkr_ai/_utils/_proxy.py +65 -0
  17. chunkr_ai/_utils/_reflection.py +42 -0
  18. chunkr_ai/_utils/_resources_proxy.py +24 -0
  19. chunkr_ai/_utils/_streams.py +12 -0
  20. chunkr_ai/_utils/_sync.py +86 -0
  21. chunkr_ai/_utils/_transform.py +447 -0
  22. chunkr_ai/_utils/_typing.py +151 -0
  23. chunkr_ai/_utils/_utils.py +422 -0
  24. chunkr_ai/_version.py +4 -0
  25. chunkr_ai/lib/.keep +4 -0
  26. chunkr_ai/pagination.py +71 -0
  27. chunkr_ai/resources/__init__.py +33 -0
  28. chunkr_ai/resources/health.py +136 -0
  29. chunkr_ai/resources/task/__init__.py +33 -0
  30. chunkr_ai/resources/task/parse.py +616 -0
  31. chunkr_ai/resources/task/task.py +664 -0
  32. chunkr_ai/types/__init__.py +8 -0
  33. chunkr_ai/types/health_check_response.py +7 -0
  34. chunkr_ai/types/task/__init__.py +7 -0
  35. chunkr_ai/types/task/parse_create_params.py +806 -0
  36. chunkr_ai/types/task/parse_update_params.py +806 -0
  37. chunkr_ai/types/task/task.py +1186 -0
  38. chunkr_ai/types/task_get_params.py +18 -0
  39. chunkr_ai/types/task_list_params.py +37 -0
  40. chunkr_ai-0.1.0a2.dist-info/METADATA +504 -0
  41. chunkr_ai-0.1.0a2.dist-info/RECORD +44 -0
  42. {chunkr_ai-0.1.0.dist-info → chunkr_ai-0.1.0a2.dist-info}/WHEEL +1 -2
  43. chunkr_ai-0.1.0a2.dist-info/licenses/LICENSE +201 -0
  44. chunkr_ai/api/auth.py +0 -13
  45. chunkr_ai/api/chunkr.py +0 -103
  46. chunkr_ai/api/chunkr_base.py +0 -185
  47. chunkr_ai/api/configuration.py +0 -313
  48. chunkr_ai/api/decorators.py +0 -101
  49. chunkr_ai/api/misc.py +0 -139
  50. chunkr_ai/api/protocol.py +0 -14
  51. chunkr_ai/api/task_response.py +0 -208
  52. chunkr_ai/models.py +0 -55
  53. chunkr_ai-0.1.0.dist-info/METADATA +0 -268
  54. chunkr_ai-0.1.0.dist-info/RECORD +0 -16
  55. chunkr_ai-0.1.0.dist-info/licenses/LICENSE +0 -21
  56. chunkr_ai-0.1.0.dist-info/top_level.txt +0 -1
  57. /chunkr_ai/{api/__init__.py → py.typed} +0 -0
chunkr_ai/_client.py ADDED
@@ -0,0 +1,403 @@
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 _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 is_given, get_async_library
23
+ from ._version import __version__
24
+ from .resources import health
25
+ from ._streaming import Stream as Stream, AsyncStream as AsyncStream
26
+ from ._exceptions import ChunkrError, APIStatusError
27
+ from ._base_client import (
28
+ DEFAULT_MAX_RETRIES,
29
+ SyncAPIClient,
30
+ AsyncAPIClient,
31
+ )
32
+ from .resources.task import task
33
+
34
+ __all__ = ["Timeout", "Transport", "ProxiesTypes", "RequestOptions", "Chunkr", "AsyncChunkr", "Client", "AsyncClient"]
35
+
36
+
37
+ class Chunkr(SyncAPIClient):
38
+ task: task.TaskResource
39
+ health: health.HealthResource
40
+ with_raw_response: ChunkrWithRawResponse
41
+ with_streaming_response: ChunkrWithStreamedResponse
42
+
43
+ # client options
44
+ api_key: str
45
+
46
+ def __init__(
47
+ self,
48
+ *,
49
+ api_key: str | None = None,
50
+ base_url: str | httpx.URL | None = None,
51
+ timeout: Union[float, Timeout, None, NotGiven] = NOT_GIVEN,
52
+ max_retries: int = DEFAULT_MAX_RETRIES,
53
+ default_headers: Mapping[str, str] | None = None,
54
+ default_query: Mapping[str, object] | None = None,
55
+ # Configure a custom httpx client.
56
+ # We provide a `DefaultHttpxClient` class that you can pass to retain the default values we use for `limits`, `timeout` & `follow_redirects`.
57
+ # See the [httpx documentation](https://www.python-httpx.org/api/#client) for more details.
58
+ http_client: httpx.Client | None = None,
59
+ # Enable or disable schema validation for data returned by the API.
60
+ # When enabled an error APIResponseValidationError is raised
61
+ # if the API responds with invalid data for the expected schema.
62
+ #
63
+ # This parameter may be removed or changed in the future.
64
+ # If you rely on this feature, please open a GitHub issue
65
+ # outlining your use-case to help us decide if it should be
66
+ # part of our public interface in the future.
67
+ _strict_response_validation: bool = False,
68
+ ) -> None:
69
+ """Construct a new synchronous Chunkr client instance.
70
+
71
+ This automatically infers the `api_key` argument from the `CHUNKR_API_KEY` environment variable if it is not provided.
72
+ """
73
+ if api_key is None:
74
+ api_key = os.environ.get("CHUNKR_API_KEY")
75
+ if api_key is None:
76
+ raise ChunkrError(
77
+ "The api_key client option must be set either by passing api_key to the client or by setting the CHUNKR_API_KEY environment variable"
78
+ )
79
+ self.api_key = api_key
80
+
81
+ if base_url is None:
82
+ base_url = os.environ.get("CHUNKR_BASE_URL")
83
+ if base_url is None:
84
+ base_url = f"https://api.chunkr.ai/api/v1/"
85
+
86
+ super().__init__(
87
+ version=__version__,
88
+ base_url=base_url,
89
+ max_retries=max_retries,
90
+ timeout=timeout,
91
+ http_client=http_client,
92
+ custom_headers=default_headers,
93
+ custom_query=default_query,
94
+ _strict_response_validation=_strict_response_validation,
95
+ )
96
+
97
+ self.task = task.TaskResource(self)
98
+ self.health = health.HealthResource(self)
99
+ self.with_raw_response = ChunkrWithRawResponse(self)
100
+ self.with_streaming_response = ChunkrWithStreamedResponse(self)
101
+
102
+ @property
103
+ @override
104
+ def qs(self) -> Querystring:
105
+ return Querystring(array_format="comma")
106
+
107
+ @property
108
+ @override
109
+ def auth_headers(self) -> dict[str, str]:
110
+ api_key = self.api_key
111
+ return {"Authorization": api_key}
112
+
113
+ @property
114
+ @override
115
+ def default_headers(self) -> dict[str, str | Omit]:
116
+ return {
117
+ **super().default_headers,
118
+ "X-Stainless-Async": "false",
119
+ **self._custom_headers,
120
+ }
121
+
122
+ def copy(
123
+ self,
124
+ *,
125
+ api_key: str | None = None,
126
+ base_url: str | httpx.URL | None = None,
127
+ timeout: float | Timeout | None | NotGiven = NOT_GIVEN,
128
+ http_client: httpx.Client | None = None,
129
+ max_retries: int | NotGiven = NOT_GIVEN,
130
+ default_headers: Mapping[str, str] | None = None,
131
+ set_default_headers: Mapping[str, str] | None = None,
132
+ default_query: Mapping[str, object] | None = None,
133
+ set_default_query: Mapping[str, object] | None = None,
134
+ _extra_kwargs: Mapping[str, Any] = {},
135
+ ) -> Self:
136
+ """
137
+ Create a new client instance re-using the same options given to the current client with optional overriding.
138
+ """
139
+ if default_headers is not None and set_default_headers is not None:
140
+ raise ValueError("The `default_headers` and `set_default_headers` arguments are mutually exclusive")
141
+
142
+ if default_query is not None and set_default_query is not None:
143
+ raise ValueError("The `default_query` and `set_default_query` arguments are mutually exclusive")
144
+
145
+ headers = self._custom_headers
146
+ if default_headers is not None:
147
+ headers = {**headers, **default_headers}
148
+ elif set_default_headers is not None:
149
+ headers = set_default_headers
150
+
151
+ params = self._custom_query
152
+ if default_query is not None:
153
+ params = {**params, **default_query}
154
+ elif set_default_query is not None:
155
+ params = set_default_query
156
+
157
+ http_client = http_client or self._client
158
+ return self.__class__(
159
+ api_key=api_key or self.api_key,
160
+ base_url=base_url or self.base_url,
161
+ timeout=self.timeout if isinstance(timeout, NotGiven) else timeout,
162
+ http_client=http_client,
163
+ max_retries=max_retries if is_given(max_retries) else self.max_retries,
164
+ default_headers=headers,
165
+ default_query=params,
166
+ **_extra_kwargs,
167
+ )
168
+
169
+ # Alias for `copy` for nicer inline usage, e.g.
170
+ # client.with_options(timeout=10).foo.create(...)
171
+ with_options = copy
172
+
173
+ @override
174
+ def _make_status_error(
175
+ self,
176
+ err_msg: str,
177
+ *,
178
+ body: object,
179
+ response: httpx.Response,
180
+ ) -> APIStatusError:
181
+ if response.status_code == 400:
182
+ return _exceptions.BadRequestError(err_msg, response=response, body=body)
183
+
184
+ if response.status_code == 401:
185
+ return _exceptions.AuthenticationError(err_msg, response=response, body=body)
186
+
187
+ if response.status_code == 403:
188
+ return _exceptions.PermissionDeniedError(err_msg, response=response, body=body)
189
+
190
+ if response.status_code == 404:
191
+ return _exceptions.NotFoundError(err_msg, response=response, body=body)
192
+
193
+ if response.status_code == 409:
194
+ return _exceptions.ConflictError(err_msg, response=response, body=body)
195
+
196
+ if response.status_code == 422:
197
+ return _exceptions.UnprocessableEntityError(err_msg, response=response, body=body)
198
+
199
+ if response.status_code == 429:
200
+ return _exceptions.RateLimitError(err_msg, response=response, body=body)
201
+
202
+ if response.status_code >= 500:
203
+ return _exceptions.InternalServerError(err_msg, response=response, body=body)
204
+ return APIStatusError(err_msg, response=response, body=body)
205
+
206
+
207
+ class AsyncChunkr(AsyncAPIClient):
208
+ task: task.AsyncTaskResource
209
+ health: health.AsyncHealthResource
210
+ with_raw_response: AsyncChunkrWithRawResponse
211
+ with_streaming_response: AsyncChunkrWithStreamedResponse
212
+
213
+ # client options
214
+ api_key: str
215
+
216
+ def __init__(
217
+ self,
218
+ *,
219
+ api_key: str | None = None,
220
+ base_url: str | httpx.URL | None = None,
221
+ timeout: Union[float, Timeout, None, NotGiven] = NOT_GIVEN,
222
+ max_retries: int = DEFAULT_MAX_RETRIES,
223
+ default_headers: Mapping[str, str] | None = None,
224
+ default_query: Mapping[str, object] | None = None,
225
+ # Configure a custom httpx client.
226
+ # We provide a `DefaultAsyncHttpxClient` class that you can pass to retain the default values we use for `limits`, `timeout` & `follow_redirects`.
227
+ # See the [httpx documentation](https://www.python-httpx.org/api/#asyncclient) for more details.
228
+ http_client: httpx.AsyncClient | None = None,
229
+ # Enable or disable schema validation for data returned by the API.
230
+ # When enabled an error APIResponseValidationError is raised
231
+ # if the API responds with invalid data for the expected schema.
232
+ #
233
+ # This parameter may be removed or changed in the future.
234
+ # If you rely on this feature, please open a GitHub issue
235
+ # outlining your use-case to help us decide if it should be
236
+ # part of our public interface in the future.
237
+ _strict_response_validation: bool = False,
238
+ ) -> None:
239
+ """Construct a new async AsyncChunkr client instance.
240
+
241
+ This automatically infers the `api_key` argument from the `CHUNKR_API_KEY` environment variable if it is not provided.
242
+ """
243
+ if api_key is None:
244
+ api_key = os.environ.get("CHUNKR_API_KEY")
245
+ if api_key is None:
246
+ raise ChunkrError(
247
+ "The api_key client option must be set either by passing api_key to the client or by setting the CHUNKR_API_KEY environment variable"
248
+ )
249
+ self.api_key = api_key
250
+
251
+ if base_url is None:
252
+ base_url = os.environ.get("CHUNKR_BASE_URL")
253
+ if base_url is None:
254
+ base_url = f"https://api.chunkr.ai/api/v1/"
255
+
256
+ super().__init__(
257
+ version=__version__,
258
+ base_url=base_url,
259
+ max_retries=max_retries,
260
+ timeout=timeout,
261
+ http_client=http_client,
262
+ custom_headers=default_headers,
263
+ custom_query=default_query,
264
+ _strict_response_validation=_strict_response_validation,
265
+ )
266
+
267
+ self.task = task.AsyncTaskResource(self)
268
+ self.health = health.AsyncHealthResource(self)
269
+ self.with_raw_response = AsyncChunkrWithRawResponse(self)
270
+ self.with_streaming_response = AsyncChunkrWithStreamedResponse(self)
271
+
272
+ @property
273
+ @override
274
+ def qs(self) -> Querystring:
275
+ return Querystring(array_format="comma")
276
+
277
+ @property
278
+ @override
279
+ def auth_headers(self) -> dict[str, str]:
280
+ api_key = self.api_key
281
+ return {"Authorization": api_key}
282
+
283
+ @property
284
+ @override
285
+ def default_headers(self) -> dict[str, str | Omit]:
286
+ return {
287
+ **super().default_headers,
288
+ "X-Stainless-Async": f"async:{get_async_library()}",
289
+ **self._custom_headers,
290
+ }
291
+
292
+ def copy(
293
+ self,
294
+ *,
295
+ api_key: str | None = None,
296
+ base_url: str | httpx.URL | None = None,
297
+ timeout: float | Timeout | None | NotGiven = NOT_GIVEN,
298
+ http_client: httpx.AsyncClient | None = None,
299
+ max_retries: int | NotGiven = NOT_GIVEN,
300
+ default_headers: Mapping[str, str] | None = None,
301
+ set_default_headers: Mapping[str, str] | None = None,
302
+ default_query: Mapping[str, object] | None = None,
303
+ set_default_query: Mapping[str, object] | None = None,
304
+ _extra_kwargs: Mapping[str, Any] = {},
305
+ ) -> Self:
306
+ """
307
+ Create a new client instance re-using the same options given to the current client with optional overriding.
308
+ """
309
+ if default_headers is not None and set_default_headers is not None:
310
+ raise ValueError("The `default_headers` and `set_default_headers` arguments are mutually exclusive")
311
+
312
+ if default_query is not None and set_default_query is not None:
313
+ raise ValueError("The `default_query` and `set_default_query` arguments are mutually exclusive")
314
+
315
+ headers = self._custom_headers
316
+ if default_headers is not None:
317
+ headers = {**headers, **default_headers}
318
+ elif set_default_headers is not None:
319
+ headers = set_default_headers
320
+
321
+ params = self._custom_query
322
+ if default_query is not None:
323
+ params = {**params, **default_query}
324
+ elif set_default_query is not None:
325
+ params = set_default_query
326
+
327
+ http_client = http_client or self._client
328
+ return self.__class__(
329
+ api_key=api_key or self.api_key,
330
+ base_url=base_url or self.base_url,
331
+ timeout=self.timeout if isinstance(timeout, NotGiven) else timeout,
332
+ http_client=http_client,
333
+ max_retries=max_retries if is_given(max_retries) else self.max_retries,
334
+ default_headers=headers,
335
+ default_query=params,
336
+ **_extra_kwargs,
337
+ )
338
+
339
+ # Alias for `copy` for nicer inline usage, e.g.
340
+ # client.with_options(timeout=10).foo.create(...)
341
+ with_options = copy
342
+
343
+ @override
344
+ def _make_status_error(
345
+ self,
346
+ err_msg: str,
347
+ *,
348
+ body: object,
349
+ response: httpx.Response,
350
+ ) -> APIStatusError:
351
+ if response.status_code == 400:
352
+ return _exceptions.BadRequestError(err_msg, response=response, body=body)
353
+
354
+ if response.status_code == 401:
355
+ return _exceptions.AuthenticationError(err_msg, response=response, body=body)
356
+
357
+ if response.status_code == 403:
358
+ return _exceptions.PermissionDeniedError(err_msg, response=response, body=body)
359
+
360
+ if response.status_code == 404:
361
+ return _exceptions.NotFoundError(err_msg, response=response, body=body)
362
+
363
+ if response.status_code == 409:
364
+ return _exceptions.ConflictError(err_msg, response=response, body=body)
365
+
366
+ if response.status_code == 422:
367
+ return _exceptions.UnprocessableEntityError(err_msg, response=response, body=body)
368
+
369
+ if response.status_code == 429:
370
+ return _exceptions.RateLimitError(err_msg, response=response, body=body)
371
+
372
+ if response.status_code >= 500:
373
+ return _exceptions.InternalServerError(err_msg, response=response, body=body)
374
+ return APIStatusError(err_msg, response=response, body=body)
375
+
376
+
377
+ class ChunkrWithRawResponse:
378
+ def __init__(self, client: Chunkr) -> None:
379
+ self.task = task.TaskResourceWithRawResponse(client.task)
380
+ self.health = health.HealthResourceWithRawResponse(client.health)
381
+
382
+
383
+ class AsyncChunkrWithRawResponse:
384
+ def __init__(self, client: AsyncChunkr) -> None:
385
+ self.task = task.AsyncTaskResourceWithRawResponse(client.task)
386
+ self.health = health.AsyncHealthResourceWithRawResponse(client.health)
387
+
388
+
389
+ class ChunkrWithStreamedResponse:
390
+ def __init__(self, client: Chunkr) -> None:
391
+ self.task = task.TaskResourceWithStreamingResponse(client.task)
392
+ self.health = health.HealthResourceWithStreamingResponse(client.health)
393
+
394
+
395
+ class AsyncChunkrWithStreamedResponse:
396
+ def __init__(self, client: AsyncChunkr) -> None:
397
+ self.task = task.AsyncTaskResourceWithStreamingResponse(client.task)
398
+ self.health = health.AsyncHealthResourceWithStreamingResponse(client.health)
399
+
400
+
401
+ Client = Chunkr
402
+
403
+ AsyncClient = AsyncChunkr
chunkr_ai/_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 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, *, deep: bool = False) -> _ModelT:
122
+ if PYDANTIC_V2:
123
+ return model.model_copy(deep=deep)
124
+ return model.copy(deep=deep) # 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: IncEx | None = None,
137
+ exclude_unset: bool = False,
138
+ exclude_defaults: bool = False,
139
+ warnings: bool = True,
140
+ mode: Literal["json", "python"] = "python",
141
+ ) -> dict[str, Any]:
142
+ if PYDANTIC_V2 or hasattr(model, "model_dump"):
143
+ return model.model_dump(
144
+ mode=mode,
145
+ exclude=exclude,
146
+ exclude_unset=exclude_unset,
147
+ exclude_defaults=exclude_defaults,
148
+ # warnings are not supported in Pydantic v1
149
+ warnings=warnings if PYDANTIC_V2 else True,
150
+ )
151
+ return cast(
152
+ "dict[str, Any]",
153
+ model.dict( # pyright: ignore[reportDeprecated, reportUnnecessaryCast]
154
+ exclude=exclude,
155
+ exclude_unset=exclude_unset,
156
+ exclude_defaults=exclude_defaults,
157
+ ),
158
+ )
159
+
160
+
161
+ def model_parse(model: type[_ModelT], data: Any) -> _ModelT:
162
+ if PYDANTIC_V2:
163
+ return model.model_validate(data)
164
+ return model.parse_obj(data) # pyright: ignore[reportDeprecated]
165
+
166
+
167
+ # generic models
168
+ if TYPE_CHECKING:
169
+
170
+ class GenericModel(pydantic.BaseModel): ...
171
+
172
+ else:
173
+ if PYDANTIC_V2:
174
+ # there no longer needs to be a distinction in v2 but
175
+ # we still have to create our own subclass to avoid
176
+ # inconsistent MRO ordering errors
177
+ class GenericModel(pydantic.BaseModel): ...
178
+
179
+ else:
180
+ import pydantic.generics
181
+
182
+ class GenericModel(pydantic.generics.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