worqhat 3.9.0__py3-none-any.whl → 4.1.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.
Files changed (80) hide show
  1. worqhat/__init__.py +8 -89
  2. worqhat/client.py +62 -0
  3. worqhat/exceptions.py +43 -0
  4. worqhat/http_client.py +171 -0
  5. worqhat/py.typed +1 -0
  6. worqhat/resources/__init__.py +5 -59
  7. worqhat/resources/database.py +293 -0
  8. worqhat/resources/flows.py +61 -409
  9. worqhat/resources/storage.py +41 -431
  10. worqhat-4.1.0.dist-info/METADATA +538 -0
  11. worqhat-4.1.0.dist-info/RECORD +13 -0
  12. {worqhat-3.9.0.dist-info → worqhat-4.1.0.dist-info}/WHEEL +2 -1
  13. worqhat-4.1.0.dist-info/top_level.txt +1 -0
  14. worqhat/_base_client.py +0 -1995
  15. worqhat/_client.py +0 -484
  16. worqhat/_compat.py +0 -219
  17. worqhat/_constants.py +0 -14
  18. worqhat/_exceptions.py +0 -108
  19. worqhat/_files.py +0 -123
  20. worqhat/_models.py +0 -835
  21. worqhat/_qs.py +0 -150
  22. worqhat/_resource.py +0 -43
  23. worqhat/_response.py +0 -830
  24. worqhat/_streaming.py +0 -333
  25. worqhat/_types.py +0 -260
  26. worqhat/_utils/__init__.py +0 -64
  27. worqhat/_utils/_compat.py +0 -45
  28. worqhat/_utils/_datetime_parse.py +0 -136
  29. worqhat/_utils/_logs.py +0 -25
  30. worqhat/_utils/_proxy.py +0 -65
  31. worqhat/_utils/_reflection.py +0 -42
  32. worqhat/_utils/_resources_proxy.py +0 -24
  33. worqhat/_utils/_streams.py +0 -12
  34. worqhat/_utils/_sync.py +0 -86
  35. worqhat/_utils/_transform.py +0 -457
  36. worqhat/_utils/_typing.py +0 -156
  37. worqhat/_utils/_utils.py +0 -421
  38. worqhat/_version.py +0 -4
  39. worqhat/lib/.keep +0 -4
  40. worqhat/resources/db/__init__.py +0 -33
  41. worqhat/resources/db/db.py +0 -800
  42. worqhat/resources/db/tables.py +0 -389
  43. worqhat/resources/health.py +0 -143
  44. worqhat/types/__init__.py +0 -32
  45. worqhat/types/db/__init__.py +0 -10
  46. worqhat/types/db/table_get_row_count_params.py +0 -12
  47. worqhat/types/db/table_get_row_count_response.py +0 -15
  48. worqhat/types/db/table_list_params.py +0 -15
  49. worqhat/types/db/table_list_response.py +0 -26
  50. worqhat/types/db/table_retrieve_schema_params.py +0 -12
  51. worqhat/types/db/table_retrieve_schema_response.py +0 -29
  52. worqhat/types/db_delete_records_params.py +0 -19
  53. worqhat/types/db_delete_records_response.py +0 -18
  54. worqhat/types/db_execute_batch_params.py +0 -36
  55. worqhat/types/db_execute_batch_response.py +0 -27
  56. worqhat/types/db_execute_query_params.py +0 -24
  57. worqhat/types/db_execute_query_response.py +0 -21
  58. worqhat/types/db_insert_record_params.py +0 -19
  59. worqhat/types/db_insert_record_response.py +0 -15
  60. worqhat/types/db_process_nl_query_params.py +0 -19
  61. worqhat/types/db_process_nl_query_response.py +0 -18
  62. worqhat/types/db_update_records_params.py +0 -22
  63. worqhat/types/db_update_records_response.py +0 -18
  64. worqhat/types/flow_get_metrics_params.py +0 -25
  65. worqhat/types/flow_get_metrics_response.py +0 -55
  66. worqhat/types/flow_trigger_with_file_params.py +0 -17
  67. worqhat/types/flow_trigger_with_file_response.py +0 -18
  68. worqhat/types/flow_trigger_with_payload_params.py +0 -13
  69. worqhat/types/flow_trigger_with_payload_response.py +0 -20
  70. worqhat/types/get_server_info_response.py +0 -15
  71. worqhat/types/health_check_response.py +0 -33
  72. worqhat/types/storage_delete_file_by_id_response.py +0 -18
  73. worqhat/types/storage_retrieve_file_by_id_response.py +0 -33
  74. worqhat/types/storage_retrieve_file_by_path_params.py +0 -12
  75. worqhat/types/storage_retrieve_file_by_path_response.py +0 -33
  76. worqhat/types/storage_upload_file_params.py +0 -17
  77. worqhat/types/storage_upload_file_response.py +0 -33
  78. worqhat-3.9.0.dist-info/METADATA +0 -432
  79. worqhat-3.9.0.dist-info/RECORD +0 -73
  80. worqhat-3.9.0.dist-info/licenses/LICENSE +0 -201
