codeset 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 (56) hide show
  1. codeset/__init__.py +90 -0
  2. codeset/_base_client.py +1985 -0
  3. codeset/_client.py +430 -0
  4. codeset/_compat.py +219 -0
  5. codeset/_constants.py +14 -0
  6. codeset/_exceptions.py +108 -0
  7. codeset/_files.py +123 -0
  8. codeset/_models.py +805 -0
  9. codeset/_qs.py +150 -0
  10. codeset/_resource.py +43 -0
  11. codeset/_response.py +830 -0
  12. codeset/_streaming.py +333 -0
  13. codeset/_types.py +219 -0
  14. codeset/_utils/__init__.py +57 -0
  15. codeset/_utils/_logs.py +25 -0
  16. codeset/_utils/_proxy.py +65 -0
  17. codeset/_utils/_reflection.py +42 -0
  18. codeset/_utils/_resources_proxy.py +24 -0
  19. codeset/_utils/_streams.py +12 -0
  20. codeset/_utils/_sync.py +86 -0
  21. codeset/_utils/_transform.py +447 -0
  22. codeset/_utils/_typing.py +151 -0
  23. codeset/_utils/_utils.py +422 -0
  24. codeset/_version.py +4 -0
  25. codeset/lib/.keep +4 -0
  26. codeset/py.typed +0 -0
  27. codeset/resources/__init__.py +47 -0
  28. codeset/resources/health.py +135 -0
  29. codeset/resources/samples.py +233 -0
  30. codeset/resources/sessions/__init__.py +33 -0
  31. codeset/resources/sessions/sessions.py +618 -0
  32. codeset/resources/sessions/verify.py +248 -0
  33. codeset/types/__init__.py +19 -0
  34. codeset/types/container_info.py +30 -0
  35. codeset/types/error_info.py +13 -0
  36. codeset/types/health_check_response.py +19 -0
  37. codeset/types/sample_download_params.py +14 -0
  38. codeset/types/sample_list_response.py +41 -0
  39. codeset/types/session.py +37 -0
  40. codeset/types/session_apply_diff_params.py +12 -0
  41. codeset/types/session_apply_diff_response.py +13 -0
  42. codeset/types/session_close_response.py +10 -0
  43. codeset/types/session_create_params.py +15 -0
  44. codeset/types/session_create_response.py +19 -0
  45. codeset/types/session_execute_command_params.py +15 -0
  46. codeset/types/session_execute_command_response.py +19 -0
  47. codeset/types/session_list_response.py +18 -0
  48. codeset/types/session_status.py +7 -0
  49. codeset/types/sessions/__init__.py +7 -0
  50. codeset/types/sessions/job_status.py +7 -0
  51. codeset/types/sessions/verify_start_response.py +19 -0
  52. codeset/types/sessions/verify_status_response.py +66 -0
  53. codeset-0.1.0a1.dist-info/METADATA +397 -0
  54. codeset-0.1.0a1.dist-info/RECORD +56 -0
  55. codeset-0.1.0a1.dist-info/WHEEL +4 -0
  56. codeset-0.1.0a1.dist-info/licenses/LICENSE +201 -0
