lark-billing 0.0.7__py3-none-any.whl → 0.0.9__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 lark-billing might be problematic. Click here for more details.

Files changed (58) hide show
  1. lark/__init__.py +45 -29
  2. lark/checkout/client.py +34 -12
  3. lark/checkout/raw_client.py +22 -6
  4. lark/client.py +19 -0
  5. lark/core/client_wrapper.py +2 -2
  6. lark/core/http_sse/__init__.py +42 -0
  7. lark/core/http_sse/_api.py +112 -0
  8. lark/core/http_sse/_decoders.py +61 -0
  9. lark/core/http_sse/_exceptions.py +7 -0
  10. lark/core/http_sse/_models.py +17 -0
  11. lark/core/pydantic_utilities.py +3 -1
  12. lark/customer_portal/client.py +4 -2
  13. lark/customer_portal/raw_client.py +2 -0
  14. lark/invoices/__init__.py +4 -0
  15. lark/invoices/client.py +136 -0
  16. lark/invoices/raw_client.py +147 -0
  17. lark/pricing_metrics/client.py +69 -0
  18. lark/pricing_metrics/raw_client.py +101 -0
  19. lark/rate_cards/__init__.py +15 -3
  20. lark/rate_cards/client.py +20 -14
  21. lark/rate_cards/raw_client.py +26 -20
  22. lark/rate_cards/types/__init__.py +12 -2
  23. lark/rate_cards/types/create_rate_card_request_usage_based_rates_item.py +30 -0
  24. lark/subjects/client.py +16 -18
  25. lark/subjects/raw_client.py +14 -8
  26. lark/subscriptions/client.py +194 -8
  27. lark/subscriptions/raw_client.py +256 -4
  28. lark/types/__init__.py +31 -32
  29. lark/types/aggregation.py +1 -43
  30. lark/types/amount.py +4 -1
  31. lark/types/create_customer_portal_session_response.py +9 -2
  32. lark/types/{create_simple_usage_based_rate_interface.py → create_fixed_rate_request.py} +11 -6
  33. lark/types/create_simple_usage_based_rate_request.py +39 -0
  34. lark/types/create_subject_response.py +29 -6
  35. lark/types/create_subscription_checkout_session_response.py +14 -3
  36. lark/types/fixed_rate_interface.py +1 -1
  37. lark/types/{custom_pricing_metric_resource.py → invoice_line_item_resource.py} +6 -2
  38. lark/types/invoice_resource.py +56 -0
  39. lark/types/invoice_status.py +5 -0
  40. lark/types/{max_aggregation_pricing_metric_resource.py → list_invoices_response.py} +4 -2
  41. lark/types/{create_fixed_rate_interface.py → list_pricing_metrics_response.py} +4 -5
  42. lark/types/period_resource.py +23 -0
  43. lark/types/{last_aggregation_pricing_metric_resource.py → pricing_metric_resource.py} +7 -2
  44. lark/types/rate_card_resource.py +36 -7
  45. lark/types/rate_card_resource_usage_based_rates_item.py +1 -2
  46. lark/types/simple_usage_based_rate_interface.py +1 -6
  47. lark/types/subject_resource.py +29 -6
  48. lark/types/subscription_resource.py +42 -8
  49. lark/types/subscription_status.py +5 -0
  50. lark/usage_events/__init__.py +6 -3
  51. lark/usage_events/client.py +15 -4
  52. lark/usage_events/raw_client.py +21 -6
  53. lark/usage_events/types/__init__.py +4 -2
  54. lark/{types/status.py → usage_events/types/create_usage_event_request_data_value.py} +1 -1
  55. {lark_billing-0.0.7.dist-info → lark_billing-0.0.9.dist-info}/METADATA +8 -7
  56. lark_billing-0.0.9.dist-info/RECORD +108 -0
  57. lark_billing-0.0.7.dist-info/RECORD +0 -94
  58. {lark_billing-0.0.7.dist-info → lark_billing-0.0.9.dist-info}/WHEEL +0 -0
