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