payi 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.

Potentially problematic release.


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

Files changed (54) hide show
  1. payi/__init__.py +83 -0
  2. payi/_base_client.py +2006 -0
  3. payi/_client.py +414 -0
  4. payi/_compat.py +222 -0
  5. payi/_constants.py +14 -0
  6. payi/_exceptions.py +108 -0
  7. payi/_files.py +127 -0
  8. payi/_models.py +739 -0
  9. payi/_qs.py +150 -0
  10. payi/_resource.py +43 -0
  11. payi/_response.py +820 -0
  12. payi/_streaming.py +333 -0
  13. payi/_types.py +220 -0
  14. payi/_utils/__init__.py +52 -0
  15. payi/_utils/_logs.py +25 -0
  16. payi/_utils/_proxy.py +63 -0
  17. payi/_utils/_reflection.py +8 -0
  18. payi/_utils/_streams.py +12 -0
  19. payi/_utils/_sync.py +81 -0
  20. payi/_utils/_transform.py +382 -0
  21. payi/_utils/_typing.py +120 -0
  22. payi/_utils/_utils.py +402 -0
  23. payi/_version.py +4 -0
  24. payi/lib/.keep +4 -0
  25. payi/py.typed +0 -0
  26. payi/resources/__init__.py +33 -0
  27. payi/resources/budgets/__init__.py +33 -0
  28. payi/resources/budgets/budgets.py +717 -0
  29. payi/resources/budgets/tags.py +529 -0
  30. payi/resources/ingest_requests.py +187 -0
  31. payi/types/__init__.py +13 -0
  32. payi/types/budget_create_params.py +26 -0
  33. payi/types/budget_history_response.py +110 -0
  34. payi/types/budget_list_params.py +25 -0
  35. payi/types/budget_response.py +98 -0
  36. payi/types/budget_update_params.py +17 -0
  37. payi/types/budgets/__init__.py +13 -0
  38. payi/types/budgets/budget_tags_response.py +18 -0
  39. payi/types/budgets/tag_create_params.py +16 -0
  40. payi/types/budgets/tag_create_response.py +9 -0
  41. payi/types/budgets/tag_delete_response.py +9 -0
  42. payi/types/budgets/tag_list_response.py +9 -0
  43. payi/types/budgets/tag_remove_params.py +16 -0
  44. payi/types/budgets/tag_remove_response.py +9 -0
  45. payi/types/budgets/tag_update_params.py +16 -0
  46. payi/types/budgets/tag_update_response.py +9 -0
  47. payi/types/default_response.py +13 -0
  48. payi/types/ingest_request_create_params.py +27 -0
  49. payi/types/paged_budget_list.py +110 -0
  50. payi/types/successful_proxy_result.py +43 -0
  51. payi-0.1.0a1.dist-info/METADATA +355 -0
  52. payi-0.1.0a1.dist-info/RECORD +54 -0
  53. payi-0.1.0a1.dist-info/WHEEL +4 -0
  54. payi-0.1.0a1.dist-info/licenses/LICENSE +201 -0