lark/__init__.py CHANGED
@@ -9,46 +9,47 @@ if typing.TYPE_CHECKING:
9
9
  from .types import (
10
10
  Aggregation,
11
11
  Aggregation_Count,
12
- Aggregation_Custom,
13
- Aggregation_Last,
14
- Aggregation_Max,
15
12
  Aggregation_Sum,
16
13
  Amount,
17
14
  BillingStateResponse,
18
15
  CountAggregationPricingMetricInterface,
19
16
  CountAggregationPricingMetricResource,
20
17
  CreateCustomerPortalSessionResponse,
21
- CreateFixedRateInterface,
18
+ CreateFixedRateRequest,
22
19
  CreatePricingMetricResponse,
23
- CreateSimpleUsageBasedRateInterface,
20
+ CreateSimpleUsageBasedRateRequest,
24
21
  CreateSubjectResponse,
25
22
  CreateSubscriptionCheckoutSessionResponse,
26
23
  CreateUsageEventSummaryResponse,
27
- CustomPricingMetricResource,
28
24
  FixedRateInterface,
29
25
  FlatPrice,
30
26
  GetPricingMetricResponse,
31
27
  HttpValidationError,
32
- LastAggregationPricingMetricResource,
28
+ InvoiceLineItemResource,
29
+ InvoiceResource,
30
+ InvoiceStatus,
31
+ ListInvoicesResponse,
32
+ ListPricingMetricsResponse,
33
33
  ListRateCardsResponse,
34
34
  ListSubjectsResponse,
35
35
  ListSubscriptionsResponse,
36
- MaxAggregationPricingMetricResource,
37
36
  PackagePrice,
38
37
  PackagePriceInputRoundingBehavior,
39
38
  PackagePriceOutputRoundingBehavior,
40
39
  Period,
40
+ PeriodResource,
41
41
  Price,
42
42
  Price_Flat,
43
43
  Price_Package,
44
+ PricingMetricResource,
44
45
  RateCardResource,
45
46
  RateCardResourceBillingInterval,
46
47
  RateCardResourceUsageBasedRatesItem,
47
48
  RateCardResourceUsageBasedRatesItem_Simple,
48
49
  SimpleUsageBasedRateInterface,
49
- Status,
50
50
  SubjectResource,
51
51
  SubscriptionResource,
52
+ SubscriptionStatus,
52
53
  SumAggregationPricingMetricInterface,
53
54
  SumAggregationPricingMetricResource,
54
55
  ValidationError,
@@ -60,6 +61,7 @@ if typing.TYPE_CHECKING:
60
61
  checkout,
61
62
  customer_access,
62
63
  customer_portal,
64
+ invoices,
63
65
  pricing_metrics,
64
66
  rate_cards,
65
67
  subjects,
@@ -69,15 +71,16 @@ if typing.TYPE_CHECKING:
69
71
  from .client import AsyncLark, Lark
70
72
  from .environment import LarkEnvironment
71
73
  from .pricing_metrics import PricingMetricAggregation, PricingMetricAggregation_Count, PricingMetricAggregation_Sum
72
- from .rate_cards import CreateRateCardRequestBillingInterval
73
- from .usage_events import CreateUsageEventSummaryRequestAggregationType
74
+ from .rate_cards import (
75
+ CreateRateCardRequestBillingInterval,
76
+ CreateRateCardRequestUsageBasedRatesItem,
77
+ CreateRateCardRequestUsageBasedRatesItem_Simple,
78
+ )
79
+ from .usage_events import CreateUsageEventRequestDataValue, CreateUsageEventSummaryRequestAggregationType
74
80
  from .version import __version__
75
81
  _dynamic_imports: typing.Dict[str, str] = {
76
82
  "Aggregation": ".types",
77
83
  "Aggregation_Count": ".types",
78
- "Aggregation_Custom": ".types",
79
- "Aggregation_Last": ".types",
80
- "Aggregation_Max": ".types",
81
84
  "Aggregation_Sum": ".types",
82
85
  "Amount": ".types",
83
86
  "AsyncLark": ".client",
@@ -85,44 +88,51 @@ _dynamic_imports: typing.Dict[str, str] = {
85
88
  "CountAggregationPricingMetricInterface": ".types",
86
89
  "CountAggregationPricingMetricResource": ".types",
87
90
  "CreateCustomerPortalSessionResponse": ".types",
88
- "CreateFixedRateInterface": ".types",
91
+ "CreateFixedRateRequest": ".types",
89
92
  "CreatePricingMetricResponse": ".types",
90
93
  "CreateRateCardRequestBillingInterval": ".rate_cards",
91
- "CreateSimpleUsageBasedRateInterface": ".types",
94
+ "CreateRateCardRequestUsageBasedRatesItem": ".rate_cards",
95
+ "CreateRateCardRequestUsageBasedRatesItem_Simple": ".rate_cards",
96
+ "CreateSimpleUsageBasedRateRequest": ".types",
92
97
  "CreateSubjectResponse": ".types",
93
98
  "CreateSubscriptionCheckoutSessionResponse": ".types",
99
+ "CreateUsageEventRequestDataValue": ".usage_events",
94
100
  "CreateUsageEventSummaryRequestAggregationType": ".usage_events",
95
101
  "CreateUsageEventSummaryResponse": ".types",
96
- "CustomPricingMetricResource": ".types",
97
102
  "FixedRateInterface": ".types",
98
103
  "FlatPrice": ".types",
99
104
  "GetPricingMetricResponse": ".types",
100
105
  "HttpValidationError": ".types",
106
+ "InvoiceLineItemResource": ".types",
107
+ "InvoiceResource": ".types",
108
+ "InvoiceStatus": ".types",
101
109
  "Lark": ".client",
102
110
  "LarkEnvironment": ".environment",
103
- "LastAggregationPricingMetricResource": ".types",
111
+ "ListInvoicesResponse": ".types",
112
+ "ListPricingMetricsResponse": ".types",
104
113
  "ListRateCardsResponse": ".types",
105
114
  "ListSubjectsResponse": ".types",
106
115
  "ListSubscriptionsResponse": ".types",
107
- "MaxAggregationPricingMetricResource": ".types",
108
116
  "PackagePrice": ".types",
109
117
  "PackagePriceInputRoundingBehavior": ".types",
110
118
  "PackagePriceOutputRoundingBehavior": ".types",
111
119
  "Period": ".types",
120
+ "PeriodResource": ".types",
112
121
  "Price": ".types",
113
122
  "Price_Flat": ".types",
114
123
  "Price_Package": ".types",
115
124
  "PricingMetricAggregation": ".pricing_metrics",
116
125
  "PricingMetricAggregation_Count": ".pricing_metrics",
117
126
  "PricingMetricAggregation_Sum": ".pricing_metrics",
127
+ "PricingMetricResource": ".types",
118
128
  "RateCardResource": ".types",
119
129
  "RateCardResourceBillingInterval": ".types",
120
130
  "RateCardResourceUsageBasedRatesItem": ".types",
121
131
  "RateCardResourceUsageBasedRatesItem_Simple": ".types",
122
132
  "SimpleUsageBasedRateInterface": ".types",
123
- "Status": ".types",
124
133
  "SubjectResource": ".types",
125
134
  "SubscriptionResource": ".types",
135
+ "SubscriptionStatus": ".types",
126
136
  "SumAggregationPricingMetricInterface": ".types",
127
137
  "SumAggregationPricingMetricResource": ".types",
128
138
  "UnprocessableEntityError": ".errors",
@@ -133,6 +143,7 @@ _dynamic_imports: typing.Dict[str, str] = {
133
143
  "checkout": ".checkout",
134
144
  "customer_access": ".customer_access",
135
145
  "customer_portal": ".customer_portal",
146
+ "invoices": ".invoices",
136
147
  "pricing_metrics": ".pricing_metrics",
137
148
  "rate_cards": ".rate_cards",
138
149
  "subjects": ".subjects",
@@ -165,9 +176,6 @@ def __dir__():
165
176
  __all__ = [
166
177
  "Aggregation",
167
178
  "Aggregation_Count",
168
- "Aggregation_Custom",
169
- "Aggregation_Last",
170
- "Aggregation_Max",
171
179
  "Aggregation_Sum",
172
180
  "Amount",
173
181
  "AsyncLark",
@@ -175,44 +183,51 @@ __all__ = [
175
183
  "CountAggregationPricingMetricInterface",
176
184
  "CountAggregationPricingMetricResource",
177
185
  "CreateCustomerPortalSessionResponse",
178
- "CreateFixedRateInterface",
186
+ "CreateFixedRateRequest",
179
187
  "CreatePricingMetricResponse",
180
188
  "CreateRateCardRequestBillingInterval",
181
- "CreateSimpleUsageBasedRateInterface",
189
+ "CreateRateCardRequestUsageBasedRatesItem",
190
+ "CreateRateCardRequestUsageBasedRatesItem_Simple",
191
+ "CreateSimpleUsageBasedRateRequest",
182
192
  "CreateSubjectResponse",
183
193
  "CreateSubscriptionCheckoutSessionResponse",
194
+ "CreateUsageEventRequestDataValue",
184
195
  "CreateUsageEventSummaryRequestAggregationType",
185
196
  "CreateUsageEventSummaryResponse",
186
- "CustomPricingMetricResource",
187
197
  "FixedRateInterface",
188
198
  "FlatPrice",
189
199
  "GetPricingMetricResponse",
190
200
  "HttpValidationError",
201
+ "InvoiceLineItemResource",
202
+ "InvoiceResource",
203
+ "InvoiceStatus",
191
204
  "Lark",
192
205
  "LarkEnvironment",
193
- "LastAggregationPricingMetricResource",
206
+ "ListInvoicesResponse",
207
+ "ListPricingMetricsResponse",
194
208
  "ListRateCardsResponse",
195
209
  "ListSubjectsResponse",
196
210
  "ListSubscriptionsResponse",
197
- "MaxAggregationPricingMetricResource",
198
211
  "PackagePrice",
199
212
  "PackagePriceInputRoundingBehavior",
200
213
  "PackagePriceOutputRoundingBehavior",
201
214
  "Period",
215
+ "PeriodResource",
202
216
  "Price",
203
217
  "Price_Flat",
204
218
  "Price_Package",
205
219
  "PricingMetricAggregation",
206
220
  "PricingMetricAggregation_Count",
207
221
  "PricingMetricAggregation_Sum",
222
+ "PricingMetricResource",
208
223
  "RateCardResource",
209
224
  "RateCardResourceBillingInterval",
210
225
  "RateCardResourceUsageBasedRatesItem",
211
226
  "RateCardResourceUsageBasedRatesItem_Simple",
212
227
  "SimpleUsageBasedRateInterface",
213
- "Status",
214
228
  "SubjectResource",
215
229
  "SubscriptionResource",
230
+ "SubscriptionStatus",
216
231
  "SumAggregationPricingMetricInterface",
217
232
  "SumAggregationPricingMetricResource",
218
233
  "UnprocessableEntityError",
@@ -223,6 +238,7 @@ __all__ = [
223
238
  "checkout",
224
239
  "customer_access",
225
240
  "customer_portal",
241
+ "invoices",
226
242
  "pricing_metrics",
227
243
  "rate_cards",
228
244
  "subjects",
lark/checkout/client.py CHANGED
@@ -31,17 +31,24 @@ class CheckoutClient:
31
31
  *,
32
32
  subject_id: str,
33
33
  rate_card_id: str,
34
- callback_url: str,
34
+ success_callback_url: str,
35
+ cancel_url: typing.Optional[str] = OMIT,
35
36
  request_options: typing.Optional[RequestOptions] = None,
36
37
  ) -> CreateSubscriptionCheckoutSessionResponse:
37
38
  """
38
39
  Parameters
39
40
  ----------
40
41
  subject_id : str
42
+ The ID of the subject to create the checkout for.
41
43
 
42
44
  rate_card_id : str
45
+ The ID of the rate card to subscribe to.
43
46
 
44
- callback_url : str
47
+ success_callback_url : str
48
+ The URL to redirect to after the checkout is successful.
49
+
50
+ cancel_url : typing.Optional[str]
51
+ The URL to redirect to after the checkout is cancelled.
45
52
 
46
53
  request_options : typing.Optional[RequestOptions]
47
54
  Request-specific configuration.
@@ -59,13 +66,17 @@ class CheckoutClient:
59
66
  api_key="YOUR_API_KEY",
60
67
  )
61
68
  client.checkout.create_subscription_checkout_session(
62
- subject_id="subject_id",
63
- rate_card_id="rate_card_id",
64
- callback_url="callback_url",
69
+ subject_id="subj_VyX6Q96h5avMho8O7QWlKeXE",
70
+ rate_card_id="rc_AJWMxR81jxoRlli6p13uf3JB",
71
+ success_callback_url="https://example.com/callback",
65
72
  )
66
73
  """
67
74
  _response = self._raw_client.create_subscription_checkout_session(
68
- subject_id=subject_id, rate_card_id=rate_card_id, callback_url=callback_url, request_options=request_options
75
+ subject_id=subject_id,
76
+ rate_card_id=rate_card_id,
77
+ success_callback_url=success_callback_url,
78
+ cancel_url=cancel_url,
79
+ request_options=request_options,
69
80
  )
70
81
  return _response.data
71
82
 
@@ -90,17 +101,24 @@ class AsyncCheckoutClient:
90
101
  *,
91
102
  subject_id: str,
92
103
  rate_card_id: str,
93
- callback_url: str,
104
+ success_callback_url: str,
105
+ cancel_url: typing.Optional[str] = OMIT,
94
106
  request_options: typing.Optional[RequestOptions] = None,
95
107
  ) -> CreateSubscriptionCheckoutSessionResponse:
96
108
  """
97
109
  Parameters
98
110
  ----------
99
111
  subject_id : str
112
+ The ID of the subject to create the checkout for.
100
113
 
101
114
  rate_card_id : str
115
+ The ID of the rate card to subscribe to.
116
+
117
+ success_callback_url : str
118
+ The URL to redirect to after the checkout is successful.
102
119
 
103
- callback_url : str
120
+ cancel_url : typing.Optional[str]
121
+ The URL to redirect to after the checkout is cancelled.
104
122
 
105
123
  request_options : typing.Optional[RequestOptions]
106
124
  Request-specific configuration.
@@ -123,15 +141,19 @@ class AsyncCheckoutClient:
123
141
 
124
142
  async def main() -> None:
125
143
  await client.checkout.create_subscription_checkout_session(
126
- subject_id="subject_id",
127
- rate_card_id="rate_card_id",
128
- callback_url="callback_url",
144
+ subject_id="subj_VyX6Q96h5avMho8O7QWlKeXE",
145
+ rate_card_id="rc_AJWMxR81jxoRlli6p13uf3JB",
146
+ success_callback_url="https://example.com/callback",
129
147
  )
130
148
 
131
149
 
132
150
  asyncio.run(main())
133
151
  """
134
152
  _response = await self._raw_client.create_subscription_checkout_session(
135
- subject_id=subject_id, rate_card_id=rate_card_id, callback_url=callback_url, request_options=request_options
153
+ subject_id=subject_id,
154
+ rate_card_id=rate_card_id,
155
+ success_callback_url=success_callback_url,
156
+ cancel_url=cancel_url,
157
+ request_options=request_options,
136
158
  )
137
159
  return _response.data
@@ -25,17 +25,24 @@ class RawCheckoutClient:
25
25
  *,
26
26
  subject_id: str,
27
27
  rate_card_id: str,
28
- callback_url: str,
28
+ success_callback_url: str,
29
+ cancel_url: typing.Optional[str] = OMIT,
29
30
  request_options: typing.Optional[RequestOptions] = None,
30
31
  ) -> HttpResponse[CreateSubscriptionCheckoutSessionResponse]:
31
32
  """
32
33
  Parameters
33
34
  ----------
34
35
  subject_id : str
36
+ The ID of the subject to create the checkout for.
35
37
 
36
38
  rate_card_id : str
39
+ The ID of the rate card to subscribe to.
37
40
 
38
- callback_url : str
41
+ success_callback_url : str
42
+ The URL to redirect to after the checkout is successful.
43
+
44
+ cancel_url : typing.Optional[str]
45
+ The URL to redirect to after the checkout is cancelled.
39
46
 
40
47
  request_options : typing.Optional[RequestOptions]
41
48
  Request-specific configuration.
@@ -51,7 +58,8 @@ class RawCheckoutClient:
51
58
  json={
52
59
  "subject_id": subject_id,
53
60
  "rate_card_id": rate_card_id,
54
- "callback_url": callback_url,
61
+ "success_callback_url": success_callback_url,
62
+ "cancel_url": cancel_url,
55
63
  },
56
64
  headers={
57
65
  "content-type": "application/json",
@@ -95,17 +103,24 @@ class AsyncRawCheckoutClient:
95
103
  *,
96
104
  subject_id: str,
97
105
  rate_card_id: str,
98
- callback_url: str,
106
+ success_callback_url: str,
107
+ cancel_url: typing.Optional[str] = OMIT,
99
108
  request_options: typing.Optional[RequestOptions] = None,
100
109
  ) -> AsyncHttpResponse[CreateSubscriptionCheckoutSessionResponse]:
101
110
  """
102
111
  Parameters
103
112
  ----------
104
113
  subject_id : str
114
+ The ID of the subject to create the checkout for.
105
115
 
106
116
  rate_card_id : str
117
+ The ID of the rate card to subscribe to.
118
+
119
+ success_callback_url : str
120
+ The URL to redirect to after the checkout is successful.
107
121
 
108
- callback_url : str
122
+ cancel_url : typing.Optional[str]
123
+ The URL to redirect to after the checkout is cancelled.
109
124
 
110
125
  request_options : typing.Optional[RequestOptions]
111
126
  Request-specific configuration.
@@ -121,7 +136,8 @@ class AsyncRawCheckoutClient:
121
136
  json={
122
137
  "subject_id": subject_id,
123
138
  "rate_card_id": rate_card_id,
124
- "callback_url": callback_url,
139
+ "success_callback_url": success_callback_url,
140
+ "cancel_url": cancel_url,
125
141
  },
126
142
  headers={
127
143
  "content-type": "application/json",
lark/client.py CHANGED
@@ -12,6 +12,7 @@ if typing.TYPE_CHECKING:
12
12
  from .checkout.client import AsyncCheckoutClient, CheckoutClient
13
13
  from .customer_access.client import AsyncCustomerAccessClient, CustomerAccessClient
14
14
  from .customer_portal.client import AsyncCustomerPortalClient, CustomerPortalClient
15
+ from .invoices.client import AsyncInvoicesClient, InvoicesClient
15
16
  from .pricing_metrics.client import AsyncPricingMetricsClient, PricingMetricsClient
16
17
  from .rate_cards.client import AsyncRateCardsClient, RateCardsClient
17
18
  from .subjects.client import AsyncSubjectsClient, SubjectsClient
@@ -92,6 +93,7 @@ class Lark:
92
93
  self._subjects: typing.Optional[SubjectsClient] = None
93
94
  self._pricing_metrics: typing.Optional[PricingMetricsClient] = None
94
95
  self._customer_access: typing.Optional[CustomerAccessClient] = None
96
+ self._invoices: typing.Optional[InvoicesClient] = None
95
97
 
96
98
  @property
97
99
  def checkout(self):
@@ -157,6 +159,14 @@ class Lark:
157
159
  self._customer_access = CustomerAccessClient(client_wrapper=self._client_wrapper)
158
160
  return self._customer_access
159
161
 
162
+ @property
163
+ def invoices(self):
164
+ if self._invoices is None:
165
+ from .invoices.client import InvoicesClient # noqa: E402
166
+
167
+ self._invoices = InvoicesClient(client_wrapper=self._client_wrapper)
168
+ return self._invoices
169
+
160
170
 
161
171
  class AsyncLark:
162
172
  """
@@ -231,6 +241,7 @@ class AsyncLark:
231
241
  self._subjects: typing.Optional[AsyncSubjectsClient] = None
232
242
  self._pricing_metrics: typing.Optional[AsyncPricingMetricsClient] = None
233
243
  self._customer_access: typing.Optional[AsyncCustomerAccessClient] = None
244
+ self._invoices: typing.Optional[AsyncInvoicesClient] = None
234
245
 
235
246
  @property
236
247
  def checkout(self):
@@ -296,6 +307,14 @@ class AsyncLark:
296
307
  self._customer_access = AsyncCustomerAccessClient(client_wrapper=self._client_wrapper)
297
308
  return self._customer_access
298
309
 
310
+ @property
311
+ def invoices(self):
312
+ if self._invoices is None:
313
+ from .invoices.client import AsyncInvoicesClient # noqa: E402
314
+
315
+ self._invoices = AsyncInvoicesClient(client_wrapper=self._client_wrapper)
316
+ return self._invoices
317
+
299
318
 
300
319
  def _get_base_url(*, base_url: typing.Optional[str] = None, environment: LarkEnvironment) -> str:
301
320
  if base_url is not None:
@@ -22,10 +22,10 @@ class BaseClientWrapper:
22
22
 
23
23
  def get_headers(self) -> typing.Dict[str, str]:
24
24
  headers: typing.Dict[str, str] = {
25
- "User-Agent": "lark-billing/0.0.7",
25
+ "User-Agent": "lark-billing/0.0.9",
26
26
  "X-Fern-Language": "Python",
27
27
  "X-Fern-SDK-Name": "lark-billing",
28
- "X-Fern-SDK-Version": "0.0.7",
28
+ "X-Fern-SDK-Version": "0.0.9",
29
29
  **(self.get_custom_headers() or {}),
30
30
  }
31
31
  headers["X-API-Key"] = self.api_key
@@ -0,0 +1,42 @@
1
+ # This file was auto-generated by Fern from our API Definition.
2
+
3
+ # isort: skip_file
4
+
5
+ import typing
6
+ from importlib import import_module
7
+
8
+ if typing.TYPE_CHECKING:
9
+ from ._api import EventSource, aconnect_sse, connect_sse
10
+ from ._exceptions import SSEError
11
+ from ._models import ServerSentEvent
12
+ _dynamic_imports: typing.Dict[str, str] = {
13
+ "EventSource": "._api",
14
+ "SSEError": "._exceptions",
15
+ "ServerSentEvent": "._models",
16
+ "aconnect_sse": "._api",
17
+ "connect_sse": "._api",
18
+ }
19
+
20
+
21
+ def __getattr__(attr_name: str) -> typing.Any:
22
+ module_name = _dynamic_imports.get(attr_name)
23
+ if module_name is None:
24
+ raise AttributeError(f"No {attr_name} found in _dynamic_imports for module name -> {__name__}")
25
+ try:
26
+ module = import_module(module_name, __package__)
27
+ if module_name == f".{attr_name}":
28
+ return module
29
+ else:
30
+ return getattr(module, attr_name)
31
+ except ImportError as e:
32
+ raise ImportError(f"Failed to import {attr_name} from {module_name}: {e}") from e
33
+ except AttributeError as e:
34
+ raise AttributeError(f"Failed to get {attr_name} from {module_name}: {e}") from e
35
+
36
+
37
+ def __dir__():
38
+ lazy_attrs = list(_dynamic_imports.keys())
39
+ return sorted(lazy_attrs)
40
+
41
+
42
+ __all__ = ["EventSource", "SSEError", "ServerSentEvent", "aconnect_sse", "connect_sse"]
@@ -0,0 +1,112 @@
1
+ # This file was auto-generated by Fern from our API Definition.
2
+
3
+ import re
4
+ from contextlib import asynccontextmanager, contextmanager
5
+ from typing import Any, AsyncGenerator, AsyncIterator, Iterator, cast
6
+
7
+ import httpx
8
+ from ._decoders import SSEDecoder
9
+ from ._exceptions import SSEError
10
+ from ._models import ServerSentEvent
11
+
12
+
13
+ class EventSource:
14
+ def __init__(self, response: httpx.Response) -> None:
15
+ self._response = response
16
+
17
+ def _check_content_type(self) -> None:
18
+ content_type = self._response.headers.get("content-type", "").partition(";")[0]
19
+ if "text/event-stream" not in content_type:
20
+ raise SSEError(
21
+ f"Expected response header Content-Type to contain 'text/event-stream', got {content_type!r}"
22
+ )
23
+
24
+ def _get_charset(self) -> str:
25
+ """Extract charset from Content-Type header, fallback to UTF-8."""
26
+ content_type = self._response.headers.get("content-type", "")
27
+
28
+ # Parse charset parameter using regex
29
+ charset_match = re.search(r"charset=([^;\s]+)", content_type, re.IGNORECASE)
30
+ if charset_match:
31
+ charset = charset_match.group(1).strip("\"'")
32
+ # Validate that it's a known encoding
33
+ try:
34
+ # Test if the charset is valid by trying to encode/decode
35
+ "test".encode(charset).decode(charset)
36
+ return charset
37
+ except (LookupError, UnicodeError):
38
+ # If charset is invalid, fall back to UTF-8
39
+ pass
40
+
41
+ # Default to UTF-8 if no charset specified or invalid charset
42
+ return "utf-8"
43
+
44
+ @property
45
+ def response(self) -> httpx.Response:
46
+ return self._response
47
+
48
+ def iter_sse(self) -> Iterator[ServerSentEvent]:
49
+ self._check_content_type()
50
+ decoder = SSEDecoder()
51
+ charset = self._get_charset()
52
+
53
+ buffer = ""
54
+ for chunk in self._response.iter_bytes():
55
+ # Decode chunk using detected charset
56
+ text_chunk = chunk.decode(charset, errors="replace")
57
+ buffer += text_chunk
58
+
59
+ # Process complete lines
60
+ while "\n" in buffer:
61
+ line, buffer = buffer.split("\n", 1)
62
+ line = line.rstrip("\r")
63
+ sse = decoder.decode(line)
64
+ # when we reach a "\n\n" => line = ''
65
+ # => decoder will attempt to return an SSE Event
66
+ if sse is not None:
67
+ yield sse
68
+
69
+ # Process any remaining data in buffer
70
+ if buffer.strip():
71
+ line = buffer.rstrip("\r")
72
+ sse = decoder.decode(line)
73
+ if sse is not None:
74
+ yield sse
75
+
76
+ async def aiter_sse(self) -> AsyncGenerator[ServerSentEvent, None]:
77
+ self._check_content_type()
78
+ decoder = SSEDecoder()
79
+ lines = cast(AsyncGenerator[str, None], self._response.aiter_lines())
80
+ try:
81
+ async for line in lines:
82
+ line = line.rstrip("\n")
83
+ sse = decoder.decode(line)
84
+ if sse is not None:
85
+ yield sse
86
+ finally:
87
+ await lines.aclose()
88
+
89
+
90
+ @contextmanager
91
+ def connect_sse(client: httpx.Client, method: str, url: str, **kwargs: Any) -> Iterator[EventSource]:
92
+ headers = kwargs.pop("headers", {})
93
+ headers["Accept"] = "text/event-stream"
94
+ headers["Cache-Control"] = "no-store"
95
+
96
+ with client.stream(method, url, headers=headers, **kwargs) as response:
97
+ yield EventSource(response)
98
+
99
+
100
+ @asynccontextmanager
101
+ async def aconnect_sse(
102
+ client: httpx.AsyncClient,
103
+ method: str,
104
+ url: str,
105
+ **kwargs: Any,
106
+ ) -> AsyncIterator[EventSource]:
107
+ headers = kwargs.pop("headers", {})
108
+ headers["Accept"] = "text/event-stream"
109
+ headers["Cache-Control"] = "no-store"
110
+
111
+ async with client.stream(method, url, headers=headers, **kwargs) as response:
112
+ yield EventSource(response)
@@ -0,0 +1,61 @@
1
+ # This file was auto-generated by Fern from our API Definition.
2
+
3
+ from typing import List, Optional
4
+
5
+ from ._models import ServerSentEvent
6
+
7
+
8
+ class SSEDecoder:
9
+ def __init__(self) -> None:
10
+ self._event = ""
11
+ self._data: List[str] = []
12
+ self._last_event_id = ""
13
+ self._retry: Optional[int] = None
14
+
15
+ def decode(self, line: str) -> Optional[ServerSentEvent]:
16
+ # See: https://html.spec.whatwg.org/multipage/server-sent-events.html#event-stream-interpretation # noqa: E501
17
+
18
+ if not line:
19
+ if not self._event and not self._data and not self._last_event_id and self._retry is None:
20
+ return None
21
+
22
+ sse = ServerSentEvent(
23
+ event=self._event,
24
+ data="\n".join(self._data),
25
+ id=self._last_event_id,
26
+ retry=self._retry,
27
+ )
28
+
29
+ # NOTE: as per the SSE spec, do not reset last_event_id.
30
+ self._event = ""
31
+ self._data = []
32
+ self._retry = None
33
+
34
+ return sse
35
+
36
+ if line.startswith(":"):
37
+ return None
38
+
39
+ fieldname, _, value = line.partition(":")
40
+
41
+ if value.startswith(" "):
42
+ value = value[1:]
43
+
44
+ if fieldname == "event":
45
+ self._event = value
46
+ elif fieldname == "data":
47
+ self._data.append(value)
48
+ elif fieldname == "id":
49
+ if "\0" in value:
50
+ pass
51
+ else:
52
+ self._last_event_id = value
53
+ elif fieldname == "retry":
54
+ try:
55
+ self._retry = int(value)
56
+ except (TypeError, ValueError):
57
+ pass
58
+ else:
59
+ pass # Field is ignored.
60
+
61
+ return None