isaacus 0.1.0a1__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.
- isaacus/__init__.py +84 -0
- isaacus/_base_client.py +1969 -0
- isaacus/_client.py +397 -0
- isaacus/_compat.py +219 -0
- isaacus/_constants.py +14 -0
- isaacus/_exceptions.py +108 -0
- isaacus/_files.py +123 -0
- isaacus/_models.py +801 -0
- isaacus/_qs.py +150 -0
- isaacus/_resource.py +43 -0
- isaacus/_response.py +830 -0
- isaacus/_streaming.py +333 -0
- isaacus/_types.py +217 -0
- isaacus/_utils/__init__.py +57 -0
- isaacus/_utils/_logs.py +25 -0
- isaacus/_utils/_proxy.py +62 -0
- isaacus/_utils/_reflection.py +42 -0
- isaacus/_utils/_streams.py +12 -0
- isaacus/_utils/_sync.py +86 -0
- isaacus/_utils/_transform.py +402 -0
- isaacus/_utils/_typing.py +149 -0
- isaacus/_utils/_utils.py +414 -0
- isaacus/_version.py +4 -0
- isaacus/lib/.keep +4 -0
- isaacus/py.typed +0 -0
- isaacus/resources/__init__.py +19 -0
- isaacus/resources/classifications/__init__.py +33 -0
- isaacus/resources/classifications/classifications.py +102 -0
- isaacus/resources/classifications/universal.py +263 -0
- isaacus/types/__init__.py +3 -0
- isaacus/types/classifications/__init__.py +6 -0
- isaacus/types/classifications/universal_classification.py +55 -0
- isaacus/types/classifications/universal_create_params.py +64 -0
- isaacus-0.1.0a1.dist-info/METADATA +391 -0
- isaacus-0.1.0a1.dist-info/RECORD +37 -0
- isaacus-0.1.0a1.dist-info/WHEEL +4 -0
- isaacus-0.1.0a1.dist-info/licenses/LICENSE +201 -0
isaacus/_client.py
ADDED
@@ -0,0 +1,397 @@
|
|
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 (
|
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 IsaacusError, APIStatusError
|
29
|
+
from ._base_client import (
|
30
|
+
DEFAULT_MAX_RETRIES,
|
31
|
+
SyncAPIClient,
|
32
|
+
AsyncAPIClient,
|
33
|
+
)
|
34
|
+
from .resources.classifications import classifications
|
35
|
+
|
36
|
+
__all__ = ["Timeout", "Transport", "ProxiesTypes", "RequestOptions", "Isaacus", "AsyncIsaacus", "Client", "AsyncClient"]
|
37
|
+
|
38
|
+
|
39
|
+
class Isaacus(SyncAPIClient):
|
40
|
+
classifications: classifications.ClassificationsResource
|
41
|
+
with_raw_response: IsaacusWithRawResponse
|
42
|
+
with_streaming_response: IsaacusWithStreamedResponse
|
43
|
+
|
44
|
+
# client options
|
45
|
+
api_key: str
|
46
|
+
|
47
|
+
def __init__(
|
48
|
+
self,
|
49
|
+
*,
|
50
|
+
api_key: str | None = None,
|
51
|
+
base_url: str | httpx.URL | None = None,
|
52
|
+
timeout: Union[float, Timeout, None, NotGiven] = NOT_GIVEN,
|
53
|
+
max_retries: int = DEFAULT_MAX_RETRIES,
|
54
|
+
default_headers: Mapping[str, str] | None = None,
|
55
|
+
default_query: Mapping[str, object] | None = None,
|
56
|
+
# Configure a custom httpx client.
|
57
|
+
# We provide a `DefaultHttpxClient` class that you can pass to retain the default values we use for `limits`, `timeout` & `follow_redirects`.
|
58
|
+
# See the [httpx documentation](https://www.python-httpx.org/api/#client) for more details.
|
59
|
+
http_client: httpx.Client | None = None,
|
60
|
+
# Enable or disable schema validation for data returned by the API.
|
61
|
+
# When enabled an error APIResponseValidationError is raised
|
62
|
+
# if the API responds with invalid data for the expected schema.
|
63
|
+
#
|
64
|
+
# This parameter may be removed or changed in the future.
|
65
|
+
# If you rely on this feature, please open a GitHub issue
|
66
|
+
# outlining your use-case to help us decide if it should be
|
67
|
+
# part of our public interface in the future.
|
68
|
+
_strict_response_validation: bool = False,
|
69
|
+
) -> None:
|
70
|
+
"""Construct a new synchronous Isaacus client instance.
|
71
|
+
|
72
|
+
This automatically infers the `api_key` argument from the `ISAACUS_API_KEY` environment variable if it is not provided.
|
73
|
+
"""
|
74
|
+
if api_key is None:
|
75
|
+
api_key = os.environ.get("ISAACUS_API_KEY")
|
76
|
+
if api_key is None:
|
77
|
+
raise IsaacusError(
|
78
|
+
"The api_key client option must be set either by passing api_key to the client or by setting the ISAACUS_API_KEY environment variable"
|
79
|
+
)
|
80
|
+
self.api_key = api_key
|
81
|
+
|
82
|
+
if base_url is None:
|
83
|
+
base_url = os.environ.get("ISAACUS_BASE_URL")
|
84
|
+
if base_url is None:
|
85
|
+
base_url = f"https://api.isaacus.com/v1"
|
86
|
+
|
87
|
+
super().__init__(
|
88
|
+
version=__version__,
|
89
|
+
base_url=base_url,
|
90
|
+
max_retries=max_retries,
|
91
|
+
timeout=timeout,
|
92
|
+
http_client=http_client,
|
93
|
+
custom_headers=default_headers,
|
94
|
+
custom_query=default_query,
|
95
|
+
_strict_response_validation=_strict_response_validation,
|
96
|
+
)
|
97
|
+
|
98
|
+
self.classifications = classifications.ClassificationsResource(self)
|
99
|
+
self.with_raw_response = IsaacusWithRawResponse(self)
|
100
|
+
self.with_streaming_response = IsaacusWithStreamedResponse(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": f"Bearer {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 AsyncIsaacus(AsyncAPIClient):
|
208
|
+
classifications: classifications.AsyncClassificationsResource
|
209
|
+
with_raw_response: AsyncIsaacusWithRawResponse
|
210
|
+
with_streaming_response: AsyncIsaacusWithStreamedResponse
|
211
|
+
|
212
|
+
# client options
|
213
|
+
api_key: str
|
214
|
+
|
215
|
+
def __init__(
|
216
|
+
self,
|
217
|
+
*,
|
218
|
+
api_key: str | None = None,
|
219
|
+
base_url: str | httpx.URL | None = None,
|
220
|
+
timeout: Union[float, Timeout, None, NotGiven] = NOT_GIVEN,
|
221
|
+
max_retries: int = DEFAULT_MAX_RETRIES,
|
222
|
+
default_headers: Mapping[str, str] | None = None,
|
223
|
+
default_query: Mapping[str, object] | None = None,
|
224
|
+
# Configure a custom httpx client.
|
225
|
+
# We provide a `DefaultAsyncHttpxClient` class that you can pass to retain the default values we use for `limits`, `timeout` & `follow_redirects`.
|
226
|
+
# See the [httpx documentation](https://www.python-httpx.org/api/#asyncclient) for more details.
|
227
|
+
http_client: httpx.AsyncClient | None = None,
|
228
|
+
# Enable or disable schema validation for data returned by the API.
|
229
|
+
# When enabled an error APIResponseValidationError is raised
|
230
|
+
# if the API responds with invalid data for the expected schema.
|
231
|
+
#
|
232
|
+
# This parameter may be removed or changed in the future.
|
233
|
+
# If you rely on this feature, please open a GitHub issue
|
234
|
+
# outlining your use-case to help us decide if it should be
|
235
|
+
# part of our public interface in the future.
|
236
|
+
_strict_response_validation: bool = False,
|
237
|
+
) -> None:
|
238
|
+
"""Construct a new async AsyncIsaacus client instance.
|
239
|
+
|
240
|
+
This automatically infers the `api_key` argument from the `ISAACUS_API_KEY` environment variable if it is not provided.
|
241
|
+
"""
|
242
|
+
if api_key is None:
|
243
|
+
api_key = os.environ.get("ISAACUS_API_KEY")
|
244
|
+
if api_key is None:
|
245
|
+
raise IsaacusError(
|
246
|
+
"The api_key client option must be set either by passing api_key to the client or by setting the ISAACUS_API_KEY environment variable"
|
247
|
+
)
|
248
|
+
self.api_key = api_key
|
249
|
+
|
250
|
+
if base_url is None:
|
251
|
+
base_url = os.environ.get("ISAACUS_BASE_URL")
|
252
|
+
if base_url is None:
|
253
|
+
base_url = f"https://api.isaacus.com/v1"
|
254
|
+
|
255
|
+
super().__init__(
|
256
|
+
version=__version__,
|
257
|
+
base_url=base_url,
|
258
|
+
max_retries=max_retries,
|
259
|
+
timeout=timeout,
|
260
|
+
http_client=http_client,
|
261
|
+
custom_headers=default_headers,
|
262
|
+
custom_query=default_query,
|
263
|
+
_strict_response_validation=_strict_response_validation,
|
264
|
+
)
|
265
|
+
|
266
|
+
self.classifications = classifications.AsyncClassificationsResource(self)
|
267
|
+
self.with_raw_response = AsyncIsaacusWithRawResponse(self)
|
268
|
+
self.with_streaming_response = AsyncIsaacusWithStreamedResponse(self)
|
269
|
+
|
270
|
+
@property
|
271
|
+
@override
|
272
|
+
def qs(self) -> Querystring:
|
273
|
+
return Querystring(array_format="comma")
|
274
|
+
|
275
|
+
@property
|
276
|
+
@override
|
277
|
+
def auth_headers(self) -> dict[str, str]:
|
278
|
+
api_key = self.api_key
|
279
|
+
return {"Authorization": f"Bearer {api_key}"}
|
280
|
+
|
281
|
+
@property
|
282
|
+
@override
|
283
|
+
def default_headers(self) -> dict[str, str | Omit]:
|
284
|
+
return {
|
285
|
+
**super().default_headers,
|
286
|
+
"X-Stainless-Async": f"async:{get_async_library()}",
|
287
|
+
**self._custom_headers,
|
288
|
+
}
|
289
|
+
|
290
|
+
def copy(
|
291
|
+
self,
|
292
|
+
*,
|
293
|
+
api_key: str | None = None,
|
294
|
+
base_url: str | httpx.URL | None = None,
|
295
|
+
timeout: float | Timeout | None | NotGiven = NOT_GIVEN,
|
296
|
+
http_client: httpx.AsyncClient | None = None,
|
297
|
+
max_retries: int | NotGiven = NOT_GIVEN,
|
298
|
+
default_headers: Mapping[str, str] | None = None,
|
299
|
+
set_default_headers: Mapping[str, str] | None = None,
|
300
|
+
default_query: Mapping[str, object] | None = None,
|
301
|
+
set_default_query: Mapping[str, object] | None = None,
|
302
|
+
_extra_kwargs: Mapping[str, Any] = {},
|
303
|
+
) -> Self:
|
304
|
+
"""
|
305
|
+
Create a new client instance re-using the same options given to the current client with optional overriding.
|
306
|
+
"""
|
307
|
+
if default_headers is not None and set_default_headers is not None:
|
308
|
+
raise ValueError("The `default_headers` and `set_default_headers` arguments are mutually exclusive")
|
309
|
+
|
310
|
+
if default_query is not None and set_default_query is not None:
|
311
|
+
raise ValueError("The `default_query` and `set_default_query` arguments are mutually exclusive")
|
312
|
+
|
313
|
+
headers = self._custom_headers
|
314
|
+
if default_headers is not None:
|
315
|
+
headers = {**headers, **default_headers}
|
316
|
+
elif set_default_headers is not None:
|
317
|
+
headers = set_default_headers
|
318
|
+
|
319
|
+
params = self._custom_query
|
320
|
+
if default_query is not None:
|
321
|
+
params = {**params, **default_query}
|
322
|
+
elif set_default_query is not None:
|
323
|
+
params = set_default_query
|
324
|
+
|
325
|
+
http_client = http_client or self._client
|
326
|
+
return self.__class__(
|
327
|
+
api_key=api_key or self.api_key,
|
328
|
+
base_url=base_url or self.base_url,
|
329
|
+
timeout=self.timeout if isinstance(timeout, NotGiven) else timeout,
|
330
|
+
http_client=http_client,
|
331
|
+
max_retries=max_retries if is_given(max_retries) else self.max_retries,
|
332
|
+
default_headers=headers,
|
333
|
+
default_query=params,
|
334
|
+
**_extra_kwargs,
|
335
|
+
)
|
336
|
+
|
337
|
+
# Alias for `copy` for nicer inline usage, e.g.
|
338
|
+
# client.with_options(timeout=10).foo.create(...)
|
339
|
+
with_options = copy
|
340
|
+
|
341
|
+
@override
|
342
|
+
def _make_status_error(
|
343
|
+
self,
|
344
|
+
err_msg: str,
|
345
|
+
*,
|
346
|
+
body: object,
|
347
|
+
response: httpx.Response,
|
348
|
+
) -> APIStatusError:
|
349
|
+
if response.status_code == 400:
|
350
|
+
return _exceptions.BadRequestError(err_msg, response=response, body=body)
|
351
|
+
|
352
|
+
if response.status_code == 401:
|
353
|
+
return _exceptions.AuthenticationError(err_msg, response=response, body=body)
|
354
|
+
|
355
|
+
if response.status_code == 403:
|
356
|
+
return _exceptions.PermissionDeniedError(err_msg, response=response, body=body)
|
357
|
+
|
358
|
+
if response.status_code == 404:
|
359
|
+
return _exceptions.NotFoundError(err_msg, response=response, body=body)
|
360
|
+
|
361
|
+
if response.status_code == 409:
|
362
|
+
return _exceptions.ConflictError(err_msg, response=response, body=body)
|
363
|
+
|
364
|
+
if response.status_code == 422:
|
365
|
+
return _exceptions.UnprocessableEntityError(err_msg, response=response, body=body)
|
366
|
+
|
367
|
+
if response.status_code == 429:
|
368
|
+
return _exceptions.RateLimitError(err_msg, response=response, body=body)
|
369
|
+
|
370
|
+
if response.status_code >= 500:
|
371
|
+
return _exceptions.InternalServerError(err_msg, response=response, body=body)
|
372
|
+
return APIStatusError(err_msg, response=response, body=body)
|
373
|
+
|
374
|
+
|
375
|
+
class IsaacusWithRawResponse:
|
376
|
+
def __init__(self, client: Isaacus) -> None:
|
377
|
+
self.classifications = classifications.ClassificationsResourceWithRawResponse(client.classifications)
|
378
|
+
|
379
|
+
|
380
|
+
class AsyncIsaacusWithRawResponse:
|
381
|
+
def __init__(self, client: AsyncIsaacus) -> None:
|
382
|
+
self.classifications = classifications.AsyncClassificationsResourceWithRawResponse(client.classifications)
|
383
|
+
|
384
|
+
|
385
|
+
class IsaacusWithStreamedResponse:
|
386
|
+
def __init__(self, client: Isaacus) -> None:
|
387
|
+
self.classifications = classifications.ClassificationsResourceWithStreamingResponse(client.classifications)
|
388
|
+
|
389
|
+
|
390
|
+
class AsyncIsaacusWithStreamedResponse:
|
391
|
+
def __init__(self, client: AsyncIsaacus) -> None:
|
392
|
+
self.classifications = classifications.AsyncClassificationsResourceWithStreamingResponse(client.classifications)
|
393
|
+
|
394
|
+
|
395
|
+
Client = Isaacus
|
396
|
+
|
397
|
+
AsyncClient = AsyncIsaacus
|
isaacus/_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
|
isaacus/_constants.py
ADDED
@@ -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
|