lark-billing 0.5.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 (81) hide show
  1. lark/__init__.py +92 -0
  2. lark/_base_client.py +1995 -0
  3. lark/_client.py +459 -0
  4. lark/_compat.py +219 -0
  5. lark/_constants.py +14 -0
  6. lark/_exceptions.py +108 -0
  7. lark/_files.py +123 -0
  8. lark/_models.py +857 -0
  9. lark/_qs.py +150 -0
  10. lark/_resource.py +43 -0
  11. lark/_response.py +830 -0
  12. lark/_streaming.py +333 -0
  13. lark/_types.py +261 -0
  14. lark/_utils/__init__.py +64 -0
  15. lark/_utils/_compat.py +45 -0
  16. lark/_utils/_datetime_parse.py +136 -0
  17. lark/_utils/_logs.py +25 -0
  18. lark/_utils/_proxy.py +65 -0
  19. lark/_utils/_reflection.py +42 -0
  20. lark/_utils/_resources_proxy.py +24 -0
  21. lark/_utils/_streams.py +12 -0
  22. lark/_utils/_sync.py +58 -0
  23. lark/_utils/_transform.py +457 -0
  24. lark/_utils/_typing.py +156 -0
  25. lark/_utils/_utils.py +421 -0
  26. lark/_version.py +4 -0
  27. lark/lib/.keep +4 -0
  28. lark/py.typed +0 -0
  29. lark/resources/__init__.py +117 -0
  30. lark/resources/customer_access.py +167 -0
  31. lark/resources/customer_portal.py +187 -0
  32. lark/resources/invoices.py +191 -0
  33. lark/resources/pricing_metrics.py +499 -0
  34. lark/resources/rate_cards.py +395 -0
  35. lark/resources/subjects.py +579 -0
  36. lark/resources/subscriptions.py +647 -0
  37. lark/resources/usage_events.py +221 -0
  38. lark/types/__init__.py +53 -0
  39. lark/types/amount_input_param.py +16 -0
  40. lark/types/amount_output.py +13 -0
  41. lark/types/checkout_callback_param.py +15 -0
  42. lark/types/customer_access_retrieve_billing_state_response.py +40 -0
  43. lark/types/customer_portal_create_session_params.py +18 -0
  44. lark/types/customer_portal_create_session_response.py +18 -0
  45. lark/types/flat_price_input_param.py +17 -0
  46. lark/types/flat_price_output.py +17 -0
  47. lark/types/invoice_list_params.py +16 -0
  48. lark/types/invoice_list_response.py +49 -0
  49. lark/types/package_price_input_param.py +24 -0
  50. lark/types/package_price_output.py +24 -0
  51. lark/types/period.py +18 -0
  52. lark/types/period_param.py +21 -0
  53. lark/types/pricing_metric_create_params.py +98 -0
  54. lark/types/pricing_metric_create_summary_params.py +25 -0
  55. lark/types/pricing_metric_create_summary_response.py +36 -0
  56. lark/types/pricing_metric_list_params.py +11 -0
  57. lark/types/pricing_metric_list_response.py +14 -0
  58. lark/types/pricing_metric_resource.py +72 -0
  59. lark/types/rate_card_create_params.py +148 -0
  60. lark/types/rate_card_list_params.py +13 -0
  61. lark/types/rate_card_list_response.py +14 -0
  62. lark/types/rate_card_resource.py +141 -0
  63. lark/types/subject_create_params.py +29 -0
  64. lark/types/subject_create_response.py +34 -0
  65. lark/types/subject_list_params.py +13 -0
  66. lark/types/subject_list_response.py +14 -0
  67. lark/types/subject_resource.py +34 -0
  68. lark/types/subject_update_params.py +22 -0
  69. lark/types/subscription_cancel_params.py +16 -0
  70. lark/types/subscription_change_rate_card_params.py +29 -0
  71. lark/types/subscription_change_rate_card_response.py +55 -0
  72. lark/types/subscription_create_params.py +38 -0
  73. lark/types/subscription_create_response.py +55 -0
  74. lark/types/subscription_list_params.py +26 -0
  75. lark/types/subscription_list_response.py +14 -0
  76. lark/types/subscription_resource.py +49 -0
  77. lark/types/usage_event_create_params.py +41 -0
  78. lark_billing-0.5.0.dist-info/METADATA +431 -0
  79. lark_billing-0.5.0.dist-info/RECORD +81 -0
  80. lark_billing-0.5.0.dist-info/WHEEL +4 -0
  81. lark_billing-0.5.0.dist-info/licenses/LICENSE +201 -0