worqhat/_client.py DELETED
@@ -1,484 +0,0 @@
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
- Body,
15
- Omit,
16
- Query,
17
- Headers,
18
- Timeout,
19
- NotGiven,
20
- Transport,
21
- ProxiesTypes,
22
- RequestOptions,
23
- not_given,
24
- )
25
- from ._utils import is_given, get_async_library
26
- from ._version import __version__
27
- from ._response import (
28
- to_raw_response_wrapper,
29
- to_streamed_response_wrapper,
30
- async_to_raw_response_wrapper,
31
- async_to_streamed_response_wrapper,
32
- )
33
- from .resources import flows, health, storage
34
- from ._streaming import Stream as Stream, AsyncStream as AsyncStream
35
- from ._exceptions import WorqhatError, APIStatusError
36
- from ._base_client import (
37
- DEFAULT_MAX_RETRIES,
38
- SyncAPIClient,
39
- AsyncAPIClient,
40
- make_request_options,
41
- )
42
- from .resources.db import db
43
- from .types.get_server_info_response import GetServerInfoResponse
44
-
45
- __all__ = ["Timeout", "Transport", "ProxiesTypes", "RequestOptions", "Worqhat", "AsyncWorqhat", "Client", "AsyncClient"]
46
-
47
-
48
- class Worqhat(SyncAPIClient):
49
- db: db.DBResource
50
- health: health.HealthResource
51
- flows: flows.FlowsResource
52
- storage: storage.StorageResource
53
- with_raw_response: WorqhatWithRawResponse
54
- with_streaming_response: WorqhatWithStreamedResponse
55
-
56
- # client options
57
- api_key: str
58
-
59
- def __init__(
60
- self,
61
- *,
62
- api_key: str | None = None,
63
- base_url: str | httpx.URL | None = None,
64
- timeout: 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 Worqhat client instance.
83
-
84
- This automatically infers the `api_key` argument from the `WORQHAT_API_KEY` environment variable if it is not provided.
85
- """
86
- if api_key is None:
87
- api_key = os.environ.get("WORQHAT_API_KEY")
88
- if api_key is None:
89
- raise WorqhatError(
90
- "The api_key client option must be set either by passing api_key to the client or by setting the WORQHAT_API_KEY environment variable"
91
- )
92
- self.api_key = api_key
93
-
94
- if base_url is None:
95
- base_url = os.environ.get("WORQHAT_BASE_URL")
96
- if base_url is None:
97
- base_url = f"https://api.worqhat.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.db = db.DBResource(self)
111
- self.health = health.HealthResource(self)
112
- self.flows = flows.FlowsResource(self)
113
- self.storage = storage.StorageResource(self)
114
- self.with_raw_response = WorqhatWithRawResponse(self)
115
- self.with_streaming_response = WorqhatWithStreamedResponse(self)
116
-
117
- @property
118
- @override
119
- def qs(self) -> Querystring:
120
- return Querystring(array_format="comma")
121
-
122
- @property
123
- @override
124
- def auth_headers(self) -> dict[str, str]:
125
- api_key = self.api_key
126
- return {"Authorization": api_key}
127
-
128
- @property
129
- @override
130
- def default_headers(self) -> dict[str, str | Omit]:
131
- return {
132
- **super().default_headers,
133
- "X-Stainless-Async": "false",
134
- **self._custom_headers,
135
- }
136
-
137
- def copy(
138
- self,
139
- *,
140
- api_key: str | None = None,
141
- base_url: str | httpx.URL | None = None,
142
- timeout: float | Timeout | None | NotGiven = not_given,
143
- http_client: httpx.Client | None = None,
144
- max_retries: int | NotGiven = not_given,
145
- default_headers: Mapping[str, str] | None = None,
146
- set_default_headers: Mapping[str, str] | None = None,
147
- default_query: Mapping[str, object] | None = None,
148
- set_default_query: Mapping[str, object] | None = None,
149
- _extra_kwargs: Mapping[str, Any] = {},
150
- ) -> Self:
151
- """
152
- Create a new client instance re-using the same options given to the current client with optional overriding.
153
- """
154
- if default_headers is not None and set_default_headers is not None:
155
- raise ValueError("The `default_headers` and `set_default_headers` arguments are mutually exclusive")
156
-
157
- if default_query is not None and set_default_query is not None:
158
- raise ValueError("The `default_query` and `set_default_query` arguments are mutually exclusive")
159
-
160
- headers = self._custom_headers
161
- if default_headers is not None:
162
- headers = {**headers, **default_headers}
163
- elif set_default_headers is not None:
164
- headers = set_default_headers
165
-
166
- params = self._custom_query
167
- if default_query is not None:
168
- params = {**params, **default_query}
169
- elif set_default_query is not None:
170
- params = set_default_query
171
-
172
- http_client = http_client or self._client
173
- return self.__class__(
174
- api_key=api_key or self.api_key,
175
- base_url=base_url or self.base_url,
176
- timeout=self.timeout if isinstance(timeout, NotGiven) else timeout,
177
- http_client=http_client,
178
- max_retries=max_retries if is_given(max_retries) else self.max_retries,
179
- default_headers=headers,
180
- default_query=params,
181
- **_extra_kwargs,
182
- )
183
-
184
- # Alias for `copy` for nicer inline usage, e.g.
185
- # client.with_options(timeout=10).foo.create(...)
186
- with_options = copy
187
-
188
- def get_server_info(
189
- self,
190
- *,
191
- # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
192
- # The extra values given here take precedence over values defined on the client or passed to this method.
193
- extra_headers: Headers | None = None,
194
- extra_query: Query | None = None,
195
- extra_body: Body | None = None,
196
- timeout: float | httpx.Timeout | None | NotGiven = not_given,
197
- ) -> GetServerInfoResponse:
198
- """Get basic server information and status"""
199
- return self.get(
200
- "/",
201
- options=make_request_options(
202
- extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
203
- ),
204
- cast_to=GetServerInfoResponse,
205
- )
206
-
207
- @override
208
- def _make_status_error(
209
- self,
210
- err_msg: str,
211
- *,
212
- body: object,
213
- response: httpx.Response,
214
- ) -> APIStatusError:
215
- if response.status_code == 400:
216
- return _exceptions.BadRequestError(err_msg, response=response, body=body)
217
-
218
- if response.status_code == 401:
219
- return _exceptions.AuthenticationError(err_msg, response=response, body=body)
220
-
221
- if response.status_code == 403:
222
- return _exceptions.PermissionDeniedError(err_msg, response=response, body=body)
223
-
224
- if response.status_code == 404:
225
- return _exceptions.NotFoundError(err_msg, response=response, body=body)
226
-
227
- if response.status_code == 409:
228
- return _exceptions.ConflictError(err_msg, response=response, body=body)
229
-
230
- if response.status_code == 422:
231
- return _exceptions.UnprocessableEntityError(err_msg, response=response, body=body)
232
-
233
- if response.status_code == 429:
234
- return _exceptions.RateLimitError(err_msg, response=response, body=body)
235
-
236
- if response.status_code >= 500:
237
- return _exceptions.InternalServerError(err_msg, response=response, body=body)
238
- return APIStatusError(err_msg, response=response, body=body)
239
-
240
-
241
- class AsyncWorqhat(AsyncAPIClient):
242
- db: db.AsyncDBResource
243
- health: health.AsyncHealthResource
244
- flows: flows.AsyncFlowsResource
245
- storage: storage.AsyncStorageResource
246
- with_raw_response: AsyncWorqhatWithRawResponse
247
- with_streaming_response: AsyncWorqhatWithStreamedResponse
248
-
249
- # client options
250
- api_key: str
251
-
252
- def __init__(
253
- self,
254
- *,
255
- api_key: str | None = None,
256
- base_url: str | httpx.URL | None = None,
257
- timeout: float | Timeout | None | NotGiven = not_given,
258
- max_retries: int = DEFAULT_MAX_RETRIES,
259
- default_headers: Mapping[str, str] | None = None,
260
- default_query: Mapping[str, object] | None = None,
261
- # Configure a custom httpx client.
262
- # We provide a `DefaultAsyncHttpxClient` class that you can pass to retain the default values we use for `limits`, `timeout` & `follow_redirects`.
263
- # See the [httpx documentation](https://www.python-httpx.org/api/#asyncclient) for more details.
264
- http_client: httpx.AsyncClient | None = None,
265
- # Enable or disable schema validation for data returned by the API.
266
- # When enabled an error APIResponseValidationError is raised
267
- # if the API responds with invalid data for the expected schema.
268
- #
269
- # This parameter may be removed or changed in the future.
270
- # If you rely on this feature, please open a GitHub issue
271
- # outlining your use-case to help us decide if it should be
272
- # part of our public interface in the future.
273
- _strict_response_validation: bool = False,
274
- ) -> None:
275
- """Construct a new async AsyncWorqhat client instance.
276
-
277
- This automatically infers the `api_key` argument from the `WORQHAT_API_KEY` environment variable if it is not provided.
278
- """
279
- if api_key is None:
280
- api_key = os.environ.get("WORQHAT_API_KEY")
281
- if api_key is None:
282
- raise WorqhatError(
283
- "The api_key client option must be set either by passing api_key to the client or by setting the WORQHAT_API_KEY environment variable"
284
- )
285
- self.api_key = api_key
286
-
287
- if base_url is None:
288
- base_url = os.environ.get("WORQHAT_BASE_URL")
289
- if base_url is None:
290
- base_url = f"https://api.worqhat.com"
291
-
292
- super().__init__(
293
- version=__version__,
294
- base_url=base_url,
295
- max_retries=max_retries,
296
- timeout=timeout,
297
- http_client=http_client,
298
- custom_headers=default_headers,
299
- custom_query=default_query,
300
- _strict_response_validation=_strict_response_validation,
301
- )
302
-
303
- self.db = db.AsyncDBResource(self)
304
- self.health = health.AsyncHealthResource(self)
305
- self.flows = flows.AsyncFlowsResource(self)
306
- self.storage = storage.AsyncStorageResource(self)
307
- self.with_raw_response = AsyncWorqhatWithRawResponse(self)
308
- self.with_streaming_response = AsyncWorqhatWithStreamedResponse(self)
309
-
310
- @property
311
- @override
312
- def qs(self) -> Querystring:
313
- return Querystring(array_format="comma")
314
-
315
- @property
316
- @override
317
- def auth_headers(self) -> dict[str, str]:
318
- api_key = self.api_key
319
- return {"Authorization": api_key}
320
-
321
- @property
322
- @override
323
- def default_headers(self) -> dict[str, str | Omit]:
324
- return {
325
- **super().default_headers,
326
- "X-Stainless-Async": f"async:{get_async_library()}",
327
- **self._custom_headers,
328
- }
329
-
330
- def copy(
331
- self,
332
- *,
333
- api_key: str | None = None,
334
- base_url: str | httpx.URL | None = None,
335
- timeout: float | Timeout | None | NotGiven = not_given,
336
- http_client: httpx.AsyncClient | None = None,
337
- max_retries: int | NotGiven = not_given,
338
- default_headers: Mapping[str, str] | None = None,
339
- set_default_headers: Mapping[str, str] | None = None,
340
- default_query: Mapping[str, object] | None = None,
341
- set_default_query: Mapping[str, object] | None = None,
342
- _extra_kwargs: Mapping[str, Any] = {},
343
- ) -> Self:
344
- """
345
- Create a new client instance re-using the same options given to the current client with optional overriding.
346
- """
347
- if default_headers is not None and set_default_headers is not None:
348
- raise ValueError("The `default_headers` and `set_default_headers` arguments are mutually exclusive")
349
-
350
- if default_query is not None and set_default_query is not None:
351
- raise ValueError("The `default_query` and `set_default_query` arguments are mutually exclusive")
352
-
353
- headers = self._custom_headers
354
- if default_headers is not None:
355
- headers = {**headers, **default_headers}
356
- elif set_default_headers is not None:
357
- headers = set_default_headers
358
-
359
- params = self._custom_query
360
- if default_query is not None:
361
- params = {**params, **default_query}
362
- elif set_default_query is not None:
363
- params = set_default_query
364
-
365
- http_client = http_client or self._client
366
- return self.__class__(
367
- api_key=api_key or self.api_key,
368
- base_url=base_url or self.base_url,
369
- timeout=self.timeout if isinstance(timeout, NotGiven) else timeout,
370
- http_client=http_client,
371
- max_retries=max_retries if is_given(max_retries) else self.max_retries,
372
- default_headers=headers,
373
- default_query=params,
374
- **_extra_kwargs,
375
- )
376
-
377
- # Alias for `copy` for nicer inline usage, e.g.
378
- # client.with_options(timeout=10).foo.create(...)
379
- with_options = copy
380
-
381
- async def get_server_info(
382
- self,
383
- *,
384
- # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
385
- # The extra values given here take precedence over values defined on the client or passed to this method.
386
- extra_headers: Headers | None = None,
387
- extra_query: Query | None = None,
388
- extra_body: Body | None = None,
389
- timeout: float | httpx.Timeout | None | NotGiven = not_given,
390
- ) -> GetServerInfoResponse:
391
- """Get basic server information and status"""
392
- return await self.get(
393
- "/",
394
- options=make_request_options(
395
- extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
396
- ),
397
- cast_to=GetServerInfoResponse,
398
- )
399
-
400
- @override
401
- def _make_status_error(
402
- self,
403
- err_msg: str,
404
- *,
405
- body: object,
406
- response: httpx.Response,
407
- ) -> APIStatusError:
408
- if response.status_code == 400:
409
- return _exceptions.BadRequestError(err_msg, response=response, body=body)
410
-
411
- if response.status_code == 401:
412
- return _exceptions.AuthenticationError(err_msg, response=response, body=body)
413
-
414
- if response.status_code == 403:
415
- return _exceptions.PermissionDeniedError(err_msg, response=response, body=body)
416
-
417
- if response.status_code == 404:
418
- return _exceptions.NotFoundError(err_msg, response=response, body=body)
419
-
420
- if response.status_code == 409:
421
- return _exceptions.ConflictError(err_msg, response=response, body=body)
422
-
423
- if response.status_code == 422:
424
- return _exceptions.UnprocessableEntityError(err_msg, response=response, body=body)
425
-
426
- if response.status_code == 429:
427
- return _exceptions.RateLimitError(err_msg, response=response, body=body)
428
-
429
- if response.status_code >= 500:
430
- return _exceptions.InternalServerError(err_msg, response=response, body=body)
431
- return APIStatusError(err_msg, response=response, body=body)
432
-
433
-
434
- class WorqhatWithRawResponse:
435
- def __init__(self, client: Worqhat) -> None:
436
- self.db = db.DBResourceWithRawResponse(client.db)
437
- self.health = health.HealthResourceWithRawResponse(client.health)
438
- self.flows = flows.FlowsResourceWithRawResponse(client.flows)
439
- self.storage = storage.StorageResourceWithRawResponse(client.storage)
440
-
441
- self.get_server_info = to_raw_response_wrapper(
442
- client.get_server_info,
443
- )
444
-
445
-
446
- class AsyncWorqhatWithRawResponse:
447
- def __init__(self, client: AsyncWorqhat) -> None:
448
- self.db = db.AsyncDBResourceWithRawResponse(client.db)
449
- self.health = health.AsyncHealthResourceWithRawResponse(client.health)
450
- self.flows = flows.AsyncFlowsResourceWithRawResponse(client.flows)
451
- self.storage = storage.AsyncStorageResourceWithRawResponse(client.storage)
452
-
453
- self.get_server_info = async_to_raw_response_wrapper(
454
- client.get_server_info,
455
- )
456
-
457
-
458
- class WorqhatWithStreamedResponse:
459
- def __init__(self, client: Worqhat) -> None:
460
- self.db = db.DBResourceWithStreamingResponse(client.db)
461
- self.health = health.HealthResourceWithStreamingResponse(client.health)
462
- self.flows = flows.FlowsResourceWithStreamingResponse(client.flows)
463
- self.storage = storage.StorageResourceWithStreamingResponse(client.storage)
464
-
465
- self.get_server_info = to_streamed_response_wrapper(
466
- client.get_server_info,
467
- )
468
-
469
-
470
- class AsyncWorqhatWithStreamedResponse:
471
- def __init__(self, client: AsyncWorqhat) -> None:
472
- self.db = db.AsyncDBResourceWithStreamingResponse(client.db)
473
- self.health = health.AsyncHealthResourceWithStreamingResponse(client.health)
474
- self.flows = flows.AsyncFlowsResourceWithStreamingResponse(client.flows)
475
- self.storage = storage.AsyncStorageResourceWithStreamingResponse(client.storage)
476
-
477
- self.get_server_info = async_to_streamed_response_wrapper(
478
- client.get_server_info,
479
- )
480
-
481
-
482
- Client = Worqhat
483
-
484
- AsyncClient = AsyncWorqhat
worqhat/_compat.py DELETED
@@ -1,219 +0,0 @@
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