aiinbx 0.7.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.

Potentially problematic release.


This version of aiinbx might be problematic. Click here for more details.

Files changed (64) hide show
  1. aiinbx/__init__.py +92 -0
  2. aiinbx/_base_client.py +1995 -0
  3. aiinbx/_client.py +422 -0
  4. aiinbx/_compat.py +219 -0
  5. aiinbx/_constants.py +14 -0
  6. aiinbx/_exceptions.py +108 -0
  7. aiinbx/_files.py +123 -0
  8. aiinbx/_models.py +835 -0
  9. aiinbx/_qs.py +150 -0
  10. aiinbx/_resource.py +43 -0
  11. aiinbx/_response.py +830 -0
  12. aiinbx/_streaming.py +331 -0
  13. aiinbx/_types.py +260 -0
  14. aiinbx/_utils/__init__.py +64 -0
  15. aiinbx/_utils/_compat.py +45 -0
  16. aiinbx/_utils/_datetime_parse.py +136 -0
  17. aiinbx/_utils/_logs.py +25 -0
  18. aiinbx/_utils/_proxy.py +65 -0
  19. aiinbx/_utils/_reflection.py +42 -0
  20. aiinbx/_utils/_resources_proxy.py +24 -0
  21. aiinbx/_utils/_streams.py +12 -0
  22. aiinbx/_utils/_sync.py +86 -0
  23. aiinbx/_utils/_transform.py +457 -0
  24. aiinbx/_utils/_typing.py +156 -0
  25. aiinbx/_utils/_utils.py +421 -0
  26. aiinbx/_version.py +4 -0
  27. aiinbx/lib/.keep +4 -0
  28. aiinbx/py.typed +0 -0
  29. aiinbx/resources/__init__.py +64 -0
  30. aiinbx/resources/domains.py +455 -0
  31. aiinbx/resources/emails.py +451 -0
  32. aiinbx/resources/meta.py +147 -0
  33. aiinbx/resources/threads.py +468 -0
  34. aiinbx/resources/webhooks.py +34 -0
  35. aiinbx/types/__init__.py +35 -0
  36. aiinbx/types/domain_create_params.py +11 -0
  37. aiinbx/types/domain_create_response.py +26 -0
  38. aiinbx/types/domain_delete_response.py +11 -0
  39. aiinbx/types/domain_list_response.py +50 -0
  40. aiinbx/types/domain_retrieve_response.py +46 -0
  41. aiinbx/types/domain_verify_response.py +149 -0
  42. aiinbx/types/email_reply_params.py +47 -0
  43. aiinbx/types/email_reply_response.py +15 -0
  44. aiinbx/types/email_retrieve_response.py +90 -0
  45. aiinbx/types/email_send_params.py +53 -0
  46. aiinbx/types/email_send_response.py +15 -0
  47. aiinbx/types/inbound_email_received_webhook_event.py +113 -0
  48. aiinbx/types/meta_webhooks_schema_response.py +298 -0
  49. aiinbx/types/outbound_email_bounced_webhook_event.py +44 -0
  50. aiinbx/types/outbound_email_clicked_webhook_event.py +36 -0
  51. aiinbx/types/outbound_email_complained_webhook_event.py +36 -0
  52. aiinbx/types/outbound_email_delivered_webhook_event.py +36 -0
  53. aiinbx/types/outbound_email_opened_webhook_event.py +32 -0
  54. aiinbx/types/outbound_email_rejected_webhook_event.py +30 -0
  55. aiinbx/types/thread_forward_params.py +43 -0
  56. aiinbx/types/thread_forward_response.py +15 -0
  57. aiinbx/types/thread_retrieve_response.py +100 -0
  58. aiinbx/types/thread_search_params.py +61 -0
  59. aiinbx/types/thread_search_response.py +43 -0
  60. aiinbx/types/unwrap_webhook_event.py +24 -0
  61. aiinbx-0.7.0.dist-info/METADATA +398 -0
  62. aiinbx-0.7.0.dist-info/RECORD +64 -0
  63. aiinbx-0.7.0.dist-info/WHEEL +4 -0
  64. aiinbx-0.7.0.dist-info/licenses/LICENSE +201 -0