payi/_client.py ADDED
@@ -0,0 +1,414 @@
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 resources, _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 (
23
+ is_given,
24
+ get_async_library,
25
+ )
26
+ from ._version import __version__
27
+ from ._streaming import Stream as Stream, AsyncStream as AsyncStream
28
+ from ._exceptions import PayiError, APIStatusError
29
+ from ._base_client import (
30
+ DEFAULT_MAX_RETRIES,
31
+ SyncAPIClient,
32
+ AsyncAPIClient,
33
+ )
34
+
35
+ __all__ = [
36
+ "Timeout",
37
+ "Transport",
38
+ "ProxiesTypes",
39
+ "RequestOptions",
40
+ "resources",
41
+ "Payi",
42
+ "AsyncPayi",
43
+ "Client",
44
+ "AsyncClient",
45
+ ]
46
+
47
+
48
+ class Payi(SyncAPIClient):
49
+ budgets: resources.BudgetsResource
50
+ ingest_requests: resources.IngestRequestsResource
51
+ with_raw_response: PayiWithRawResponse
52
+ with_streaming_response: PayiWithStreamedResponse
53
+
54
+ # client options
55
+ payi_api_key: str
56
+
57
+ def __init__(
58
+ self,
59
+ *,
60
+ payi_api_key: str | None = None,
61
+ base_url: str | httpx.URL | None = None,
62
+ timeout: Union[float, Timeout, None, NotGiven] = NOT_GIVEN,
63
+ max_retries: int = DEFAULT_MAX_RETRIES,
64
+ default_headers: Mapping[str, str] | None = None,
65
+ default_query: Mapping[str, object] | None = None,
66
+ # Configure a custom httpx client.
67
+ # We provide a `DefaultHttpxClient` class that you can pass to retain the default values we use for `limits`, `timeout` & `follow_redirects`.
68
+ # See the [httpx documentation](https://www.python-httpx.org/api/#client) for more details.
69
+ http_client: httpx.Client | None = None,
70
+ # Enable or disable schema validation for data returned by the API.
71
+ # When enabled an error APIResponseValidationError is raised
72
+ # if the API responds with invalid data for the expected schema.
73
+ #
74
+ # This parameter may be removed or changed in the future.
75
+ # If you rely on this feature, please open a GitHub issue
76
+ # outlining your use-case to help us decide if it should be
77
+ # part of our public interface in the future.
78
+ _strict_response_validation: bool = False,
79
+ ) -> None:
80
+ """Construct a new synchronous payi client instance.
81
+
82
+ This automatically infers the `payi_api_key` argument from the `PAYI_API_KEY` environment variable if it is not provided.
83
+ """
84
+ if payi_api_key is None:
85
+ payi_api_key = os.environ.get("PAYI_API_KEY")
86
+ if payi_api_key is None:
87
+ raise PayiError(
88
+ "The payi_api_key client option must be set either by passing payi_api_key to the client or by setting the PAYI_API_KEY environment variable"
89
+ )
90
+ self.payi_api_key = payi_api_key
91
+
92
+ if base_url is None:
93
+ base_url = os.environ.get("PAYI_BASE_URL")
94
+ if base_url is None:
95
+ base_url = f"https://apim-payi-prod-eastus.azure-api.net"
96
+
97
+ super().__init__(
98
+ version=__version__,
99
+ base_url=base_url,
100
+ max_retries=max_retries,
101
+ timeout=timeout,
102
+ http_client=http_client,
103
+ custom_headers=default_headers,
104
+ custom_query=default_query,
105
+ _strict_response_validation=_strict_response_validation,
106
+ )
107
+
108
+ self.budgets = resources.BudgetsResource(self)
109
+ self.ingest_requests = resources.IngestRequestsResource(self)
110
+ self.with_raw_response = PayiWithRawResponse(self)
111
+ self.with_streaming_response = PayiWithStreamedResponse(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
+ payi_api_key = self.payi_api_key
122
+ return {"Authorization": payi_api_key}
123
+
124
+ @property
125
+ @override
126
+ def default_headers(self) -> dict[str, str | Omit]:
127
+ return {
128
+ **super().default_headers,
129
+ "X-Stainless-Async": "false",
130
+ **self._custom_headers,
131
+ }
132
+
133
+ def copy(
134
+ self,
135
+ *,
136
+ payi_api_key: str | None = None,
137
+ base_url: str | httpx.URL | None = None,
138
+ timeout: float | Timeout | None | NotGiven = NOT_GIVEN,
139
+ http_client: httpx.Client | None = None,
140
+ max_retries: int | NotGiven = NOT_GIVEN,
141
+ default_headers: Mapping[str, str] | None = None,
142
+ set_default_headers: Mapping[str, str] | None = None,
143
+ default_query: Mapping[str, object] | None = None,
144
+ set_default_query: Mapping[str, object] | None = None,
145
+ _extra_kwargs: Mapping[str, Any] = {},
146
+ ) -> Self:
147
+ """
148
+ Create a new client instance re-using the same options given to the current client with optional overriding.
149
+ """
150
+ if default_headers is not None and set_default_headers is not None:
151
+ raise ValueError("The `default_headers` and `set_default_headers` arguments are mutually exclusive")
152
+
153
+ if default_query is not None and set_default_query is not None:
154
+ raise ValueError("The `default_query` and `set_default_query` arguments are mutually exclusive")
155
+
156
+ headers = self._custom_headers
157
+ if default_headers is not None:
158
+ headers = {**headers, **default_headers}
159
+ elif set_default_headers is not None:
160
+ headers = set_default_headers
161
+
162
+ params = self._custom_query
163
+ if default_query is not None:
164
+ params = {**params, **default_query}
165
+ elif set_default_query is not None:
166
+ params = set_default_query
167
+
168
+ http_client = http_client or self._client
169
+ return self.__class__(
170
+ payi_api_key=payi_api_key or self.payi_api_key,
171
+ base_url=base_url or self.base_url,
172
+ timeout=self.timeout if isinstance(timeout, NotGiven) else timeout,
173
+ http_client=http_client,
174
+ max_retries=max_retries if is_given(max_retries) else self.max_retries,
175
+ default_headers=headers,
176
+ default_query=params,
177
+ **_extra_kwargs,
178
+ )
179
+
180
+ # Alias for `copy` for nicer inline usage, e.g.
181
+ # client.with_options(timeout=10).foo.create(...)
182
+ with_options = copy
183
+
184
+ @override
185
+ def _make_status_error(
186
+ self,
187
+ err_msg: str,
188
+ *,
189
+ body: object,
190
+ response: httpx.Response,
191
+ ) -> APIStatusError:
192
+ if response.status_code == 400:
193
+ return _exceptions.BadRequestError(err_msg, response=response, body=body)
194
+
195
+ if response.status_code == 401:
196
+ return _exceptions.AuthenticationError(err_msg, response=response, body=body)
197
+
198
+ if response.status_code == 403:
199
+ return _exceptions.PermissionDeniedError(err_msg, response=response, body=body)
200
+
201
+ if response.status_code == 404:
202
+ return _exceptions.NotFoundError(err_msg, response=response, body=body)
203
+
204
+ if response.status_code == 409:
205
+ return _exceptions.ConflictError(err_msg, response=response, body=body)
206
+
207
+ if response.status_code == 422:
208
+ return _exceptions.UnprocessableEntityError(err_msg, response=response, body=body)
209
+
210
+ if response.status_code == 429:
211
+ return _exceptions.RateLimitError(err_msg, response=response, body=body)
212
+
213
+ if response.status_code >= 500:
214
+ return _exceptions.InternalServerError(err_msg, response=response, body=body)
215
+ return APIStatusError(err_msg, response=response, body=body)
216
+
217
+
218
+ class AsyncPayi(AsyncAPIClient):
219
+ budgets: resources.AsyncBudgetsResource
220
+ ingest_requests: resources.AsyncIngestRequestsResource
221
+ with_raw_response: AsyncPayiWithRawResponse
222
+ with_streaming_response: AsyncPayiWithStreamedResponse
223
+
224
+ # client options
225
+ payi_api_key: str
226
+
227
+ def __init__(
228
+ self,
229
+ *,
230
+ payi_api_key: str | None = None,
231
+ base_url: str | httpx.URL | None = None,
232
+ timeout: Union[float, Timeout, None, NotGiven] = NOT_GIVEN,
233
+ max_retries: int = DEFAULT_MAX_RETRIES,
234
+ default_headers: Mapping[str, str] | None = None,
235
+ default_query: Mapping[str, object] | None = None,
236
+ # Configure a custom httpx client.
237
+ # We provide a `DefaultAsyncHttpxClient` class that you can pass to retain the default values we use for `limits`, `timeout` & `follow_redirects`.
238
+ # See the [httpx documentation](https://www.python-httpx.org/api/#asyncclient) for more details.
239
+ http_client: httpx.AsyncClient | None = None,
240
+ # Enable or disable schema validation for data returned by the API.
241
+ # When enabled an error APIResponseValidationError is raised
242
+ # if the API responds with invalid data for the expected schema.
243
+ #
244
+ # This parameter may be removed or changed in the future.
245
+ # If you rely on this feature, please open a GitHub issue
246
+ # outlining your use-case to help us decide if it should be
247
+ # part of our public interface in the future.
248
+ _strict_response_validation: bool = False,
249
+ ) -> None:
250
+ """Construct a new async payi client instance.
251
+
252
+ This automatically infers the `payi_api_key` argument from the `PAYI_API_KEY` environment variable if it is not provided.
253
+ """
254
+ if payi_api_key is None:
255
+ payi_api_key = os.environ.get("PAYI_API_KEY")
256
+ if payi_api_key is None:
257
+ raise PayiError(
258
+ "The payi_api_key client option must be set either by passing payi_api_key to the client or by setting the PAYI_API_KEY environment variable"
259
+ )
260
+ self.payi_api_key = payi_api_key
261
+
262
+ if base_url is None:
263
+ base_url = os.environ.get("PAYI_BASE_URL")
264
+ if base_url is None:
265
+ base_url = f"https://apim-payi-prod-eastus.azure-api.net"
266
+
267
+ super().__init__(
268
+ version=__version__,
269
+ base_url=base_url,
270
+ max_retries=max_retries,
271
+ timeout=timeout,
272
+ http_client=http_client,
273
+ custom_headers=default_headers,
274
+ custom_query=default_query,
275
+ _strict_response_validation=_strict_response_validation,
276
+ )
277
+
278
+ self.budgets = resources.AsyncBudgetsResource(self)
279
+ self.ingest_requests = resources.AsyncIngestRequestsResource(self)
280
+ self.with_raw_response = AsyncPayiWithRawResponse(self)
281
+ self.with_streaming_response = AsyncPayiWithStreamedResponse(self)
282
+
283
+ @property
284
+ @override
285
+ def qs(self) -> Querystring:
286
+ return Querystring(array_format="comma")
287
+
288
+ @property
289
+ @override
290
+ def auth_headers(self) -> dict[str, str]:
291
+ payi_api_key = self.payi_api_key
292
+ return {"Authorization": payi_api_key}
293
+
294
+ @property
295
+ @override
296
+ def default_headers(self) -> dict[str, str | Omit]:
297
+ return {
298
+ **super().default_headers,
299
+ "X-Stainless-Async": f"async:{get_async_library()}",
300
+ **self._custom_headers,
301
+ }
302
+
303
+ def copy(
304
+ self,
305
+ *,
306
+ payi_api_key: str | None = None,
307
+ base_url: str | httpx.URL | None = None,
308
+ timeout: float | Timeout | None | NotGiven = NOT_GIVEN,
309
+ http_client: httpx.AsyncClient | None = None,
310
+ max_retries: int | NotGiven = NOT_GIVEN,
311
+ default_headers: Mapping[str, str] | None = None,
312
+ set_default_headers: Mapping[str, str] | None = None,
313
+ default_query: Mapping[str, object] | None = None,
314
+ set_default_query: Mapping[str, object] | None = None,
315
+ _extra_kwargs: Mapping[str, Any] = {},
316
+ ) -> Self:
317
+ """
318
+ Create a new client instance re-using the same options given to the current client with optional overriding.
319
+ """
320
+ if default_headers is not None and set_default_headers is not None:
321
+ raise ValueError("The `default_headers` and `set_default_headers` arguments are mutually exclusive")
322
+
323
+ if default_query is not None and set_default_query is not None:
324
+ raise ValueError("The `default_query` and `set_default_query` arguments are mutually exclusive")
325
+
326
+ headers = self._custom_headers
327
+ if default_headers is not None:
328
+ headers = {**headers, **default_headers}
329
+ elif set_default_headers is not None:
330
+ headers = set_default_headers
331
+
332
+ params = self._custom_query
333
+ if default_query is not None:
334
+ params = {**params, **default_query}
335
+ elif set_default_query is not None:
336
+ params = set_default_query
337
+
338
+ http_client = http_client or self._client
339
+ return self.__class__(
340
+ payi_api_key=payi_api_key or self.payi_api_key,
341
+ base_url=base_url or self.base_url,
342
+ timeout=self.timeout if isinstance(timeout, NotGiven) else timeout,
343
+ http_client=http_client,
344
+ max_retries=max_retries if is_given(max_retries) else self.max_retries,
345
+ default_headers=headers,
346
+ default_query=params,
347
+ **_extra_kwargs,
348
+ )
349
+
350
+ # Alias for `copy` for nicer inline usage, e.g.
351
+ # client.with_options(timeout=10).foo.create(...)
352
+ with_options = copy
353
+
354
+ @override
355
+ def _make_status_error(
356
+ self,
357
+ err_msg: str,
358
+ *,
359
+ body: object,
360
+ response: httpx.Response,
361
+ ) -> APIStatusError:
362
+ if response.status_code == 400:
363
+ return _exceptions.BadRequestError(err_msg, response=response, body=body)
364
+
365
+ if response.status_code == 401:
366
+ return _exceptions.AuthenticationError(err_msg, response=response, body=body)
367
+
368
+ if response.status_code == 403:
369
+ return _exceptions.PermissionDeniedError(err_msg, response=response, body=body)
370
+
371
+ if response.status_code == 404:
372
+ return _exceptions.NotFoundError(err_msg, response=response, body=body)
373
+
374
+ if response.status_code == 409:
375
+ return _exceptions.ConflictError(err_msg, response=response, body=body)
376
+
377
+ if response.status_code == 422:
378
+ return _exceptions.UnprocessableEntityError(err_msg, response=response, body=body)
379
+
380
+ if response.status_code == 429:
381
+ return _exceptions.RateLimitError(err_msg, response=response, body=body)
382
+
383
+ if response.status_code >= 500:
384
+ return _exceptions.InternalServerError(err_msg, response=response, body=body)
385
+ return APIStatusError(err_msg, response=response, body=body)
386
+
387
+
388
+ class PayiWithRawResponse:
389
+ def __init__(self, client: Payi) -> None:
390
+ self.budgets = resources.BudgetsResourceWithRawResponse(client.budgets)
391
+ self.ingest_requests = resources.IngestRequestsResourceWithRawResponse(client.ingest_requests)
392
+
393
+
394
+ class AsyncPayiWithRawResponse:
395
+ def __init__(self, client: AsyncPayi) -> None:
396
+ self.budgets = resources.AsyncBudgetsResourceWithRawResponse(client.budgets)
397
+ self.ingest_requests = resources.AsyncIngestRequestsResourceWithRawResponse(client.ingest_requests)
398
+
399
+
400
+ class PayiWithStreamedResponse:
401
+ def __init__(self, client: Payi) -> None:
402
+ self.budgets = resources.BudgetsResourceWithStreamingResponse(client.budgets)
403
+ self.ingest_requests = resources.IngestRequestsResourceWithStreamingResponse(client.ingest_requests)
404
+
405
+
406
+ class AsyncPayiWithStreamedResponse:
407
+ def __init__(self, client: AsyncPayi) -> None:
408
+ self.budgets = resources.AsyncBudgetsResourceWithStreamingResponse(client.budgets)
409
+ self.ingest_requests = resources.AsyncIngestRequestsResourceWithStreamingResponse(client.ingest_requests)
410
+
411
+
412
+ Client = Payi
413
+
414
+ AsyncClient = AsyncPayi
payi/_compat.py ADDED
@@ -0,0 +1,222 @@
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
6
+
7
+ import pydantic
8
+ from pydantic.fields import FieldInfo
9
+
10
+ from ._types import 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) -> _ModelT:
122
+ if PYDANTIC_V2:
123
+ return model.model_copy()
124
+ return model.copy() # 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_unset: bool = False,
137
+ exclude_defaults: bool = False,
138
+ ) -> dict[str, Any]:
139
+ if PYDANTIC_V2:
140
+ return model.model_dump(
141
+ exclude_unset=exclude_unset,
142
+ exclude_defaults=exclude_defaults,
143
+ )
144
+ return cast(
145
+ "dict[str, Any]",
146
+ model.dict( # pyright: ignore[reportDeprecated, reportUnnecessaryCast]
147
+ exclude_unset=exclude_unset,
148
+ exclude_defaults=exclude_defaults,
149
+ ),
150
+ )
151
+
152
+
153
+ def model_parse(model: type[_ModelT], data: Any) -> _ModelT:
154
+ if PYDANTIC_V2:
155
+ return model.model_validate(data)
156
+ return model.parse_obj(data) # pyright: ignore[reportDeprecated]
157
+
158
+
159
+ # generic models
160
+ if TYPE_CHECKING:
161
+
162
+ class GenericModel(pydantic.BaseModel):
163
+ ...
164
+
165
+ else:
166
+ if PYDANTIC_V2:
167
+ # there no longer needs to be a distinction in v2 but
168
+ # we still have to create our own subclass to avoid
169
+ # inconsistent MRO ordering errors
170
+ class GenericModel(pydantic.BaseModel):
171
+ ...
172
+
173
+ else:
174
+ import pydantic.generics
175
+
176
+ class GenericModel(pydantic.generics.GenericModel, pydantic.BaseModel):
177
+ ...
178
+
179
+
180
+ # cached properties
181
+ if TYPE_CHECKING:
182
+ cached_property = property
183
+
184
+ # we define a separate type (copied from typeshed)
185
+ # that represents that `cached_property` is `set`able
186
+ # at runtime, which differs from `@property`.
187
+ #
188
+ # this is a separate type as editors likely special case
189
+ # `@property` and we don't want to cause issues just to have
190
+ # more helpful internal types.
191
+
192
+ class typed_cached_property(Generic[_T]):
193
+ func: Callable[[Any], _T]
194
+ attrname: str | None
195
+
196
+ def __init__(self, func: Callable[[Any], _T]) -> None:
197
+ ...
198
+
199
+ @overload
200
+ def __get__(self, instance: None, owner: type[Any] | None = None) -> Self:
201
+ ...
202
+
203
+ @overload
204
+ def __get__(self, instance: object, owner: type[Any] | None = None) -> _T:
205
+ ...
206
+
207
+ def __get__(self, instance: object, owner: type[Any] | None = None) -> _T | Self:
208
+ raise NotImplementedError()
209
+
210
+ def __set_name__(self, owner: type[Any], name: str) -> None:
211
+ ...
212
+
213
+ # __set__ is not defined at runtime, but @cached_property is designed to be settable
214
+ def __set__(self, instance: object, value: _T) -> None:
215
+ ...
216
+ else:
217
+ try:
218
+ from functools import cached_property as cached_property
219
+ except ImportError:
220
+ from cached_property import cached_property as cached_property
221
+
222
+ typed_cached_property = cached_property
payi/_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.0, 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