codeset/_client.py ADDED
@@ -0,0 +1,430 @@
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
+ Headers,
17
+ Timeout,
18
+ NotGiven,
19
+ Transport,
20
+ ProxiesTypes,
21
+ RequestOptions,
22
+ )
23
+ from ._utils import is_given, get_async_library
24
+ from ._version import __version__
25
+ from .resources import health, samples
26
+ from ._streaming import Stream as Stream, AsyncStream as AsyncStream
27
+ from ._exceptions import APIStatusError
28
+ from ._base_client import (
29
+ DEFAULT_MAX_RETRIES,
30
+ SyncAPIClient,
31
+ AsyncAPIClient,
32
+ )
33
+ from .resources.sessions import sessions
34
+
35
+ __all__ = ["Timeout", "Transport", "ProxiesTypes", "RequestOptions", "Codeset", "AsyncCodeset", "Client", "AsyncClient"]
36
+
37
+
38
+ class Codeset(SyncAPIClient):
39
+ health: health.HealthResource
40
+ samples: samples.SamplesResource
41
+ sessions: sessions.SessionsResource
42
+ with_raw_response: CodesetWithRawResponse
43
+ with_streaming_response: CodesetWithStreamedResponse
44
+
45
+ # client options
46
+ api_key: str | None
47
+
48
+ def __init__(
49
+ self,
50
+ *,
51
+ api_key: str | None = None,
52
+ base_url: str | httpx.URL | None = None,
53
+ timeout: Union[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 Codeset client instance.
72
+
73
+ This automatically infers the `api_key` argument from the `CODESET_API_KEY` environment variable if it is not provided.
74
+ """
75
+ if api_key is None:
76
+ api_key = os.environ.get("CODESET_API_KEY")
77
+ self.api_key = api_key
78
+
79
+ if base_url is None:
80
+ base_url = os.environ.get("CODESET_BASE_URL")
81
+ if base_url is None:
82
+ base_url = f"/api/v1"
83
+
84
+ super().__init__(
85
+ version=__version__,
86
+ base_url=base_url,
87
+ max_retries=max_retries,
88
+ timeout=timeout,
89
+ http_client=http_client,
90
+ custom_headers=default_headers,
91
+ custom_query=default_query,
92
+ _strict_response_validation=_strict_response_validation,
93
+ )
94
+
95
+ self.health = health.HealthResource(self)
96
+ self.samples = samples.SamplesResource(self)
97
+ self.sessions = sessions.SessionsResource(self)
98
+ self.with_raw_response = CodesetWithRawResponse(self)
99
+ self.with_streaming_response = CodesetWithStreamedResponse(self)
100
+
101
+ @property
102
+ @override
103
+ def qs(self) -> Querystring:
104
+ return Querystring(array_format="comma")
105
+
106
+ @property
107
+ @override
108
+ def auth_headers(self) -> dict[str, str]:
109
+ api_key = self.api_key
110
+ if api_key is None:
111
+ return {}
112
+ return {"Authorization": f"Bearer {api_key}"}
113
+
114
+ @property
115
+ @override
116
+ def default_headers(self) -> dict[str, str | Omit]:
117
+ return {
118
+ **super().default_headers,
119
+ "X-Stainless-Async": "false",
120
+ **self._custom_headers,
121
+ }
122
+
123
+ @override
124
+ def _validate_headers(self, headers: Headers, custom_headers: Headers) -> None:
125
+ if self.api_key and headers.get("Authorization"):
126
+ return
127
+ if isinstance(custom_headers.get("Authorization"), Omit):
128
+ return
129
+
130
+ raise TypeError(
131
+ '"Could not resolve authentication method. Expected the api_key to be set. Or for the `Authorization` headers to be explicitly omitted"'
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 AsyncCodeset(AsyncAPIClient):
220
+ health: health.AsyncHealthResource
221
+ samples: samples.AsyncSamplesResource
222
+ sessions: sessions.AsyncSessionsResource
223
+ with_raw_response: AsyncCodesetWithRawResponse
224
+ with_streaming_response: AsyncCodesetWithStreamedResponse
225
+
226
+ # client options
227
+ api_key: str | None
228
+
229
+ def __init__(
230
+ self,
231
+ *,
232
+ api_key: str | None = None,
233
+ base_url: str | httpx.URL | None = None,
234
+ timeout: Union[float, Timeout, None, NotGiven] = NOT_GIVEN,
235
+ max_retries: int = DEFAULT_MAX_RETRIES,
236
+ default_headers: Mapping[str, str] | None = None,
237
+ default_query: Mapping[str, object] | None = None,
238
+ # Configure a custom httpx client.
239
+ # We provide a `DefaultAsyncHttpxClient` class that you can pass to retain the default values we use for `limits`, `timeout` & `follow_redirects`.
240
+ # See the [httpx documentation](https://www.python-httpx.org/api/#asyncclient) for more details.
241
+ http_client: httpx.AsyncClient | None = None,
242
+ # Enable or disable schema validation for data returned by the API.
243
+ # When enabled an error APIResponseValidationError is raised
244
+ # if the API responds with invalid data for the expected schema.
245
+ #
246
+ # This parameter may be removed or changed in the future.
247
+ # If you rely on this feature, please open a GitHub issue
248
+ # outlining your use-case to help us decide if it should be
249
+ # part of our public interface in the future.
250
+ _strict_response_validation: bool = False,
251
+ ) -> None:
252
+ """Construct a new async AsyncCodeset client instance.
253
+
254
+ This automatically infers the `api_key` argument from the `CODESET_API_KEY` environment variable if it is not provided.
255
+ """
256
+ if api_key is None:
257
+ api_key = os.environ.get("CODESET_API_KEY")
258
+ self.api_key = api_key
259
+
260
+ if base_url is None:
261
+ base_url = os.environ.get("CODESET_BASE_URL")
262
+ if base_url is None:
263
+ base_url = f"/api/v1"
264
+
265
+ super().__init__(
266
+ version=__version__,
267
+ base_url=base_url,
268
+ max_retries=max_retries,
269
+ timeout=timeout,
270
+ http_client=http_client,
271
+ custom_headers=default_headers,
272
+ custom_query=default_query,
273
+ _strict_response_validation=_strict_response_validation,
274
+ )
275
+
276
+ self.health = health.AsyncHealthResource(self)
277
+ self.samples = samples.AsyncSamplesResource(self)
278
+ self.sessions = sessions.AsyncSessionsResource(self)
279
+ self.with_raw_response = AsyncCodesetWithRawResponse(self)
280
+ self.with_streaming_response = AsyncCodesetWithStreamedResponse(self)
281
+
282
+ @property
283
+ @override
284
+ def qs(self) -> Querystring:
285
+ return Querystring(array_format="comma")
286
+
287
+ @property
288
+ @override
289
+ def auth_headers(self) -> dict[str, str]:
290
+ api_key = self.api_key
291
+ if api_key is None:
292
+ return {}
293
+ return {"Authorization": f"Bearer {api_key}"}
294
+
295
+ @property
296
+ @override
297
+ def default_headers(self) -> dict[str, str | Omit]:
298
+ return {
299
+ **super().default_headers,
300
+ "X-Stainless-Async": f"async:{get_async_library()}",
301
+ **self._custom_headers,
302
+ }
303
+
304
+ @override
305
+ def _validate_headers(self, headers: Headers, custom_headers: Headers) -> None:
306
+ if self.api_key and headers.get("Authorization"):
307
+ return
308
+ if isinstance(custom_headers.get("Authorization"), Omit):
309
+ return
310
+
311
+ raise TypeError(
312
+ '"Could not resolve authentication method. Expected the api_key to be set. Or for the `Authorization` headers to be explicitly omitted"'
313
+ )
314
+
315
+ def copy(
316
+ self,
317
+ *,
318
+ api_key: str | None = None,
319
+ base_url: str | httpx.URL | None = None,
320
+ timeout: float | Timeout | None | NotGiven = NOT_GIVEN,
321
+ http_client: httpx.AsyncClient | None = None,
322
+ max_retries: int | NotGiven = NOT_GIVEN,
323
+ default_headers: Mapping[str, str] | None = None,
324
+ set_default_headers: Mapping[str, str] | None = None,
325
+ default_query: Mapping[str, object] | None = None,
326
+ set_default_query: Mapping[str, object] | None = None,
327
+ _extra_kwargs: Mapping[str, Any] = {},
328
+ ) -> Self:
329
+ """
330
+ Create a new client instance re-using the same options given to the current client with optional overriding.
331
+ """
332
+ if default_headers is not None and set_default_headers is not None:
333
+ raise ValueError("The `default_headers` and `set_default_headers` arguments are mutually exclusive")
334
+
335
+ if default_query is not None and set_default_query is not None:
336
+ raise ValueError("The `default_query` and `set_default_query` arguments are mutually exclusive")
337
+
338
+ headers = self._custom_headers
339
+ if default_headers is not None:
340
+ headers = {**headers, **default_headers}
341
+ elif set_default_headers is not None:
342
+ headers = set_default_headers
343
+
344
+ params = self._custom_query
345
+ if default_query is not None:
346
+ params = {**params, **default_query}
347
+ elif set_default_query is not None:
348
+ params = set_default_query
349
+
350
+ http_client = http_client or self._client
351
+ return self.__class__(
352
+ api_key=api_key or self.api_key,
353
+ base_url=base_url or self.base_url,
354
+ timeout=self.timeout if isinstance(timeout, NotGiven) else timeout,
355
+ http_client=http_client,
356
+ max_retries=max_retries if is_given(max_retries) else self.max_retries,
357
+ default_headers=headers,
358
+ default_query=params,
359
+ **_extra_kwargs,
360
+ )
361
+
362
+ # Alias for `copy` for nicer inline usage, e.g.
363
+ # client.with_options(timeout=10).foo.create(...)
364
+ with_options = copy
365
+
366
+ @override
367
+ def _make_status_error(
368
+ self,
369
+ err_msg: str,
370
+ *,
371
+ body: object,
372
+ response: httpx.Response,
373
+ ) -> APIStatusError:
374
+ if response.status_code == 400:
375
+ return _exceptions.BadRequestError(err_msg, response=response, body=body)
376
+
377
+ if response.status_code == 401:
378
+ return _exceptions.AuthenticationError(err_msg, response=response, body=body)
379
+
380
+ if response.status_code == 403:
381
+ return _exceptions.PermissionDeniedError(err_msg, response=response, body=body)
382
+
383
+ if response.status_code == 404:
384
+ return _exceptions.NotFoundError(err_msg, response=response, body=body)
385
+
386
+ if response.status_code == 409:
387
+ return _exceptions.ConflictError(err_msg, response=response, body=body)
388
+
389
+ if response.status_code == 422:
390
+ return _exceptions.UnprocessableEntityError(err_msg, response=response, body=body)
391
+
392
+ if response.status_code == 429:
393
+ return _exceptions.RateLimitError(err_msg, response=response, body=body)
394
+
395
+ if response.status_code >= 500:
396
+ return _exceptions.InternalServerError(err_msg, response=response, body=body)
397
+ return APIStatusError(err_msg, response=response, body=body)
398
+
399
+
400
+ class CodesetWithRawResponse:
401
+ def __init__(self, client: Codeset) -> None:
402
+ self.health = health.HealthResourceWithRawResponse(client.health)
403
+ self.samples = samples.SamplesResourceWithRawResponse(client.samples)
404
+ self.sessions = sessions.SessionsResourceWithRawResponse(client.sessions)
405
+
406
+
407
+ class AsyncCodesetWithRawResponse:
408
+ def __init__(self, client: AsyncCodeset) -> None:
409
+ self.health = health.AsyncHealthResourceWithRawResponse(client.health)
410
+ self.samples = samples.AsyncSamplesResourceWithRawResponse(client.samples)
411
+ self.sessions = sessions.AsyncSessionsResourceWithRawResponse(client.sessions)
412
+
413
+
414
+ class CodesetWithStreamedResponse:
415
+ def __init__(self, client: Codeset) -> None:
416
+ self.health = health.HealthResourceWithStreamingResponse(client.health)
417
+ self.samples = samples.SamplesResourceWithStreamingResponse(client.samples)
418
+ self.sessions = sessions.SessionsResourceWithStreamingResponse(client.sessions)
419
+
420
+
421
+ class AsyncCodesetWithStreamedResponse:
422
+ def __init__(self, client: AsyncCodeset) -> None:
423
+ self.health = health.AsyncHealthResourceWithStreamingResponse(client.health)
424
+ self.samples = samples.AsyncSamplesResourceWithStreamingResponse(client.samples)
425
+ self.sessions = sessions.AsyncSessionsResourceWithStreamingResponse(client.sessions)
426
+
427
+
428
+ Client = Codeset
429
+
430
+ AsyncClient = AsyncCodeset
codeset/_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
codeset/_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