aiinbx/_client.py ADDED
@@ -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, 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 meta, emails, domains, threads, webhooks
25
+ from ._streaming import Stream as Stream, AsyncStream as AsyncStream
26
+ from ._exceptions import AIInbxError, APIStatusError
27
+ from ._base_client import (
28
+ DEFAULT_MAX_RETRIES,
29
+ SyncAPIClient,
30
+ AsyncAPIClient,
31
+ )
32
+
33
+ __all__ = ["Timeout", "Transport", "ProxiesTypes", "RequestOptions", "AIInbx", "AsyncAIInbx", "Client", "AsyncClient"]
34
+
35
+
36
+ class AIInbx(SyncAPIClient):
37
+ threads: threads.ThreadsResource
38
+ emails: emails.EmailsResource
39
+ domains: domains.DomainsResource
40
+ webhooks: webhooks.WebhooksResource
41
+ meta: meta.MetaResource
42
+ with_raw_response: AIInbxWithRawResponse
43
+ with_streaming_response: AIInbxWithStreamedResponse
44
+
45
+ # client options
46
+ api_key: str
47
+
48
+ def __init__(
49
+ self,
50
+ *,
51
+ api_key: str | None = None,
52
+ base_url: str | httpx.URL | None = None,
53
+ timeout: float | Timeout | None | NotGiven = not_given,
54
+ max_retries: int = DEFAULT_MAX_RETRIES,
55
+ default_headers: Mapping[str, str] | None = None,
56
+ default_query: Mapping[str, object] | None = None,
57
+ # Configure a custom httpx client.
58
+ # We provide a `DefaultHttpxClient` class that you can pass to retain the default values we use for `limits`, `timeout` & `follow_redirects`.
59
+ # See the [httpx documentation](https://www.python-httpx.org/api/#client) for more details.
60
+ http_client: httpx.Client | None = None,
61
+ # Enable or disable schema validation for data returned by the API.
62
+ # When enabled an error APIResponseValidationError is raised
63
+ # if the API responds with invalid data for the expected schema.
64
+ #
65
+ # This parameter may be removed or changed in the future.
66
+ # If you rely on this feature, please open a GitHub issue
67
+ # outlining your use-case to help us decide if it should be
68
+ # part of our public interface in the future.
69
+ _strict_response_validation: bool = False,
70
+ ) -> None:
71
+ """Construct a new synchronous AIInbx client instance.
72
+
73
+ This automatically infers the `api_key` argument from the `AI_INBX_API_KEY` environment variable if it is not provided.
74
+ """
75
+ if api_key is None:
76
+ api_key = os.environ.get("AI_INBX_API_KEY")
77
+ if api_key is None:
78
+ raise AIInbxError(
79
+ "The api_key client option must be set either by passing api_key to the client or by setting the AI_INBX_API_KEY environment variable"
80
+ )
81
+ self.api_key = api_key
82
+
83
+ if base_url is None:
84
+ base_url = os.environ.get("AI_INBX_BASE_URL")
85
+ if base_url is None:
86
+ base_url = f"https://aiinbx.com/api/v1"
87
+
88
+ super().__init__(
89
+ version=__version__,
90
+ base_url=base_url,
91
+ max_retries=max_retries,
92
+ timeout=timeout,
93
+ http_client=http_client,
94
+ custom_headers=default_headers,
95
+ custom_query=default_query,
96
+ _strict_response_validation=_strict_response_validation,
97
+ )
98
+
99
+ self.threads = threads.ThreadsResource(self)
100
+ self.emails = emails.EmailsResource(self)
101
+ self.domains = domains.DomainsResource(self)
102
+ self.webhooks = webhooks.WebhooksResource(self)
103
+ self.meta = meta.MetaResource(self)
104
+ self.with_raw_response = AIInbxWithRawResponse(self)
105
+ self.with_streaming_response = AIInbxWithStreamedResponse(self)
106
+
107
+ @property
108
+ @override
109
+ def qs(self) -> Querystring:
110
+ return Querystring(array_format="comma")
111
+
112
+ @property
113
+ @override
114
+ def auth_headers(self) -> dict[str, str]:
115
+ api_key = self.api_key
116
+ return {"Authorization": f"Bearer {api_key}"}
117
+
118
+ @property
119
+ @override
120
+ def default_headers(self) -> dict[str, str | Omit]:
121
+ return {
122
+ **super().default_headers,
123
+ "X-Stainless-Async": "false",
124
+ **self._custom_headers,
125
+ }
126
+
127
+ def copy(
128
+ self,
129
+ *,
130
+ api_key: str | None = None,
131
+ base_url: str | httpx.URL | None = None,
132
+ timeout: float | Timeout | None | NotGiven = not_given,
133
+ http_client: httpx.Client | None = None,
134
+ max_retries: int | NotGiven = not_given,
135
+ default_headers: Mapping[str, str] | None = None,
136
+ set_default_headers: Mapping[str, str] | None = None,
137
+ default_query: Mapping[str, object] | None = None,
138
+ set_default_query: Mapping[str, object] | None = None,
139
+ _extra_kwargs: Mapping[str, Any] = {},
140
+ ) -> Self:
141
+ """
142
+ Create a new client instance re-using the same options given to the current client with optional overriding.
143
+ """
144
+ if default_headers is not None and set_default_headers is not None:
145
+ raise ValueError("The `default_headers` and `set_default_headers` arguments are mutually exclusive")
146
+
147
+ if default_query is not None and set_default_query is not None:
148
+ raise ValueError("The `default_query` and `set_default_query` arguments are mutually exclusive")
149
+
150
+ headers = self._custom_headers
151
+ if default_headers is not None:
152
+ headers = {**headers, **default_headers}
153
+ elif set_default_headers is not None:
154
+ headers = set_default_headers
155
+
156
+ params = self._custom_query
157
+ if default_query is not None:
158
+ params = {**params, **default_query}
159
+ elif set_default_query is not None:
160
+ params = set_default_query
161
+
162
+ http_client = http_client or self._client
163
+ return self.__class__(
164
+ api_key=api_key or self.api_key,
165
+ base_url=base_url or self.base_url,
166
+ timeout=self.timeout if isinstance(timeout, NotGiven) else timeout,
167
+ http_client=http_client,
168
+ max_retries=max_retries if is_given(max_retries) else self.max_retries,
169
+ default_headers=headers,
170
+ default_query=params,
171
+ **_extra_kwargs,
172
+ )
173
+
174
+ # Alias for `copy` for nicer inline usage, e.g.
175
+ # client.with_options(timeout=10).foo.create(...)
176
+ with_options = copy
177
+
178
+ @override
179
+ def _make_status_error(
180
+ self,
181
+ err_msg: str,
182
+ *,
183
+ body: object,
184
+ response: httpx.Response,
185
+ ) -> APIStatusError:
186
+ if response.status_code == 400:
187
+ return _exceptions.BadRequestError(err_msg, response=response, body=body)
188
+
189
+ if response.status_code == 401:
190
+ return _exceptions.AuthenticationError(err_msg, response=response, body=body)
191
+
192
+ if response.status_code == 403:
193
+ return _exceptions.PermissionDeniedError(err_msg, response=response, body=body)
194
+
195
+ if response.status_code == 404:
196
+ return _exceptions.NotFoundError(err_msg, response=response, body=body)
197
+
198
+ if response.status_code == 409:
199
+ return _exceptions.ConflictError(err_msg, response=response, body=body)
200
+
201
+ if response.status_code == 422:
202
+ return _exceptions.UnprocessableEntityError(err_msg, response=response, body=body)
203
+
204
+ if response.status_code == 429:
205
+ return _exceptions.RateLimitError(err_msg, response=response, body=body)
206
+
207
+ if response.status_code >= 500:
208
+ return _exceptions.InternalServerError(err_msg, response=response, body=body)
209
+ return APIStatusError(err_msg, response=response, body=body)
210
+
211
+
212
+ class AsyncAIInbx(AsyncAPIClient):
213
+ threads: threads.AsyncThreadsResource
214
+ emails: emails.AsyncEmailsResource
215
+ domains: domains.AsyncDomainsResource
216
+ webhooks: webhooks.AsyncWebhooksResource
217
+ meta: meta.AsyncMetaResource
218
+ with_raw_response: AsyncAIInbxWithRawResponse
219
+ with_streaming_response: AsyncAIInbxWithStreamedResponse
220
+
221
+ # client options
222
+ api_key: str
223
+
224
+ def __init__(
225
+ self,
226
+ *,
227
+ api_key: str | None = None,
228
+ base_url: str | httpx.URL | None = None,
229
+ timeout: float | Timeout | None | NotGiven = not_given,
230
+ max_retries: int = DEFAULT_MAX_RETRIES,
231
+ default_headers: Mapping[str, str] | None = None,
232
+ default_query: Mapping[str, object] | None = None,
233
+ # Configure a custom httpx client.
234
+ # We provide a `DefaultAsyncHttpxClient` class that you can pass to retain the default values we use for `limits`, `timeout` & `follow_redirects`.
235
+ # See the [httpx documentation](https://www.python-httpx.org/api/#asyncclient) for more details.
236
+ http_client: httpx.AsyncClient | None = None,
237
+ # Enable or disable schema validation for data returned by the API.
238
+ # When enabled an error APIResponseValidationError is raised
239
+ # if the API responds with invalid data for the expected schema.
240
+ #
241
+ # This parameter may be removed or changed in the future.
242
+ # If you rely on this feature, please open a GitHub issue
243
+ # outlining your use-case to help us decide if it should be
244
+ # part of our public interface in the future.
245
+ _strict_response_validation: bool = False,
246
+ ) -> None:
247
+ """Construct a new async AsyncAIInbx client instance.
248
+
249
+ This automatically infers the `api_key` argument from the `AI_INBX_API_KEY` environment variable if it is not provided.
250
+ """
251
+ if api_key is None:
252
+ api_key = os.environ.get("AI_INBX_API_KEY")
253
+ if api_key is None:
254
+ raise AIInbxError(
255
+ "The api_key client option must be set either by passing api_key to the client or by setting the AI_INBX_API_KEY environment variable"
256
+ )
257
+ self.api_key = api_key
258
+
259
+ if base_url is None:
260
+ base_url = os.environ.get("AI_INBX_BASE_URL")
261
+ if base_url is None:
262
+ base_url = f"https://aiinbx.com/api/v1"
263
+
264
+ super().__init__(
265
+ version=__version__,
266
+ base_url=base_url,
267
+ max_retries=max_retries,
268
+ timeout=timeout,
269
+ http_client=http_client,
270
+ custom_headers=default_headers,
271
+ custom_query=default_query,
272
+ _strict_response_validation=_strict_response_validation,
273
+ )
274
+
275
+ self.threads = threads.AsyncThreadsResource(self)
276
+ self.emails = emails.AsyncEmailsResource(self)
277
+ self.domains = domains.AsyncDomainsResource(self)
278
+ self.webhooks = webhooks.AsyncWebhooksResource(self)
279
+ self.meta = meta.AsyncMetaResource(self)
280
+ self.with_raw_response = AsyncAIInbxWithRawResponse(self)
281
+ self.with_streaming_response = AsyncAIInbxWithStreamedResponse(self)
282
+
283
+ @property
284
+ @override
285
+ def qs(self) -> Querystring:
286
+ return Querystring(array_format="comma")
287
+
288
+ @property
289
+ @override
290
+ def auth_headers(self) -> dict[str, str]:
291
+ api_key = self.api_key
292
+ return {"Authorization": f"Bearer {api_key}"}
293
+
294
+ @property
295
+ @override
296
+ def default_headers(self) -> dict[str, str | Omit]:
297
+ return {
298
+ **super().default_headers,
299
+ "X-Stainless-Async": f"async:{get_async_library()}",
300
+ **self._custom_headers,
301
+ }
302
+
303
+ def copy(
304
+ self,
305
+ *,
306
+ api_key: str | None = None,
307
+ base_url: str | httpx.URL | None = None,
308
+ timeout: float | Timeout | None | NotGiven = not_given,
309
+ http_client: httpx.AsyncClient | None = None,
310
+ max_retries: int | NotGiven = not_given,
311
+ default_headers: Mapping[str, str] | None = None,
312
+ set_default_headers: Mapping[str, str] | None = None,
313
+ default_query: Mapping[str, object] | None = None,
314
+ set_default_query: Mapping[str, object] | None = None,
315
+ _extra_kwargs: Mapping[str, Any] = {},
316
+ ) -> Self:
317
+ """
318
+ Create a new client instance re-using the same options given to the current client with optional overriding.
319
+ """
320
+ if default_headers is not None and set_default_headers is not None:
321
+ raise ValueError("The `default_headers` and `set_default_headers` arguments are mutually exclusive")
322
+
323
+ if default_query is not None and set_default_query is not None:
324
+ raise ValueError("The `default_query` and `set_default_query` arguments are mutually exclusive")
325
+
326
+ headers = self._custom_headers
327
+ if default_headers is not None:
328
+ headers = {**headers, **default_headers}
329
+ elif set_default_headers is not None:
330
+ headers = set_default_headers
331
+
332
+ params = self._custom_query
333
+ if default_query is not None:
334
+ params = {**params, **default_query}
335
+ elif set_default_query is not None:
336
+ params = set_default_query
337
+
338
+ http_client = http_client or self._client
339
+ return self.__class__(
340
+ api_key=api_key or self.api_key,
341
+ base_url=base_url or self.base_url,
342
+ timeout=self.timeout if isinstance(timeout, NotGiven) else timeout,
343
+ http_client=http_client,
344
+ max_retries=max_retries if is_given(max_retries) else self.max_retries,
345
+ default_headers=headers,
346
+ default_query=params,
347
+ **_extra_kwargs,
348
+ )
349
+
350
+ # Alias for `copy` for nicer inline usage, e.g.
351
+ # client.with_options(timeout=10).foo.create(...)
352
+ with_options = copy
353
+
354
+ @override
355
+ def _make_status_error(
356
+ self,
357
+ err_msg: str,
358
+ *,
359
+ body: object,
360
+ response: httpx.Response,
361
+ ) -> APIStatusError:
362
+ if response.status_code == 400:
363
+ return _exceptions.BadRequestError(err_msg, response=response, body=body)
364
+
365
+ if response.status_code == 401:
366
+ return _exceptions.AuthenticationError(err_msg, response=response, body=body)
367
+
368
+ if response.status_code == 403:
369
+ return _exceptions.PermissionDeniedError(err_msg, response=response, body=body)
370
+
371
+ if response.status_code == 404:
372
+ return _exceptions.NotFoundError(err_msg, response=response, body=body)
373
+
374
+ if response.status_code == 409:
375
+ return _exceptions.ConflictError(err_msg, response=response, body=body)
376
+
377
+ if response.status_code == 422:
378
+ return _exceptions.UnprocessableEntityError(err_msg, response=response, body=body)
379
+
380
+ if response.status_code == 429:
381
+ return _exceptions.RateLimitError(err_msg, response=response, body=body)
382
+
383
+ if response.status_code >= 500:
384
+ return _exceptions.InternalServerError(err_msg, response=response, body=body)
385
+ return APIStatusError(err_msg, response=response, body=body)
386
+
387
+
388
+ class AIInbxWithRawResponse:
389
+ def __init__(self, client: AIInbx) -> None:
390
+ self.threads = threads.ThreadsResourceWithRawResponse(client.threads)
391
+ self.emails = emails.EmailsResourceWithRawResponse(client.emails)
392
+ self.domains = domains.DomainsResourceWithRawResponse(client.domains)
393
+ self.meta = meta.MetaResourceWithRawResponse(client.meta)
394
+
395
+
396
+ class AsyncAIInbxWithRawResponse:
397
+ def __init__(self, client: AsyncAIInbx) -> None:
398
+ self.threads = threads.AsyncThreadsResourceWithRawResponse(client.threads)
399
+ self.emails = emails.AsyncEmailsResourceWithRawResponse(client.emails)
400
+ self.domains = domains.AsyncDomainsResourceWithRawResponse(client.domains)
401
+ self.meta = meta.AsyncMetaResourceWithRawResponse(client.meta)
402
+
403
+
404
+ class AIInbxWithStreamedResponse:
405
+ def __init__(self, client: AIInbx) -> None:
406
+ self.threads = threads.ThreadsResourceWithStreamingResponse(client.threads)
407
+ self.emails = emails.EmailsResourceWithStreamingResponse(client.emails)
408
+ self.domains = domains.DomainsResourceWithStreamingResponse(client.domains)
409
+ self.meta = meta.MetaResourceWithStreamingResponse(client.meta)
410
+
411
+
412
+ class AsyncAIInbxWithStreamedResponse:
413
+ def __init__(self, client: AsyncAIInbx) -> None:
414
+ self.threads = threads.AsyncThreadsResourceWithStreamingResponse(client.threads)
415
+ self.emails = emails.AsyncEmailsResourceWithStreamingResponse(client.emails)
416
+ self.domains = domains.AsyncDomainsResourceWithStreamingResponse(client.domains)
417
+ self.meta = meta.AsyncMetaResourceWithStreamingResponse(client.meta)
418
+
419
+
420
+ Client = AIInbx
421
+
422
+ AsyncClient = AsyncAIInbx
aiinbx/_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
aiinbx/_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