profound 0.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.

Potentially problematic release.


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

Files changed (66) hide show
  1. profound/__init__.py +102 -0
  2. profound/_base_client.py +1995 -0
  3. profound/_client.py +448 -0
  4. profound/_compat.py +219 -0
  5. profound/_constants.py +14 -0
  6. profound/_exceptions.py +108 -0
  7. profound/_files.py +123 -0
  8. profound/_models.py +835 -0
  9. profound/_qs.py +150 -0
  10. profound/_resource.py +43 -0
  11. profound/_response.py +830 -0
  12. profound/_streaming.py +333 -0
  13. profound/_types.py +260 -0
  14. profound/_utils/__init__.py +64 -0
  15. profound/_utils/_compat.py +45 -0
  16. profound/_utils/_datetime_parse.py +136 -0
  17. profound/_utils/_logs.py +25 -0
  18. profound/_utils/_proxy.py +65 -0
  19. profound/_utils/_reflection.py +42 -0
  20. profound/_utils/_resources_proxy.py +24 -0
  21. profound/_utils/_streams.py +12 -0
  22. profound/_utils/_sync.py +86 -0
  23. profound/_utils/_transform.py +457 -0
  24. profound/_utils/_typing.py +156 -0
  25. profound/_utils/_utils.py +421 -0
  26. profound/_version.py +4 -0
  27. profound/lib/.keep +4 -0
  28. profound/py.typed +0 -0
  29. profound/resources/__init__.py +61 -0
  30. profound/resources/logs/__init__.py +33 -0
  31. profound/resources/logs/logs.py +102 -0
  32. profound/resources/logs/raw.py +511 -0
  33. profound/resources/organizations/__init__.py +33 -0
  34. profound/resources/organizations/categories.py +372 -0
  35. profound/resources/organizations/organizations.py +269 -0
  36. profound/resources/prompts.py +201 -0
  37. profound/resources/reports.py +609 -0
  38. profound/types/__init__.py +17 -0
  39. profound/types/info.py +13 -0
  40. profound/types/logs/__init__.py +8 -0
  41. profound/types/logs/raw_bots_params.py +111 -0
  42. profound/types/logs/raw_bots_response.py +45 -0
  43. profound/types/logs/raw_logs_params.py +99 -0
  44. profound/types/logs/raw_logs_response.py +39 -0
  45. profound/types/organization_domains_response.py +20 -0
  46. profound/types/organization_models_response.py +10 -0
  47. profound/types/organization_regions_response.py +10 -0
  48. profound/types/organizations/__init__.py +9 -0
  49. profound/types/organizations/category_list_response.py +10 -0
  50. profound/types/organizations/category_prompts_response.py +31 -0
  51. profound/types/organizations/category_tags_response.py +10 -0
  52. profound/types/organizations/category_topics_response.py +10 -0
  53. profound/types/organizations/org_item.py +11 -0
  54. profound/types/pagination_param.py +15 -0
  55. profound/types/prompt_answers_params.py +82 -0
  56. profound/types/prompt_answers_response.py +44 -0
  57. profound/types/report_citations_params.py +83 -0
  58. profound/types/report_citations_response.py +16 -0
  59. profound/types/report_sentiment_params.py +83 -0
  60. profound/types/report_visibility_params.py +83 -0
  61. profound/types/response.py +16 -0
  62. profound/types/result.py +13 -0
  63. profound-0.1.0.dist-info/METADATA +415 -0
  64. profound-0.1.0.dist-info/RECORD +66 -0
  65. profound-0.1.0.dist-info/WHEEL +4 -0
  66. profound-0.1.0.dist-info/licenses/LICENSE +201 -0