lark/_client.py ADDED
@@ -0,0 +1,459 @@
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
+ Timeout,
16
+ NotGiven,
17
+ Transport,
18
+ ProxiesTypes,
19
+ RequestOptions,
20
+ not_given,
21
+ )
22
+ from ._utils import is_given, get_async_library
23
+ from ._version import __version__
24
+ from .resources import (
25
+ invoices,
26
+ subjects,
27
+ rate_cards,
28
+ usage_events,
29
+ subscriptions,
30
+ customer_access,
31
+ customer_portal,
32
+ pricing_metrics,
33
+ )
34
+ from ._streaming import Stream as Stream, AsyncStream as AsyncStream
35
+ from ._exceptions import LarkError, APIStatusError
36
+ from ._base_client import (
37
+ DEFAULT_MAX_RETRIES,
38
+ SyncAPIClient,
39
+ AsyncAPIClient,
40
+ )
41
+
42
+ __all__ = ["Timeout", "Transport", "ProxiesTypes", "RequestOptions", "Lark", "AsyncLark", "Client", "AsyncClient"]
43
+
44
+
45
+ class Lark(SyncAPIClient):
46
+ customer_portal: customer_portal.CustomerPortalResource
47
+ rate_cards: rate_cards.RateCardsResource
48
+ usage_events: usage_events.UsageEventsResource
49
+ subscriptions: subscriptions.SubscriptionsResource
50
+ subjects: subjects.SubjectsResource
51
+ pricing_metrics: pricing_metrics.PricingMetricsResource
52
+ customer_access: customer_access.CustomerAccessResource
53
+ invoices: invoices.InvoicesResource
54
+ with_raw_response: LarkWithRawResponse
55
+ with_streaming_response: LarkWithStreamedResponse
56
+
57
+ # client options
58
+ api_key: str
59
+
60
+ def __init__(
61
+ self,
62
+ *,
63
+ api_key: str | None = None,
64
+ base_url: str | httpx.URL | None = None,
65
+ timeout: float | Timeout | None | NotGiven = not_given,
66
+ max_retries: int = DEFAULT_MAX_RETRIES,
67
+ default_headers: Mapping[str, str] | None = None,
68
+ default_query: Mapping[str, object] | None = None,
69
+ # Configure a custom httpx client.
70
+ # We provide a `DefaultHttpxClient` class that you can pass to retain the default values we use for `limits`, `timeout` & `follow_redirects`.
71
+ # See the [httpx documentation](https://www.python-httpx.org/api/#client) for more details.
72
+ http_client: httpx.Client | None = None,
73
+ # Enable or disable schema validation for data returned by the API.
74
+ # When enabled an error APIResponseValidationError is raised
75
+ # if the API responds with invalid data for the expected schema.
76
+ #
77
+ # This parameter may be removed or changed in the future.
78
+ # If you rely on this feature, please open a GitHub issue
79
+ # outlining your use-case to help us decide if it should be
80
+ # part of our public interface in the future.
81
+ _strict_response_validation: bool = False,
82
+ ) -> None:
83
+ """Construct a new synchronous Lark client instance.
84
+
85
+ This automatically infers the `api_key` argument from the `LARK_API_KEY` environment variable if it is not provided.
86
+ """
87
+ if api_key is None:
88
+ api_key = os.environ.get("LARK_API_KEY")
89
+ if api_key is None:
90
+ raise LarkError(
91
+ "The api_key client option must be set either by passing api_key to the client or by setting the LARK_API_KEY environment variable"
92
+ )
93
+ self.api_key = api_key
94
+
95
+ if base_url is None:
96
+ base_url = os.environ.get("LARK_BASE_URL")
97
+ if base_url is None:
98
+ base_url = f"https://api.uselark.ai"
99
+
100
+ super().__init__(
101
+ version=__version__,
102
+ base_url=base_url,
103
+ max_retries=max_retries,
104
+ timeout=timeout,
105
+ http_client=http_client,
106
+ custom_headers=default_headers,
107
+ custom_query=default_query,
108
+ _strict_response_validation=_strict_response_validation,
109
+ )
110
+
111
+ self.customer_portal = customer_portal.CustomerPortalResource(self)
112
+ self.rate_cards = rate_cards.RateCardsResource(self)
113
+ self.usage_events = usage_events.UsageEventsResource(self)
114
+ self.subscriptions = subscriptions.SubscriptionsResource(self)
115
+ self.subjects = subjects.SubjectsResource(self)
116
+ self.pricing_metrics = pricing_metrics.PricingMetricsResource(self)
117
+ self.customer_access = customer_access.CustomerAccessResource(self)
118
+ self.invoices = invoices.InvoicesResource(self)
119
+ self.with_raw_response = LarkWithRawResponse(self)
120
+ self.with_streaming_response = LarkWithStreamedResponse(self)
121
+
122
+ @property
123
+ @override
124
+ def qs(self) -> Querystring:
125
+ return Querystring(array_format="comma")
126
+
127
+ @property
128
+ @override
129
+ def auth_headers(self) -> dict[str, str]:
130
+ api_key = self.api_key
131
+ return {"X-API-Key": api_key}
132
+
133
+ @property
134
+ @override
135
+ def default_headers(self) -> dict[str, str | Omit]:
136
+ return {
137
+ **super().default_headers,
138
+ "X-Stainless-Async": "false",
139
+ **self._custom_headers,
140
+ }
141
+
142
+ def copy(
143
+ self,
144
+ *,
145
+ api_key: str | None = None,
146
+ base_url: str | httpx.URL | None = None,
147
+ timeout: float | Timeout | None | NotGiven = not_given,
148
+ http_client: httpx.Client | None = None,
149
+ max_retries: int | NotGiven = not_given,
150
+ default_headers: Mapping[str, str] | None = None,
151
+ set_default_headers: Mapping[str, str] | None = None,
152
+ default_query: Mapping[str, object] | None = None,
153
+ set_default_query: Mapping[str, object] | None = None,
154
+ _extra_kwargs: Mapping[str, Any] = {},
155
+ ) -> Self:
156
+ """
157
+ Create a new client instance re-using the same options given to the current client with optional overriding.
158
+ """
159
+ if default_headers is not None and set_default_headers is not None:
160
+ raise ValueError("The `default_headers` and `set_default_headers` arguments are mutually exclusive")
161
+
162
+ if default_query is not None and set_default_query is not None:
163
+ raise ValueError("The `default_query` and `set_default_query` arguments are mutually exclusive")
164
+
165
+ headers = self._custom_headers
166
+ if default_headers is not None:
167
+ headers = {**headers, **default_headers}
168
+ elif set_default_headers is not None:
169
+ headers = set_default_headers
170
+
171
+ params = self._custom_query
172
+ if default_query is not None:
173
+ params = {**params, **default_query}
174
+ elif set_default_query is not None:
175
+ params = set_default_query
176
+
177
+ http_client = http_client or self._client
178
+ return self.__class__(
179
+ api_key=api_key or self.api_key,
180
+ base_url=base_url or self.base_url,
181
+ timeout=self.timeout if isinstance(timeout, NotGiven) else timeout,
182
+ http_client=http_client,
183
+ max_retries=max_retries if is_given(max_retries) else self.max_retries,
184
+ default_headers=headers,
185
+ default_query=params,
186
+ **_extra_kwargs,
187
+ )
188
+
189
+ # Alias for `copy` for nicer inline usage, e.g.
190
+ # client.with_options(timeout=10).foo.create(...)
191
+ with_options = copy
192
+
193
+ @override
194
+ def _make_status_error(
195
+ self,
196
+ err_msg: str,
197
+ *,
198
+ body: object,
199
+ response: httpx.Response,
200
+ ) -> APIStatusError:
201
+ if response.status_code == 400:
202
+ return _exceptions.BadRequestError(err_msg, response=response, body=body)
203
+
204
+ if response.status_code == 401:
205
+ return _exceptions.AuthenticationError(err_msg, response=response, body=body)
206
+
207
+ if response.status_code == 403:
208
+ return _exceptions.PermissionDeniedError(err_msg, response=response, body=body)
209
+
210
+ if response.status_code == 404:
211
+ return _exceptions.NotFoundError(err_msg, response=response, body=body)
212
+
213
+ if response.status_code == 409:
214
+ return _exceptions.ConflictError(err_msg, response=response, body=body)
215
+
216
+ if response.status_code == 422:
217
+ return _exceptions.UnprocessableEntityError(err_msg, response=response, body=body)
218
+
219
+ if response.status_code == 429:
220
+ return _exceptions.RateLimitError(err_msg, response=response, body=body)
221
+
222
+ if response.status_code >= 500:
223
+ return _exceptions.InternalServerError(err_msg, response=response, body=body)
224
+ return APIStatusError(err_msg, response=response, body=body)
225
+
226
+
227
+ class AsyncLark(AsyncAPIClient):
228
+ customer_portal: customer_portal.AsyncCustomerPortalResource
229
+ rate_cards: rate_cards.AsyncRateCardsResource
230
+ usage_events: usage_events.AsyncUsageEventsResource
231
+ subscriptions: subscriptions.AsyncSubscriptionsResource
232
+ subjects: subjects.AsyncSubjectsResource
233
+ pricing_metrics: pricing_metrics.AsyncPricingMetricsResource
234
+ customer_access: customer_access.AsyncCustomerAccessResource
235
+ invoices: invoices.AsyncInvoicesResource
236
+ with_raw_response: AsyncLarkWithRawResponse
237
+ with_streaming_response: AsyncLarkWithStreamedResponse
238
+
239
+ # client options
240
+ api_key: str
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 AsyncLark client instance.
266
+
267
+ This automatically infers the `api_key` argument from the `LARK_API_KEY` environment variable if it is not provided.
268
+ """
269
+ if api_key is None:
270
+ api_key = os.environ.get("LARK_API_KEY")
271
+ if api_key is None:
272
+ raise LarkError(
273
+ "The api_key client option must be set either by passing api_key to the client or by setting the LARK_API_KEY environment variable"
274
+ )
275
+ self.api_key = api_key
276
+
277
+ if base_url is None:
278
+ base_url = os.environ.get("LARK_BASE_URL")
279
+ if base_url is None:
280
+ base_url = f"https://api.uselark.ai"
281
+
282
+ super().__init__(
283
+ version=__version__,
284
+ base_url=base_url,
285
+ max_retries=max_retries,
286
+ timeout=timeout,
287
+ http_client=http_client,
288
+ custom_headers=default_headers,
289
+ custom_query=default_query,
290
+ _strict_response_validation=_strict_response_validation,
291
+ )
292
+
293
+ self.customer_portal = customer_portal.AsyncCustomerPortalResource(self)
294
+ self.rate_cards = rate_cards.AsyncRateCardsResource(self)
295
+ self.usage_events = usage_events.AsyncUsageEventsResource(self)
296
+ self.subscriptions = subscriptions.AsyncSubscriptionsResource(self)
297
+ self.subjects = subjects.AsyncSubjectsResource(self)
298
+ self.pricing_metrics = pricing_metrics.AsyncPricingMetricsResource(self)
299
+ self.customer_access = customer_access.AsyncCustomerAccessResource(self)
300
+ self.invoices = invoices.AsyncInvoicesResource(self)
301
+ self.with_raw_response = AsyncLarkWithRawResponse(self)
302
+ self.with_streaming_response = AsyncLarkWithStreamedResponse(self)
303
+
304
+ @property
305
+ @override
306
+ def qs(self) -> Querystring:
307
+ return Querystring(array_format="comma")
308
+
309
+ @property
310
+ @override
311
+ def auth_headers(self) -> dict[str, str]:
312
+ api_key = self.api_key
313
+ return {"X-API-Key": api_key}
314
+
315
+ @property
316
+ @override
317
+ def default_headers(self) -> dict[str, str | Omit]:
318
+ return {
319
+ **super().default_headers,
320
+ "X-Stainless-Async": f"async:{get_async_library()}",
321
+ **self._custom_headers,
322
+ }
323
+
324
+ def copy(
325
+ self,
326
+ *,
327
+ api_key: str | None = None,
328
+ base_url: str | httpx.URL | None = None,
329
+ timeout: float | Timeout | None | NotGiven = not_given,
330
+ http_client: httpx.AsyncClient | None = None,
331
+ max_retries: int | NotGiven = not_given,
332
+ default_headers: Mapping[str, str] | None = None,
333
+ set_default_headers: Mapping[str, str] | None = None,
334
+ default_query: Mapping[str, object] | None = None,
335
+ set_default_query: Mapping[str, object] | None = None,
336
+ _extra_kwargs: Mapping[str, Any] = {},
337
+ ) -> Self:
338
+ """
339
+ Create a new client instance re-using the same options given to the current client with optional overriding.
340
+ """
341
+ if default_headers is not None and set_default_headers is not None:
342
+ raise ValueError("The `default_headers` and `set_default_headers` arguments are mutually exclusive")
343
+
344
+ if default_query is not None and set_default_query is not None:
345
+ raise ValueError("The `default_query` and `set_default_query` arguments are mutually exclusive")
346
+
347
+ headers = self._custom_headers
348
+ if default_headers is not None:
349
+ headers = {**headers, **default_headers}
350
+ elif set_default_headers is not None:
351
+ headers = set_default_headers
352
+
353
+ params = self._custom_query
354
+ if default_query is not None:
355
+ params = {**params, **default_query}
356
+ elif set_default_query is not None:
357
+ params = set_default_query
358
+
359
+ http_client = http_client or self._client
360
+ return self.__class__(
361
+ api_key=api_key or self.api_key,
362
+ base_url=base_url or self.base_url,
363
+ timeout=self.timeout if isinstance(timeout, NotGiven) else timeout,
364
+ http_client=http_client,
365
+ max_retries=max_retries if is_given(max_retries) else self.max_retries,
366
+ default_headers=headers,
367
+ default_query=params,
368
+ **_extra_kwargs,
369
+ )
370
+
371
+ # Alias for `copy` for nicer inline usage, e.g.
372
+ # client.with_options(timeout=10).foo.create(...)
373
+ with_options = copy
374
+
375
+ @override
376
+ def _make_status_error(
377
+ self,
378
+ err_msg: str,
379
+ *,
380
+ body: object,
381
+ response: httpx.Response,
382
+ ) -> APIStatusError:
383
+ if response.status_code == 400:
384
+ return _exceptions.BadRequestError(err_msg, response=response, body=body)
385
+
386
+ if response.status_code == 401:
387
+ return _exceptions.AuthenticationError(err_msg, response=response, body=body)
388
+
389
+ if response.status_code == 403:
390
+ return _exceptions.PermissionDeniedError(err_msg, response=response, body=body)
391
+
392
+ if response.status_code == 404:
393
+ return _exceptions.NotFoundError(err_msg, response=response, body=body)
394
+
395
+ if response.status_code == 409:
396
+ return _exceptions.ConflictError(err_msg, response=response, body=body)
397
+
398
+ if response.status_code == 422:
399
+ return _exceptions.UnprocessableEntityError(err_msg, response=response, body=body)
400
+
401
+ if response.status_code == 429:
402
+ return _exceptions.RateLimitError(err_msg, response=response, body=body)
403
+
404
+ if response.status_code >= 500:
405
+ return _exceptions.InternalServerError(err_msg, response=response, body=body)
406
+ return APIStatusError(err_msg, response=response, body=body)
407
+
408
+
409
+ class LarkWithRawResponse:
410
+ def __init__(self, client: Lark) -> None:
411
+ self.customer_portal = customer_portal.CustomerPortalResourceWithRawResponse(client.customer_portal)
412
+ self.rate_cards = rate_cards.RateCardsResourceWithRawResponse(client.rate_cards)
413
+ self.usage_events = usage_events.UsageEventsResourceWithRawResponse(client.usage_events)
414
+ self.subscriptions = subscriptions.SubscriptionsResourceWithRawResponse(client.subscriptions)
415
+ self.subjects = subjects.SubjectsResourceWithRawResponse(client.subjects)
416
+ self.pricing_metrics = pricing_metrics.PricingMetricsResourceWithRawResponse(client.pricing_metrics)
417
+ self.customer_access = customer_access.CustomerAccessResourceWithRawResponse(client.customer_access)
418
+ self.invoices = invoices.InvoicesResourceWithRawResponse(client.invoices)
419
+
420
+
421
+ class AsyncLarkWithRawResponse:
422
+ def __init__(self, client: AsyncLark) -> None:
423
+ self.customer_portal = customer_portal.AsyncCustomerPortalResourceWithRawResponse(client.customer_portal)
424
+ self.rate_cards = rate_cards.AsyncRateCardsResourceWithRawResponse(client.rate_cards)
425
+ self.usage_events = usage_events.AsyncUsageEventsResourceWithRawResponse(client.usage_events)
426
+ self.subscriptions = subscriptions.AsyncSubscriptionsResourceWithRawResponse(client.subscriptions)
427
+ self.subjects = subjects.AsyncSubjectsResourceWithRawResponse(client.subjects)
428
+ self.pricing_metrics = pricing_metrics.AsyncPricingMetricsResourceWithRawResponse(client.pricing_metrics)
429
+ self.customer_access = customer_access.AsyncCustomerAccessResourceWithRawResponse(client.customer_access)
430
+ self.invoices = invoices.AsyncInvoicesResourceWithRawResponse(client.invoices)
431
+
432
+
433
+ class LarkWithStreamedResponse:
434
+ def __init__(self, client: Lark) -> None:
435
+ self.customer_portal = customer_portal.CustomerPortalResourceWithStreamingResponse(client.customer_portal)
436
+ self.rate_cards = rate_cards.RateCardsResourceWithStreamingResponse(client.rate_cards)
437
+ self.usage_events = usage_events.UsageEventsResourceWithStreamingResponse(client.usage_events)
438
+ self.subscriptions = subscriptions.SubscriptionsResourceWithStreamingResponse(client.subscriptions)
439
+ self.subjects = subjects.SubjectsResourceWithStreamingResponse(client.subjects)
440
+ self.pricing_metrics = pricing_metrics.PricingMetricsResourceWithStreamingResponse(client.pricing_metrics)
441
+ self.customer_access = customer_access.CustomerAccessResourceWithStreamingResponse(client.customer_access)
442
+ self.invoices = invoices.InvoicesResourceWithStreamingResponse(client.invoices)
443
+
444
+
445
+ class AsyncLarkWithStreamedResponse:
446
+ def __init__(self, client: AsyncLark) -> None:
447
+ self.customer_portal = customer_portal.AsyncCustomerPortalResourceWithStreamingResponse(client.customer_portal)
448
+ self.rate_cards = rate_cards.AsyncRateCardsResourceWithStreamingResponse(client.rate_cards)
449
+ self.usage_events = usage_events.AsyncUsageEventsResourceWithStreamingResponse(client.usage_events)
450
+ self.subscriptions = subscriptions.AsyncSubscriptionsResourceWithStreamingResponse(client.subscriptions)
451
+ self.subjects = subjects.AsyncSubjectsResourceWithStreamingResponse(client.subjects)
452
+ self.pricing_metrics = pricing_metrics.AsyncPricingMetricsResourceWithStreamingResponse(client.pricing_metrics)
453
+ self.customer_access = customer_access.AsyncCustomerAccessResourceWithStreamingResponse(client.customer_access)
454
+ self.invoices = invoices.AsyncInvoicesResourceWithStreamingResponse(client.invoices)
455
+
456
+
457
+ Client = Lark
458
+
459
+ AsyncClient = AsyncLark
lark/_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
lark/_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