cartography-client 0.0.1__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 cartography-client might be problematic. Click here for more details.

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