profound/_client.py ADDED
@@ -0,0 +1,448 @@
1
+ # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ from __future__ import annotations
4
+
5
+ import os
6
+ from typing import Any, Mapping
7
+ from typing_extensions import Self, override
8
+
9
+ import httpx
10
+
11
+ from . import _exceptions
12
+ from ._qs import Querystring
13
+ from ._types import (
14
+ Omit,
15
+ Headers,
16
+ Timeout,
17
+ NotGiven,
18
+ Transport,
19
+ ProxiesTypes,
20
+ RequestOptions,
21
+ not_given,
22
+ )
23
+ from ._utils import is_given, get_async_library
24
+ from ._version import __version__
25
+ from .resources import prompts, reports
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.logs import logs
34
+ from .resources.organizations import organizations
35
+
36
+ __all__ = [
37
+ "Timeout",
38
+ "Transport",
39
+ "ProxiesTypes",
40
+ "RequestOptions",
41
+ "Profound",
42
+ "AsyncProfound",
43
+ "Client",
44
+ "AsyncClient",
45
+ ]
46
+
47
+
48
+ class Profound(SyncAPIClient):
49
+ organizations: organizations.OrganizationsResource
50
+ prompts: prompts.PromptsResource
51
+ reports: reports.ReportsResource
52
+ logs: logs.LogsResource
53
+ with_raw_response: ProfoundWithRawResponse
54
+ with_streaming_response: ProfoundWithStreamedResponse
55
+
56
+ # client options
57
+ api_key: str | None
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 Profound client instance.
83
+
84
+ This automatically infers the `api_key` argument from the `PROFOUND_API_KEY` environment variable if it is not provided.
85
+ """
86
+ if api_key is None:
87
+ api_key = os.environ.get("PROFOUND_API_KEY")
88
+ self.api_key = api_key
89
+
90
+ if base_url is None:
91
+ base_url = os.environ.get("PROFOUND_BASE_URL")
92
+ if base_url is None:
93
+ base_url = f"https://api.tryprofound.com"
94
+
95
+ super().__init__(
96
+ version=__version__,
97
+ base_url=base_url,
98
+ max_retries=max_retries,
99
+ timeout=timeout,
100
+ http_client=http_client,
101
+ custom_headers=default_headers,
102
+ custom_query=default_query,
103
+ _strict_response_validation=_strict_response_validation,
104
+ )
105
+
106
+ self.organizations = organizations.OrganizationsResource(self)
107
+ self.prompts = prompts.PromptsResource(self)
108
+ self.reports = reports.ReportsResource(self)
109
+ self.logs = logs.LogsResource(self)
110
+ self.with_raw_response = ProfoundWithRawResponse(self)
111
+ self.with_streaming_response = ProfoundWithStreamedResponse(self)
112
+
113
+ @property
114
+ @override
115
+ def qs(self) -> Querystring:
116
+ return Querystring(array_format="comma")
117
+
118
+ @property
119
+ @override
120
+ def auth_headers(self) -> dict[str, str]:
121
+ api_key = self.api_key
122
+ if api_key is None:
123
+ return {}
124
+ return {"X-API-Key": api_key}
125
+
126
+ @property
127
+ @override
128
+ def default_headers(self) -> dict[str, str | Omit]:
129
+ return {
130
+ **super().default_headers,
131
+ "X-Stainless-Async": "false",
132
+ **self._custom_headers,
133
+ }
134
+
135
+ @override
136
+ def _validate_headers(self, headers: Headers, custom_headers: Headers) -> None:
137
+ if self.api_key and headers.get("X-API-Key"):
138
+ return
139
+ if isinstance(custom_headers.get("X-API-Key"), Omit):
140
+ return
141
+
142
+ raise TypeError(
143
+ '"Could not resolve authentication method. Expected the api_key to be set. Or for the `X-API-Key` headers to be explicitly omitted"'
144
+ )
145
+
146
+ def copy(
147
+ self,
148
+ *,
149
+ api_key: str | None = None,
150
+ base_url: str | httpx.URL | None = None,
151
+ timeout: float | Timeout | None | NotGiven = not_given,
152
+ http_client: httpx.Client | None = None,
153
+ max_retries: int | NotGiven = not_given,
154
+ default_headers: Mapping[str, str] | None = None,
155
+ set_default_headers: Mapping[str, str] | None = None,
156
+ default_query: Mapping[str, object] | None = None,
157
+ set_default_query: Mapping[str, object] | None = None,
158
+ _extra_kwargs: Mapping[str, Any] = {},
159
+ ) -> Self:
160
+ """
161
+ Create a new client instance re-using the same options given to the current client with optional overriding.
162
+ """
163
+ if default_headers is not None and set_default_headers is not None:
164
+ raise ValueError("The `default_headers` and `set_default_headers` arguments are mutually exclusive")
165
+
166
+ if default_query is not None and set_default_query is not None:
167
+ raise ValueError("The `default_query` and `set_default_query` arguments are mutually exclusive")
168
+
169
+ headers = self._custom_headers
170
+ if default_headers is not None:
171
+ headers = {**headers, **default_headers}
172
+ elif set_default_headers is not None:
173
+ headers = set_default_headers
174
+
175
+ params = self._custom_query
176
+ if default_query is not None:
177
+ params = {**params, **default_query}
178
+ elif set_default_query is not None:
179
+ params = set_default_query
180
+
181
+ http_client = http_client or self._client
182
+ return self.__class__(
183
+ api_key=api_key or self.api_key,
184
+ base_url=base_url or self.base_url,
185
+ timeout=self.timeout if isinstance(timeout, NotGiven) else timeout,
186
+ http_client=http_client,
187
+ max_retries=max_retries if is_given(max_retries) else self.max_retries,
188
+ default_headers=headers,
189
+ default_query=params,
190
+ **_extra_kwargs,
191
+ )
192
+
193
+ # Alias for `copy` for nicer inline usage, e.g.
194
+ # client.with_options(timeout=10).foo.create(...)
195
+ with_options = copy
196
+
197
+ @override
198
+ def _make_status_error(
199
+ self,
200
+ err_msg: str,
201
+ *,
202
+ body: object,
203
+ response: httpx.Response,
204
+ ) -> APIStatusError:
205
+ if response.status_code == 400:
206
+ return _exceptions.BadRequestError(err_msg, response=response, body=body)
207
+
208
+ if response.status_code == 401:
209
+ return _exceptions.AuthenticationError(err_msg, response=response, body=body)
210
+
211
+ if response.status_code == 403:
212
+ return _exceptions.PermissionDeniedError(err_msg, response=response, body=body)
213
+
214
+ if response.status_code == 404:
215
+ return _exceptions.NotFoundError(err_msg, response=response, body=body)
216
+
217
+ if response.status_code == 409:
218
+ return _exceptions.ConflictError(err_msg, response=response, body=body)
219
+
220
+ if response.status_code == 422:
221
+ return _exceptions.UnprocessableEntityError(err_msg, response=response, body=body)
222
+
223
+ if response.status_code == 429:
224
+ return _exceptions.RateLimitError(err_msg, response=response, body=body)
225
+
226
+ if response.status_code >= 500:
227
+ return _exceptions.InternalServerError(err_msg, response=response, body=body)
228
+ return APIStatusError(err_msg, response=response, body=body)
229
+
230
+
231
+ class AsyncProfound(AsyncAPIClient):
232
+ organizations: organizations.AsyncOrganizationsResource
233
+ prompts: prompts.AsyncPromptsResource
234
+ reports: reports.AsyncReportsResource
235
+ logs: logs.AsyncLogsResource
236
+ with_raw_response: AsyncProfoundWithRawResponse
237
+ with_streaming_response: AsyncProfoundWithStreamedResponse
238
+
239
+ # client options
240
+ api_key: str | None
241
+
242
+ def __init__(
243
+ self,
244
+ *,
245
+ api_key: str | None = None,
246
+ base_url: str | httpx.URL | None = None,
247
+ timeout: float | Timeout | None | NotGiven = not_given,
248
+ max_retries: int = DEFAULT_MAX_RETRIES,
249
+ default_headers: Mapping[str, str] | None = None,
250
+ default_query: Mapping[str, object] | None = None,
251
+ # Configure a custom httpx client.
252
+ # We provide a `DefaultAsyncHttpxClient` class that you can pass to retain the default values we use for `limits`, `timeout` & `follow_redirects`.
253
+ # See the [httpx documentation](https://www.python-httpx.org/api/#asyncclient) for more details.
254
+ http_client: httpx.AsyncClient | None = None,
255
+ # Enable or disable schema validation for data returned by the API.
256
+ # When enabled an error APIResponseValidationError is raised
257
+ # if the API responds with invalid data for the expected schema.
258
+ #
259
+ # This parameter may be removed or changed in the future.
260
+ # If you rely on this feature, please open a GitHub issue
261
+ # outlining your use-case to help us decide if it should be
262
+ # part of our public interface in the future.
263
+ _strict_response_validation: bool = False,
264
+ ) -> None:
265
+ """Construct a new async AsyncProfound client instance.
266
+
267
+ This automatically infers the `api_key` argument from the `PROFOUND_API_KEY` environment variable if it is not provided.
268
+ """
269
+ if api_key is None:
270
+ api_key = os.environ.get("PROFOUND_API_KEY")
271
+ self.api_key = api_key
272
+
273
+ if base_url is None:
274
+ base_url = os.environ.get("PROFOUND_BASE_URL")
275
+ if base_url is None:
276
+ base_url = f"https://api.tryprofound.com"
277
+
278
+ super().__init__(
279
+ version=__version__,
280
+ base_url=base_url,
281
+ max_retries=max_retries,
282
+ timeout=timeout,
283
+ http_client=http_client,
284
+ custom_headers=default_headers,
285
+ custom_query=default_query,
286
+ _strict_response_validation=_strict_response_validation,
287
+ )
288
+
289
+ self.organizations = organizations.AsyncOrganizationsResource(self)
290
+ self.prompts = prompts.AsyncPromptsResource(self)
291
+ self.reports = reports.AsyncReportsResource(self)
292
+ self.logs = logs.AsyncLogsResource(self)
293
+ self.with_raw_response = AsyncProfoundWithRawResponse(self)
294
+ self.with_streaming_response = AsyncProfoundWithStreamedResponse(self)
295
+
296
+ @property
297
+ @override
298
+ def qs(self) -> Querystring:
299
+ return Querystring(array_format="comma")
300
+
301
+ @property
302
+ @override
303
+ def auth_headers(self) -> dict[str, str]:
304
+ api_key = self.api_key
305
+ if api_key is None:
306
+ return {}
307
+ return {"X-API-Key": api_key}
308
+
309
+ @property
310
+ @override
311
+ def default_headers(self) -> dict[str, str | Omit]:
312
+ return {
313
+ **super().default_headers,
314
+ "X-Stainless-Async": f"async:{get_async_library()}",
315
+ **self._custom_headers,
316
+ }
317
+
318
+ @override
319
+ def _validate_headers(self, headers: Headers, custom_headers: Headers) -> None:
320
+ if self.api_key and headers.get("X-API-Key"):
321
+ return
322
+ if isinstance(custom_headers.get("X-API-Key"), Omit):
323
+ return
324
+
325
+ raise TypeError(
326
+ '"Could not resolve authentication method. Expected the api_key to be set. Or for the `X-API-Key` headers to be explicitly omitted"'
327
+ )
328
+
329
+ def copy(
330
+ self,
331
+ *,
332
+ api_key: str | None = None,
333
+ base_url: str | httpx.URL | None = None,
334
+ timeout: float | Timeout | None | NotGiven = not_given,
335
+ http_client: httpx.AsyncClient | None = None,
336
+ max_retries: int | NotGiven = not_given,
337
+ default_headers: Mapping[str, str] | None = None,
338
+ set_default_headers: Mapping[str, str] | None = None,
339
+ default_query: Mapping[str, object] | None = None,
340
+ set_default_query: Mapping[str, object] | None = None,
341
+ _extra_kwargs: Mapping[str, Any] = {},
342
+ ) -> Self:
343
+ """
344
+ Create a new client instance re-using the same options given to the current client with optional overriding.
345
+ """
346
+ if default_headers is not None and set_default_headers is not None:
347
+ raise ValueError("The `default_headers` and `set_default_headers` arguments are mutually exclusive")
348
+
349
+ if default_query is not None and set_default_query is not None:
350
+ raise ValueError("The `default_query` and `set_default_query` arguments are mutually exclusive")
351
+
352
+ headers = self._custom_headers
353
+ if default_headers is not None:
354
+ headers = {**headers, **default_headers}
355
+ elif set_default_headers is not None:
356
+ headers = set_default_headers
357
+
358
+ params = self._custom_query
359
+ if default_query is not None:
360
+ params = {**params, **default_query}
361
+ elif set_default_query is not None:
362
+ params = set_default_query
363
+
364
+ http_client = http_client or self._client
365
+ return self.__class__(
366
+ api_key=api_key or self.api_key,
367
+ base_url=base_url or self.base_url,
368
+ timeout=self.timeout if isinstance(timeout, NotGiven) else timeout,
369
+ http_client=http_client,
370
+ max_retries=max_retries if is_given(max_retries) else self.max_retries,
371
+ default_headers=headers,
372
+ default_query=params,
373
+ **_extra_kwargs,
374
+ )
375
+
376
+ # Alias for `copy` for nicer inline usage, e.g.
377
+ # client.with_options(timeout=10).foo.create(...)
378
+ with_options = copy
379
+
380
+ @override
381
+ def _make_status_error(
382
+ self,
383
+ err_msg: str,
384
+ *,
385
+ body: object,
386
+ response: httpx.Response,
387
+ ) -> APIStatusError:
388
+ if response.status_code == 400:
389
+ return _exceptions.BadRequestError(err_msg, response=response, body=body)
390
+
391
+ if response.status_code == 401:
392
+ return _exceptions.AuthenticationError(err_msg, response=response, body=body)
393
+
394
+ if response.status_code == 403:
395
+ return _exceptions.PermissionDeniedError(err_msg, response=response, body=body)
396
+
397
+ if response.status_code == 404:
398
+ return _exceptions.NotFoundError(err_msg, response=response, body=body)
399
+
400
+ if response.status_code == 409:
401
+ return _exceptions.ConflictError(err_msg, response=response, body=body)
402
+
403
+ if response.status_code == 422:
404
+ return _exceptions.UnprocessableEntityError(err_msg, response=response, body=body)
405
+
406
+ if response.status_code == 429:
407
+ return _exceptions.RateLimitError(err_msg, response=response, body=body)
408
+
409
+ if response.status_code >= 500:
410
+ return _exceptions.InternalServerError(err_msg, response=response, body=body)
411
+ return APIStatusError(err_msg, response=response, body=body)
412
+
413
+
414
+ class ProfoundWithRawResponse:
415
+ def __init__(self, client: Profound) -> None:
416
+ self.organizations = organizations.OrganizationsResourceWithRawResponse(client.organizations)
417
+ self.prompts = prompts.PromptsResourceWithRawResponse(client.prompts)
418
+ self.reports = reports.ReportsResourceWithRawResponse(client.reports)
419
+ self.logs = logs.LogsResourceWithRawResponse(client.logs)
420
+
421
+
422
+ class AsyncProfoundWithRawResponse:
423
+ def __init__(self, client: AsyncProfound) -> None:
424
+ self.organizations = organizations.AsyncOrganizationsResourceWithRawResponse(client.organizations)
425
+ self.prompts = prompts.AsyncPromptsResourceWithRawResponse(client.prompts)
426
+ self.reports = reports.AsyncReportsResourceWithRawResponse(client.reports)
427
+ self.logs = logs.AsyncLogsResourceWithRawResponse(client.logs)
428
+
429
+
430
+ class ProfoundWithStreamedResponse:
431
+ def __init__(self, client: Profound) -> None:
432
+ self.organizations = organizations.OrganizationsResourceWithStreamingResponse(client.organizations)
433
+ self.prompts = prompts.PromptsResourceWithStreamingResponse(client.prompts)
434
+ self.reports = reports.ReportsResourceWithStreamingResponse(client.reports)
435
+ self.logs = logs.LogsResourceWithStreamingResponse(client.logs)
436
+
437
+
438
+ class AsyncProfoundWithStreamedResponse:
439
+ def __init__(self, client: AsyncProfound) -> None:
440
+ self.organizations = organizations.AsyncOrganizationsResourceWithStreamingResponse(client.organizations)
441
+ self.prompts = prompts.AsyncPromptsResourceWithStreamingResponse(client.prompts)
442
+ self.reports = reports.AsyncReportsResourceWithStreamingResponse(client.reports)
443
+ self.logs = logs.AsyncLogsResourceWithStreamingResponse(client.logs)
444
+
445
+
446
+ Client = Profound
447
+
448
+ AsyncClient = AsyncProfound
profound/_compat.py ADDED
@@ -0,0 +1,219 @@
1
+ from __future__ import annotations
2
+
3
+ from typing import TYPE_CHECKING, Any, Union, Generic, TypeVar, Callable, cast, overload
4
+ from datetime import date, datetime
5
+ from typing_extensions import Self, Literal
6
+
7
+ import pydantic
8
+ from pydantic.fields import FieldInfo
9
+
10
+ from ._types import IncEx, StrBytesIntFloat
11
+
12
+ _T = TypeVar("_T")
13
+ _ModelT = TypeVar("_ModelT", bound=pydantic.BaseModel)
14
+
15
+ # --------------- Pydantic v2, v3 compatibility ---------------
16
+
17
+ # Pyright incorrectly reports some of our functions as overriding a method when they don't
18
+ # pyright: reportIncompatibleMethodOverride=false
19
+
20
+ PYDANTIC_V1 = pydantic.VERSION.startswith("1.")
21
+
22
+ if TYPE_CHECKING:
23
+
24
+ def parse_date(value: date | StrBytesIntFloat) -> date: # noqa: ARG001
25
+ ...
26
+
27
+ def parse_datetime(value: Union[datetime, StrBytesIntFloat]) -> datetime: # noqa: ARG001
28
+ ...
29
+
30
+ def get_args(t: type[Any]) -> tuple[Any, ...]: # noqa: ARG001
31
+ ...
32
+
33
+ def is_union(tp: type[Any] | None) -> bool: # noqa: ARG001
34
+ ...
35
+
36
+ def get_origin(t: type[Any]) -> type[Any] | None: # noqa: ARG001
37
+ ...
38
+
39
+ def is_literal_type(type_: type[Any]) -> bool: # noqa: ARG001
40
+ ...
41
+
42
+ def is_typeddict(type_: type[Any]) -> bool: # noqa: ARG001
43
+ ...
44
+
45
+ else:
46
+ # v1 re-exports
47
+ if PYDANTIC_V1:
48
+ from pydantic.typing import (
49
+ get_args as get_args,
50
+ is_union as is_union,
51
+ get_origin as get_origin,
52
+ is_typeddict as is_typeddict,
53
+ is_literal_type as is_literal_type,
54
+ )
55
+ from pydantic.datetime_parse import parse_date as parse_date, parse_datetime as parse_datetime
56
+ else:
57
+ from ._utils import (
58
+ get_args as get_args,
59
+ is_union as is_union,
60
+ get_origin as get_origin,
61
+ parse_date as parse_date,
62
+ is_typeddict as is_typeddict,
63
+ parse_datetime as parse_datetime,
64
+ is_literal_type as is_literal_type,
65
+ )
66
+
67
+
68
+ # refactored config
69
+ if TYPE_CHECKING:
70
+ from pydantic import ConfigDict as ConfigDict
71
+ else:
72
+ if PYDANTIC_V1:
73
+ # TODO: provide an error message here?
74
+ ConfigDict = None
75
+ else:
76
+ from pydantic import ConfigDict as ConfigDict
77
+
78
+
79
+ # renamed methods / properties
80
+ def parse_obj(model: type[_ModelT], value: object) -> _ModelT:
81
+ if PYDANTIC_V1:
82
+ return cast(_ModelT, model.parse_obj(value)) # pyright: ignore[reportDeprecated, reportUnnecessaryCast]
83
+ else:
84
+ return model.model_validate(value)
85
+
86
+
87
+ def field_is_required(field: FieldInfo) -> bool:
88
+ if PYDANTIC_V1:
89
+ return field.required # type: ignore
90
+ return field.is_required()
91
+
92
+
93
+ def field_get_default(field: FieldInfo) -> Any:
94
+ value = field.get_default()
95
+ if PYDANTIC_V1:
96
+ return value
97
+ from pydantic_core import PydanticUndefined
98
+
99
+ if value == PydanticUndefined:
100
+ return None
101
+ return value
102
+
103
+
104
+ def field_outer_type(field: FieldInfo) -> Any:
105
+ if PYDANTIC_V1:
106
+ return field.outer_type_ # type: ignore
107
+ return field.annotation
108
+
109
+
110
+ def get_model_config(model: type[pydantic.BaseModel]) -> Any:
111
+ if PYDANTIC_V1:
112
+ return model.__config__ # type: ignore
113
+ return model.model_config
114
+
115
+
116
+ def get_model_fields(model: type[pydantic.BaseModel]) -> dict[str, FieldInfo]:
117
+ if PYDANTIC_V1:
118
+ return model.__fields__ # type: ignore
119
+ return model.model_fields
120
+
121
+
122
+ def model_copy(model: _ModelT, *, deep: bool = False) -> _ModelT:
123
+ if PYDANTIC_V1:
124
+ return model.copy(deep=deep) # type: ignore
125
+ return model.model_copy(deep=deep)
126
+
127
+
128
+ def model_json(model: pydantic.BaseModel, *, indent: int | None = None) -> str:
129
+ if PYDANTIC_V1:
130
+ return model.json(indent=indent) # type: ignore
131
+ return model.model_dump_json(indent=indent)
132
+
133
+
134
+ def model_dump(
135
+ model: pydantic.BaseModel,
136
+ *,
137
+ exclude: IncEx | None = None,
138
+ exclude_unset: bool = False,
139
+ exclude_defaults: bool = False,
140
+ warnings: bool = True,
141
+ mode: Literal["json", "python"] = "python",
142
+ ) -> dict[str, Any]:
143
+ if (not PYDANTIC_V1) or hasattr(model, "model_dump"):
144
+ return model.model_dump(
145
+ mode=mode,
146
+ exclude=exclude,
147
+ exclude_unset=exclude_unset,
148
+ exclude_defaults=exclude_defaults,
149
+ # warnings are not supported in Pydantic v1
150
+ warnings=True if PYDANTIC_V1 else warnings,
151
+ )
152
+ return cast(
153
+ "dict[str, Any]",
154
+ model.dict( # pyright: ignore[reportDeprecated, reportUnnecessaryCast]
155
+ exclude=exclude,
156
+ exclude_unset=exclude_unset,
157
+ exclude_defaults=exclude_defaults,
158
+ ),
159
+ )
160
+
161
+
162
+ def model_parse(model: type[_ModelT], data: Any) -> _ModelT:
163
+ if PYDANTIC_V1:
164
+ return model.parse_obj(data) # pyright: ignore[reportDeprecated]
165
+ return model.model_validate(data)
166
+
167
+
168
+ # generic models
169
+ if TYPE_CHECKING:
170
+
171
+ class GenericModel(pydantic.BaseModel): ...
172
+
173
+ else:
174
+ if PYDANTIC_V1:
175
+ import pydantic.generics
176
+
177
+ class GenericModel(pydantic.generics.GenericModel, pydantic.BaseModel): ...
178
+ else:
179
+ # there no longer needs to be a distinction in v2 but
180
+ # we still have to create our own subclass to avoid
181
+ # inconsistent MRO ordering errors
182
+ class GenericModel(pydantic.BaseModel): ...
183
+
184
+
185
+ # cached properties
186
+ if TYPE_CHECKING:
187
+ cached_property = property
188
+
189
+ # we define a separate type (copied from typeshed)
190
+ # that represents that `cached_property` is `set`able
191
+ # at runtime, which differs from `@property`.
192
+ #
193
+ # this is a separate type as editors likely special case
194
+ # `@property` and we don't want to cause issues just to have
195
+ # more helpful internal types.
196
+
197
+ class typed_cached_property(Generic[_T]):
198
+ func: Callable[[Any], _T]
199
+ attrname: str | None
200
+
201
+ def __init__(self, func: Callable[[Any], _T]) -> None: ...
202
+
203
+ @overload
204
+ def __get__(self, instance: None, owner: type[Any] | None = None) -> Self: ...
205
+
206
+ @overload
207
+ def __get__(self, instance: object, owner: type[Any] | None = None) -> _T: ...
208
+
209
+ def __get__(self, instance: object, owner: type[Any] | None = None) -> _T | Self:
210
+ raise NotImplementedError()
211
+
212
+ def __set_name__(self, owner: type[Any], name: str) -> None: ...
213
+
214
+ # __set__ is not defined at runtime, but @cached_property is designed to be settable
215
+ def __set__(self, instance: object, value: _T) -> None: ...
216
+ else:
217
+ from functools import cached_property as cached_property
218
+
219
+ typed_cached_property = cached_property
profound/_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