paid-python 0.6.0__py3-none-any.whl → 1.0.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.
- paid/__init__.py +65 -95
- paid/client.py +17 -494
- paid/contacts/client.py +415 -133
- paid/contacts/raw_client.py +1046 -118
- paid/core/client_wrapper.py +9 -10
- paid/customers/client.py +270 -566
- paid/customers/raw_client.py +731 -537
- paid/environment.py +1 -1
- paid/errors/bad_request_error.py +2 -2
- paid/errors/forbidden_error.py +2 -2
- paid/errors/internal_server_error.py +2 -2
- paid/errors/not_found_error.py +2 -2
- paid/invoices/client.py +369 -0
- paid/invoices/raw_client.py +692 -0
- paid/orders/__init__.py +0 -3
- paid/orders/client.py +371 -128
- paid/orders/raw_client.py +829 -121
- paid/products/__init__.py +0 -3
- paid/products/client.py +129 -265
- paid/products/raw_client.py +563 -233
- paid/signals/client.py +130 -0
- paid/signals/raw_client.py +190 -0
- paid/tracing/autoinstrumentation.py +12 -6
- paid/tracing/context_manager.py +2 -6
- paid/tracing/distributed_tracing.py +3 -3
- paid/tracing/signal.py +3 -3
- paid/tracing/wrappers/openai_agents/openaiAgentsHook.py +1 -1
- paid/types/__init__.py +62 -86
- paid/types/attribution.py +8 -0
- paid/types/{agent_attribute.py → bulk_signals_response.py} +4 -5
- paid/types/contact.py +12 -20
- paid/types/{address.py → contact_billing_address.py} +6 -7
- paid/types/{traces_response.py → contact_list_response.py} +5 -9
- paid/types/customer.py +15 -22
- paid/types/customer_attribution.py +8 -0
- paid/types/customer_billing_address.py +26 -0
- paid/types/{usage_summary_order.py → customer_by_external_id.py} +3 -5
- paid/types/{usage_summary_order_line.py → customer_by_id.py} +3 -5
- paid/types/customer_creation_state.py +5 -0
- paid/types/customer_list_response.py +22 -0
- paid/types/empty_response.py +17 -0
- paid/types/{error.py → error_response.py} +4 -7
- paid/types/invoice.py +57 -0
- paid/types/invoice_line.py +42 -0
- paid/types/invoice_line_payment_status.py +7 -0
- paid/types/invoice_lines_response.py +22 -0
- paid/types/invoice_list_response.py +22 -0
- paid/types/invoice_payment_status.py +5 -0
- paid/types/invoice_source.py +5 -0
- paid/types/invoice_status.py +7 -0
- paid/types/invoice_tax_status.py +7 -0
- paid/types/order.py +30 -29
- paid/types/order_creation_state.py +5 -0
- paid/types/order_line.py +6 -24
- paid/types/order_lines_response.py +22 -0
- paid/types/order_list_response.py +22 -0
- paid/types/pagination.py +24 -0
- paid/types/product.py +4 -29
- paid/types/{tier.py → product_by_external_id.py} +5 -4
- paid/types/{cost_amount.py → product_by_id.py} +5 -12
- paid/types/product_list_response.py +22 -0
- paid/types/signal.py +8 -34
- paid/types/{agent.py → update_contact_request.py} +10 -11
- paid/types/update_customer_request.py +38 -0
- paid/types/{product_update.py → update_product_request.py} +2 -12
- {paid_python-0.6.0.dist-info → paid_python-1.0.0a1.dist-info}/METADATA +27 -11
- paid_python-1.0.0a1.dist-info/RECORD +110 -0
- opentelemetry/instrumentation/openai/__init__.py +0 -54
- opentelemetry/instrumentation/openai/shared/__init__.py +0 -399
- opentelemetry/instrumentation/openai/shared/audio_wrappers.py +0 -247
- opentelemetry/instrumentation/openai/shared/chat_wrappers.py +0 -1192
- opentelemetry/instrumentation/openai/shared/completion_wrappers.py +0 -292
- opentelemetry/instrumentation/openai/shared/config.py +0 -15
- opentelemetry/instrumentation/openai/shared/embeddings_wrappers.py +0 -311
- opentelemetry/instrumentation/openai/shared/event_emitter.py +0 -108
- opentelemetry/instrumentation/openai/shared/event_models.py +0 -41
- opentelemetry/instrumentation/openai/shared/image_gen_wrappers.py +0 -68
- opentelemetry/instrumentation/openai/shared/span_utils.py +0 -0
- opentelemetry/instrumentation/openai/utils.py +0 -213
- opentelemetry/instrumentation/openai/v0/__init__.py +0 -176
- opentelemetry/instrumentation/openai/v1/__init__.py +0 -394
- opentelemetry/instrumentation/openai/v1/assistant_wrappers.py +0 -329
- opentelemetry/instrumentation/openai/v1/event_handler_wrapper.py +0 -134
- opentelemetry/instrumentation/openai/v1/responses_wrappers.py +0 -1113
- opentelemetry/instrumentation/openai/version.py +0 -1
- paid/agents/client.py +0 -880
- paid/agents/raw_client.py +0 -785
- paid/orders/lines/client.py +0 -144
- paid/orders/lines/raw_client.py +0 -129
- paid/plans/__init__.py +0 -4
- paid/plans/client.py +0 -332
- paid/plans/raw_client.py +0 -464
- paid/products/types/__init__.py +0 -7
- paid/products/types/product_create_type.py +0 -5
- paid/traces/__init__.py +0 -4
- paid/traces/client.py +0 -218
- paid/traces/raw_client.py +0 -226
- paid/types/agent_price_point.py +0 -27
- paid/types/agent_price_point_tiers.py +0 -23
- paid/types/agent_update.py +0 -29
- paid/types/api_error.py +0 -29
- paid/types/billing_frequency.py +0 -5
- paid/types/charge_type.py +0 -5
- paid/types/cost_trace.py +0 -55
- paid/types/cost_traces_response.py +0 -26
- paid/types/creation_source.py +0 -5
- paid/types/creation_state.py +0 -5
- paid/types/customer_update.py +0 -40
- paid/types/entitlement_usage.py +0 -48
- paid/types/order_line_attribute.py +0 -27
- paid/types/order_line_attribute_create_one.py +0 -5
- paid/types/order_line_attribute_pricing.py +0 -33
- paid/types/order_line_create.py +0 -72
- paid/types/pagination_meta.py +0 -84
- paid/types/plan.py +0 -81
- paid/types/plan_group.py +0 -60
- paid/types/plan_plan_products_item.py +0 -35
- paid/types/plan_plan_products_item_plan_product_attribute_item.py +0 -34
- paid/types/price_point.py +0 -25
- paid/types/pricing.py +0 -31
- paid/types/pricing_model_type.py +0 -7
- paid/types/product_type.py +0 -5
- paid/types/product_update_type.py +0 -5
- paid/types/salutation.py +0 -5
- paid/types/signal_v_2.py +0 -56
- paid/types/tax_exempt_status.py +0 -5
- paid/types/trace.py +0 -69
- paid/types/usage_pagination_meta.py +0 -43
- paid/types/usage_summaries_response.py +0 -26
- paid/types/usage_summary.py +0 -121
- paid/usage/__init__.py +0 -7
- paid/usage/client.py +0 -321
- paid/usage/raw_client.py +0 -387
- paid/usage/types/__init__.py +0 -7
- paid/usage/types/usage_check_usage_response.py +0 -53
- paid_python-0.6.0.dist-info/RECORD +0 -153
- /paid/{agents → invoices}/__init__.py +0 -0
- /paid/{orders/lines → signals}/__init__.py +0 -0
- {paid_python-0.6.0.dist-info → paid_python-1.0.0a1.dist-info}/LICENSE +0 -0
- {paid_python-0.6.0.dist-info → paid_python-1.0.0a1.dist-info}/WHEEL +0 -0
paid/client.py
CHANGED
|
@@ -1,37 +1,16 @@
|
|
|
1
1
|
# This file was auto-generated by Fern from our API Definition.
|
|
2
|
-
|
|
2
|
+
|
|
3
3
|
import typing
|
|
4
|
-
import warnings
|
|
5
4
|
|
|
6
5
|
import httpx
|
|
7
|
-
from dotenv import load_dotenv
|
|
8
|
-
|
|
9
|
-
# Load environment variables from .env file
|
|
10
|
-
load_dotenv()
|
|
11
|
-
from .agents.client import AgentsClient, AsyncAgentsClient
|
|
12
6
|
from .contacts.client import AsyncContactsClient, ContactsClient
|
|
13
7
|
from .core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
|
|
14
8
|
from .customers.client import AsyncCustomersClient, CustomersClient
|
|
15
9
|
from .environment import PaidEnvironment
|
|
10
|
+
from .invoices.client import AsyncInvoicesClient, InvoicesClient
|
|
16
11
|
from .orders.client import AsyncOrdersClient, OrdersClient
|
|
17
|
-
from .plans.client import AsyncPlansClient, PlansClient
|
|
18
12
|
from .products.client import AsyncProductsClient, ProductsClient
|
|
19
|
-
from .
|
|
20
|
-
from .tracing.distributed_tracing import (
|
|
21
|
-
generate_tracing_token,
|
|
22
|
-
set_tracing_token,
|
|
23
|
-
unset_tracing_token,
|
|
24
|
-
)
|
|
25
|
-
from .tracing.signal import signal
|
|
26
|
-
from .tracing.tracing import (
|
|
27
|
-
DEFAULT_COLLECTOR_ENDPOINT,
|
|
28
|
-
initialize_tracing,
|
|
29
|
-
trace_async_,
|
|
30
|
-
trace_sync_,
|
|
31
|
-
)
|
|
32
|
-
from .usage.client import AsyncUsageClient, UsageClient
|
|
33
|
-
|
|
34
|
-
T = typing.TypeVar("T")
|
|
13
|
+
from .signals.client import AsyncSignalsClient, SignalsClient
|
|
35
14
|
|
|
36
15
|
|
|
37
16
|
class Paid:
|
|
@@ -48,11 +27,11 @@ class Paid:
|
|
|
48
27
|
|
|
49
28
|
|
|
50
29
|
|
|
51
|
-
Defaults to PaidEnvironment.
|
|
30
|
+
Defaults to PaidEnvironment.DEFAULT
|
|
52
31
|
|
|
53
32
|
|
|
54
33
|
|
|
55
|
-
token : typing.
|
|
34
|
+
token : typing.Union[str, typing.Callable[[], str]]
|
|
56
35
|
timeout : typing.Optional[float]
|
|
57
36
|
The timeout to be used, in seconds, for requests. By default the timeout is 60 seconds, unless a custom httpx client is used, in which case this default is not enforced.
|
|
58
37
|
|
|
@@ -75,20 +54,12 @@ class Paid:
|
|
|
75
54
|
self,
|
|
76
55
|
*,
|
|
77
56
|
base_url: typing.Optional[str] = None,
|
|
78
|
-
environment: PaidEnvironment = PaidEnvironment.
|
|
79
|
-
token: typing.
|
|
57
|
+
environment: PaidEnvironment = PaidEnvironment.DEFAULT,
|
|
58
|
+
token: typing.Union[str, typing.Callable[[], str]],
|
|
80
59
|
timeout: typing.Optional[float] = None,
|
|
81
60
|
follow_redirects: typing.Optional[bool] = True,
|
|
82
61
|
httpx_client: typing.Optional[httpx.Client] = None,
|
|
83
62
|
):
|
|
84
|
-
# If token is not provided, try to get it from environment variable
|
|
85
|
-
if token is None:
|
|
86
|
-
token = os.environ.get("PAID_API_KEY")
|
|
87
|
-
if token is None:
|
|
88
|
-
raise ValueError(
|
|
89
|
-
"API token must be provided either via the 'token' parameter or the 'PAID_API_KEY' environment variable"
|
|
90
|
-
)
|
|
91
|
-
|
|
92
63
|
_defaulted_timeout = (
|
|
93
64
|
timeout if timeout is not None else 60 if httpx_client is None else httpx_client.timeout.read
|
|
94
65
|
)
|
|
@@ -102,231 +73,12 @@ class Paid:
|
|
|
102
73
|
else httpx.Client(timeout=_defaulted_timeout),
|
|
103
74
|
timeout=_defaulted_timeout,
|
|
104
75
|
)
|
|
105
|
-
self.customers = CustomersClient(client_wrapper=self._client_wrapper)
|
|
106
|
-
self.agents = AgentsClient(client_wrapper=self._client_wrapper)
|
|
107
76
|
self.products = ProductsClient(client_wrapper=self._client_wrapper)
|
|
77
|
+
self.customers = CustomersClient(client_wrapper=self._client_wrapper)
|
|
108
78
|
self.contacts = ContactsClient(client_wrapper=self._client_wrapper)
|
|
109
79
|
self.orders = OrdersClient(client_wrapper=self._client_wrapper)
|
|
110
|
-
self.
|
|
111
|
-
self.
|
|
112
|
-
self.traces = TracesClient(client_wrapper=self._client_wrapper)
|
|
113
|
-
|
|
114
|
-
def initialize_tracing(self, collector_endpoint: str = DEFAULT_COLLECTOR_ENDPOINT) -> None:
|
|
115
|
-
"""
|
|
116
|
-
Deprecated: Use the @paid_tracing decorator or context manager instead.
|
|
117
|
-
|
|
118
|
-
This method is deprecated and will be removed in a future version.
|
|
119
|
-
The @paid_tracing decorator automatically initializes tracing as needed.
|
|
120
|
-
|
|
121
|
-
Instead of:
|
|
122
|
-
client.initialize_tracing()
|
|
123
|
-
client.trace(external_customer_id="...", fn=lambda: ...)
|
|
124
|
-
|
|
125
|
-
Use:
|
|
126
|
-
from paid.tracing import paid_tracing
|
|
127
|
-
|
|
128
|
-
@paid_tracing(external_customer_id="...", external_agent_id="...")
|
|
129
|
-
def my_function():
|
|
130
|
-
...
|
|
131
|
-
|
|
132
|
-
Or as a context manager:
|
|
133
|
-
with paid_tracing(external_customer_id="..."):
|
|
134
|
-
result = agent_workflow()
|
|
135
|
-
"""
|
|
136
|
-
warnings.warn(
|
|
137
|
-
"Paid.initialize_tracing() is deprecated and will be removed in a future version. "
|
|
138
|
-
"Use @paid_tracing decorator/context manager directly, which auto-initializes tracing. "
|
|
139
|
-
"See documentation: https://docs.paid.ai/documentation/getting-started/integrate-signals-and-cost-tracking-to-your-codebase",
|
|
140
|
-
DeprecationWarning,
|
|
141
|
-
stacklevel=2,
|
|
142
|
-
)
|
|
143
|
-
token = self._client_wrapper._get_token()
|
|
144
|
-
initialize_tracing(token, collector_endpoint=collector_endpoint)
|
|
145
|
-
|
|
146
|
-
def generate_tracing_token(self) -> int:
|
|
147
|
-
"""
|
|
148
|
-
Deprecated: Import and use generate_tracing_token() directly from paid.tracing.
|
|
149
|
-
|
|
150
|
-
This method is deprecated and will be removed in a future version.
|
|
151
|
-
Use the standalone function instead.
|
|
152
|
-
|
|
153
|
-
Instead of:
|
|
154
|
-
from paid import Paid
|
|
155
|
-
client = Paid(token="...")
|
|
156
|
-
token = client.generate_tracing_token()
|
|
157
|
-
|
|
158
|
-
Use:
|
|
159
|
-
from paid.tracing import generate_tracing_token
|
|
160
|
-
token = generate_tracing_token()
|
|
161
|
-
"""
|
|
162
|
-
warnings.warn(
|
|
163
|
-
"Paid.generate_tracing_token() is deprecated and will be removed in a future version. "
|
|
164
|
-
"Import and use generate_tracing_token() directly from paid.tracing instead.",
|
|
165
|
-
DeprecationWarning,
|
|
166
|
-
stacklevel=2,
|
|
167
|
-
)
|
|
168
|
-
return generate_tracing_token()
|
|
169
|
-
|
|
170
|
-
def set_tracing_token(self, token: int):
|
|
171
|
-
"""
|
|
172
|
-
Deprecated: Pass tracing_token directly to @paid_tracing() decorator instead.
|
|
173
|
-
|
|
174
|
-
This method is deprecated and will be removed in a future version.
|
|
175
|
-
Use the tracing_token parameter in @paid_tracing() to link traces across processes.
|
|
176
|
-
|
|
177
|
-
Instead of:
|
|
178
|
-
from paid import Paid
|
|
179
|
-
client = Paid(token="...")
|
|
180
|
-
token = load_from_storage("workflow_123")
|
|
181
|
-
client.set_tracing_token(token)
|
|
182
|
-
@paid_tracing(external_customer_id="cust_123", external_agent_id="agent_456")
|
|
183
|
-
def process_workflow():
|
|
184
|
-
...
|
|
185
|
-
client.unset_tracing_token()
|
|
186
|
-
|
|
187
|
-
Use:
|
|
188
|
-
from paid.tracing import paid_tracing
|
|
189
|
-
token = load_from_storage("workflow_123")
|
|
190
|
-
|
|
191
|
-
@paid_tracing(
|
|
192
|
-
external_customer_id="cust_123",
|
|
193
|
-
external_agent_id="agent_456",
|
|
194
|
-
tracing_token=token
|
|
195
|
-
)
|
|
196
|
-
def process_workflow():
|
|
197
|
-
...
|
|
198
|
-
|
|
199
|
-
Parameters
|
|
200
|
-
----------
|
|
201
|
-
token : int
|
|
202
|
-
A tracing token to use for the next traces.
|
|
203
|
-
"""
|
|
204
|
-
warnings.warn(
|
|
205
|
-
"Paid.set_tracing_token() is deprecated and will be removed in a future version. "
|
|
206
|
-
"Pass tracing_token directly to @paid_tracing(tracing_token=...) decorator instead.",
|
|
207
|
-
DeprecationWarning,
|
|
208
|
-
stacklevel=2,
|
|
209
|
-
)
|
|
210
|
-
set_tracing_token(token)
|
|
211
|
-
|
|
212
|
-
def unset_tracing_token(self):
|
|
213
|
-
"""
|
|
214
|
-
Deprecated: No longer needed. Use tracing_token parameter in @paid_tracing() instead.
|
|
215
|
-
|
|
216
|
-
This method is deprecated and will be removed in a future version.
|
|
217
|
-
Since tracing_token is now passed directly to @paid_tracing(), there's no need
|
|
218
|
-
to manually set/unset tokens in the context.
|
|
219
|
-
|
|
220
|
-
Old pattern (no longer recommended):
|
|
221
|
-
from paid import Paid
|
|
222
|
-
client = Paid(token="...")
|
|
223
|
-
client.set_tracing_token(token)
|
|
224
|
-
@paid_tracing(external_customer_id="cust_123", external_agent_id="agent_456")
|
|
225
|
-
def my_function():
|
|
226
|
-
...
|
|
227
|
-
client.unset_tracing_token()
|
|
228
|
-
|
|
229
|
-
New pattern (recommended):
|
|
230
|
-
from paid.tracing import paid_tracing
|
|
231
|
-
@paid_tracing(
|
|
232
|
-
external_customer_id="cust_123",
|
|
233
|
-
external_agent_id="agent_456",
|
|
234
|
-
tracing_token=token
|
|
235
|
-
)
|
|
236
|
-
def my_function():
|
|
237
|
-
...
|
|
238
|
-
"""
|
|
239
|
-
warnings.warn(
|
|
240
|
-
"Paid.unset_tracing_token() is deprecated and will be removed in a future version. "
|
|
241
|
-
"Use tracing_token parameter in @paid_tracing(tracing_token=...) decorator instead.",
|
|
242
|
-
DeprecationWarning,
|
|
243
|
-
stacklevel=2,
|
|
244
|
-
)
|
|
245
|
-
unset_tracing_token()
|
|
246
|
-
|
|
247
|
-
def trace(
|
|
248
|
-
self,
|
|
249
|
-
external_customer_id: str,
|
|
250
|
-
fn: typing.Callable[[], T],
|
|
251
|
-
external_agent_id: typing.Optional[str] = None,
|
|
252
|
-
tracing_token: typing.Optional[int] = None,
|
|
253
|
-
metadata: typing.Optional[typing.Dict[str, typing.Any]] = None,
|
|
254
|
-
args: typing.Optional[typing.Tuple] = None,
|
|
255
|
-
kwargs: typing.Optional[typing.Dict] = None,
|
|
256
|
-
) -> T:
|
|
257
|
-
"""
|
|
258
|
-
Deprecated: Use the @paid_tracing decorator or context manager instead.
|
|
259
|
-
|
|
260
|
-
This method is deprecated and will be removed in a future version.
|
|
261
|
-
The callback-based tracing via Paid.trace() is being replaced with the more
|
|
262
|
-
Pythonic @paid_tracing decorator and context manager.
|
|
263
|
-
|
|
264
|
-
Instead of:
|
|
265
|
-
result = client.trace(
|
|
266
|
-
external_customer_id="cust_123",
|
|
267
|
-
fn=lambda: agent_workflow(),
|
|
268
|
-
external_agent_id="agent_456"
|
|
269
|
-
)
|
|
270
|
-
|
|
271
|
-
Use the decorator:
|
|
272
|
-
from paid.tracing import paid_tracing
|
|
273
|
-
|
|
274
|
-
@paid_tracing(external_customer_id="cust_123", external_agent_id="agent_456")
|
|
275
|
-
def agent_workflow():
|
|
276
|
-
...
|
|
277
|
-
|
|
278
|
-
result = agent_workflow()
|
|
279
|
-
|
|
280
|
-
Or use the context manager:
|
|
281
|
-
with paid_tracing(external_customer_id="cust_123", external_agent_id="agent_456"):
|
|
282
|
-
result = agent_workflow()
|
|
283
|
-
"""
|
|
284
|
-
warnings.warn(
|
|
285
|
-
"Paid.trace() is deprecated and will be removed in a future version. "
|
|
286
|
-
"Use the @paid_tracing decorator or context manager instead. "
|
|
287
|
-
"See documentation: https://docs.paid.ai/documentation/getting-started/integrate-signals-and-cost-tracking-to-your-codebase",
|
|
288
|
-
DeprecationWarning,
|
|
289
|
-
stacklevel=2,
|
|
290
|
-
)
|
|
291
|
-
return trace_sync_(
|
|
292
|
-
external_customer_id=external_customer_id,
|
|
293
|
-
fn=fn,
|
|
294
|
-
external_agent_id=external_agent_id,
|
|
295
|
-
tracing_token=tracing_token,
|
|
296
|
-
metadata=metadata,
|
|
297
|
-
args=args,
|
|
298
|
-
kwargs=kwargs,
|
|
299
|
-
)
|
|
300
|
-
|
|
301
|
-
def signal(
|
|
302
|
-
self,
|
|
303
|
-
event_name: str,
|
|
304
|
-
*,
|
|
305
|
-
data: typing.Optional[typing.Dict[str, typing.Any]] = None,
|
|
306
|
-
enable_cost_tracing: bool = False,
|
|
307
|
-
) -> None:
|
|
308
|
-
"""
|
|
309
|
-
Deprecated: Import and use signal() directly from paid.tracing.
|
|
310
|
-
|
|
311
|
-
This method is deprecated and will be removed in a future version.
|
|
312
|
-
Use the standalone function instead.
|
|
313
|
-
|
|
314
|
-
Instead of:
|
|
315
|
-
from paid import Paid
|
|
316
|
-
client = Paid(token="...")
|
|
317
|
-
client.signal("event_name", data={...})
|
|
318
|
-
|
|
319
|
-
Use:
|
|
320
|
-
from paid.tracing import signal
|
|
321
|
-
signal("event_name", data={...})
|
|
322
|
-
"""
|
|
323
|
-
warnings.warn(
|
|
324
|
-
"Paid.signal() is deprecated and will be removed in a future version. "
|
|
325
|
-
"Import and use signal() directly from paid.tracing instead.",
|
|
326
|
-
DeprecationWarning,
|
|
327
|
-
stacklevel=2,
|
|
328
|
-
)
|
|
329
|
-
signal(event_name=event_name, enable_cost_tracing=enable_cost_tracing, data=data)
|
|
80
|
+
self.invoices = InvoicesClient(client_wrapper=self._client_wrapper)
|
|
81
|
+
self.signals = SignalsClient(client_wrapper=self._client_wrapper)
|
|
330
82
|
|
|
331
83
|
|
|
332
84
|
class AsyncPaid:
|
|
@@ -343,11 +95,11 @@ class AsyncPaid:
|
|
|
343
95
|
|
|
344
96
|
|
|
345
97
|
|
|
346
|
-
Defaults to PaidEnvironment.
|
|
98
|
+
Defaults to PaidEnvironment.DEFAULT
|
|
347
99
|
|
|
348
100
|
|
|
349
101
|
|
|
350
|
-
token : typing.
|
|
102
|
+
token : typing.Union[str, typing.Callable[[], str]]
|
|
351
103
|
timeout : typing.Optional[float]
|
|
352
104
|
The timeout to be used, in seconds, for requests. By default the timeout is 60 seconds, unless a custom httpx client is used, in which case this default is not enforced.
|
|
353
105
|
|
|
@@ -370,20 +122,12 @@ class AsyncPaid:
|
|
|
370
122
|
self,
|
|
371
123
|
*,
|
|
372
124
|
base_url: typing.Optional[str] = None,
|
|
373
|
-
environment: PaidEnvironment = PaidEnvironment.
|
|
374
|
-
token: typing.
|
|
125
|
+
environment: PaidEnvironment = PaidEnvironment.DEFAULT,
|
|
126
|
+
token: typing.Union[str, typing.Callable[[], str]],
|
|
375
127
|
timeout: typing.Optional[float] = None,
|
|
376
128
|
follow_redirects: typing.Optional[bool] = True,
|
|
377
129
|
httpx_client: typing.Optional[httpx.AsyncClient] = None,
|
|
378
130
|
):
|
|
379
|
-
# If token is not provided, try to get it from environment variable
|
|
380
|
-
if token is None:
|
|
381
|
-
token = os.environ.get("PAID_API_KEY")
|
|
382
|
-
if token is None:
|
|
383
|
-
raise ValueError(
|
|
384
|
-
"API token must be provided either via the 'token' parameter or the 'PAID_API_KEY' environment variable"
|
|
385
|
-
)
|
|
386
|
-
|
|
387
131
|
_defaulted_timeout = (
|
|
388
132
|
timeout if timeout is not None else 60 if httpx_client is None else httpx_client.timeout.read
|
|
389
133
|
)
|
|
@@ -397,233 +141,12 @@ class AsyncPaid:
|
|
|
397
141
|
else httpx.AsyncClient(timeout=_defaulted_timeout),
|
|
398
142
|
timeout=_defaulted_timeout,
|
|
399
143
|
)
|
|
400
|
-
self.customers = AsyncCustomersClient(client_wrapper=self._client_wrapper)
|
|
401
|
-
self.agents = AsyncAgentsClient(client_wrapper=self._client_wrapper)
|
|
402
144
|
self.products = AsyncProductsClient(client_wrapper=self._client_wrapper)
|
|
145
|
+
self.customers = AsyncCustomersClient(client_wrapper=self._client_wrapper)
|
|
403
146
|
self.contacts = AsyncContactsClient(client_wrapper=self._client_wrapper)
|
|
404
147
|
self.orders = AsyncOrdersClient(client_wrapper=self._client_wrapper)
|
|
405
|
-
self.
|
|
406
|
-
self.
|
|
407
|
-
self.traces = AsyncTracesClient(client_wrapper=self._client_wrapper)
|
|
408
|
-
|
|
409
|
-
def initialize_tracing(self, collector_endpoint: str = DEFAULT_COLLECTOR_ENDPOINT) -> None:
|
|
410
|
-
"""
|
|
411
|
-
Deprecated: Use the @paid_tracing decorator or context manager instead.
|
|
412
|
-
|
|
413
|
-
This method is deprecated and will be removed in a future version.
|
|
414
|
-
The @paid_tracing decorator automatically initializes tracing as needed.
|
|
415
|
-
|
|
416
|
-
Instead of:
|
|
417
|
-
client.initialize_tracing()
|
|
418
|
-
await client.trace(external_customer_id="...", fn=async_func)
|
|
419
|
-
|
|
420
|
-
Use:
|
|
421
|
-
from paid.tracing import paid_tracing
|
|
422
|
-
|
|
423
|
-
@paid_tracing(external_customer_id="...", external_agent_id="...")
|
|
424
|
-
async def my_async_function():
|
|
425
|
-
...
|
|
426
|
-
|
|
427
|
-
await my_async_function()
|
|
428
|
-
|
|
429
|
-
Or as an async context manager:
|
|
430
|
-
async with paid_tracing(external_customer_id="..."):
|
|
431
|
-
result = await async_operation()
|
|
432
|
-
"""
|
|
433
|
-
warnings.warn(
|
|
434
|
-
"AsyncPaid.initialize_tracing() is deprecated and will be removed in a future version. "
|
|
435
|
-
"Use @paid_tracing decorator/context manager directly, which auto-initializes tracing. "
|
|
436
|
-
"See documentation: https://docs.paid.ai/documentation/getting-started/integrate-signals-and-cost-tracking-to-your-codebase",
|
|
437
|
-
DeprecationWarning,
|
|
438
|
-
stacklevel=2,
|
|
439
|
-
)
|
|
440
|
-
token = self._client_wrapper._get_token()
|
|
441
|
-
initialize_tracing(token, collector_endpoint=collector_endpoint)
|
|
442
|
-
|
|
443
|
-
def generate_tracing_token(self) -> int:
|
|
444
|
-
"""
|
|
445
|
-
Deprecated: Import and use generate_tracing_token() directly from paid.tracing.
|
|
446
|
-
|
|
447
|
-
This method is deprecated and will be removed in a future version.
|
|
448
|
-
Use the standalone function instead.
|
|
449
|
-
|
|
450
|
-
Instead of:
|
|
451
|
-
from paid import AsyncPaid
|
|
452
|
-
client = AsyncPaid(token="...")
|
|
453
|
-
token = client.generate_tracing_token()
|
|
454
|
-
|
|
455
|
-
Use:
|
|
456
|
-
from paid.tracing import generate_tracing_token
|
|
457
|
-
token = generate_tracing_token()
|
|
458
|
-
"""
|
|
459
|
-
warnings.warn(
|
|
460
|
-
"AsyncPaid.generate_tracing_token() is deprecated and will be removed in a future version. "
|
|
461
|
-
"Import and use generate_tracing_token() directly from paid.tracing instead.",
|
|
462
|
-
DeprecationWarning,
|
|
463
|
-
stacklevel=2,
|
|
464
|
-
)
|
|
465
|
-
return generate_tracing_token()
|
|
466
|
-
|
|
467
|
-
def set_tracing_token(self, token: int):
|
|
468
|
-
"""
|
|
469
|
-
Deprecated: Pass tracing_token directly to @paid_tracing() decorator instead.
|
|
470
|
-
|
|
471
|
-
This method is deprecated and will be removed in a future version.
|
|
472
|
-
Use the tracing_token parameter in @paid_tracing() to link traces across processes.
|
|
473
|
-
|
|
474
|
-
Instead of:
|
|
475
|
-
from paid import AsyncPaid
|
|
476
|
-
client = AsyncPaid(token="...")
|
|
477
|
-
token = load_from_storage("workflow_123")
|
|
478
|
-
client.set_tracing_token(token)
|
|
479
|
-
@paid_tracing(external_customer_id="cust_123", external_agent_id="agent_456")
|
|
480
|
-
async def process_workflow():
|
|
481
|
-
...
|
|
482
|
-
client.unset_tracing_token()
|
|
483
|
-
|
|
484
|
-
Use:
|
|
485
|
-
from paid.tracing import paid_tracing
|
|
486
|
-
token = load_from_storage("workflow_123")
|
|
487
|
-
|
|
488
|
-
@paid_tracing(
|
|
489
|
-
external_customer_id="cust_123",
|
|
490
|
-
external_agent_id="agent_456",
|
|
491
|
-
tracing_token=token
|
|
492
|
-
)
|
|
493
|
-
async def process_workflow():
|
|
494
|
-
...
|
|
495
|
-
|
|
496
|
-
Parameters
|
|
497
|
-
----------
|
|
498
|
-
token : int
|
|
499
|
-
A tracing token to use for the next traces.
|
|
500
|
-
"""
|
|
501
|
-
warnings.warn(
|
|
502
|
-
"AsyncPaid.set_tracing_token() is deprecated and will be removed in a future version. "
|
|
503
|
-
"Pass tracing_token directly to @paid_tracing(tracing_token=...) decorator instead.",
|
|
504
|
-
DeprecationWarning,
|
|
505
|
-
stacklevel=2,
|
|
506
|
-
)
|
|
507
|
-
set_tracing_token(token)
|
|
508
|
-
|
|
509
|
-
def unset_tracing_token(self):
|
|
510
|
-
"""
|
|
511
|
-
Deprecated: No longer needed. Use tracing_token parameter in @paid_tracing() instead.
|
|
512
|
-
|
|
513
|
-
This method is deprecated and will be removed in a future version.
|
|
514
|
-
Since tracing_token is now passed directly to @paid_tracing(), there's no need
|
|
515
|
-
to manually set/unset tokens in the context.
|
|
516
|
-
|
|
517
|
-
Old pattern (no longer recommended):
|
|
518
|
-
from paid import AsyncPaid
|
|
519
|
-
client = AsyncPaid(token="...")
|
|
520
|
-
client.set_tracing_token(token)
|
|
521
|
-
@paid_tracing(external_customer_id="cust_123", external_agent_id="agent_456")
|
|
522
|
-
async def my_function():
|
|
523
|
-
...
|
|
524
|
-
client.unset_tracing_token()
|
|
525
|
-
|
|
526
|
-
New pattern (recommended):
|
|
527
|
-
from paid.tracing import paid_tracing
|
|
528
|
-
@paid_tracing(
|
|
529
|
-
external_customer_id="cust_123",
|
|
530
|
-
external_agent_id="agent_456",
|
|
531
|
-
tracing_token=token
|
|
532
|
-
)
|
|
533
|
-
async def my_function():
|
|
534
|
-
...
|
|
535
|
-
"""
|
|
536
|
-
warnings.warn(
|
|
537
|
-
"AsyncPaid.unset_tracing_token() is deprecated and will be removed in a future version. "
|
|
538
|
-
"Use tracing_token parameter in @paid_tracing(tracing_token=...) decorator instead.",
|
|
539
|
-
DeprecationWarning,
|
|
540
|
-
stacklevel=2,
|
|
541
|
-
)
|
|
542
|
-
unset_tracing_token()
|
|
543
|
-
|
|
544
|
-
async def trace(
|
|
545
|
-
self,
|
|
546
|
-
external_customer_id: str,
|
|
547
|
-
fn: typing.Callable[[], typing.Awaitable[T]],
|
|
548
|
-
external_agent_id: typing.Optional[str] = None,
|
|
549
|
-
tracing_token: typing.Optional[int] = None,
|
|
550
|
-
metadata: typing.Optional[typing.Dict[str, typing.Any]] = None,
|
|
551
|
-
args: typing.Optional[typing.Tuple] = None,
|
|
552
|
-
kwargs: typing.Optional[typing.Dict] = None,
|
|
553
|
-
) -> typing.Union[T, typing.Awaitable[T]]:
|
|
554
|
-
"""
|
|
555
|
-
Deprecated: Use the @paid_tracing decorator or context manager instead.
|
|
556
|
-
|
|
557
|
-
This method is deprecated and will be removed in a future version.
|
|
558
|
-
The callback-based tracing via AsyncPaid.trace() is being replaced with the more
|
|
559
|
-
Pythonic @paid_tracing decorator and context manager.
|
|
560
|
-
|
|
561
|
-
Instead of:
|
|
562
|
-
result = await client.trace(
|
|
563
|
-
external_customer_id="cust_123",
|
|
564
|
-
fn=agent_workflow,
|
|
565
|
-
external_agent_id="agent_456"
|
|
566
|
-
)
|
|
567
|
-
|
|
568
|
-
Use the decorator:
|
|
569
|
-
from paid.tracing import paid_tracing
|
|
570
|
-
|
|
571
|
-
@paid_tracing(external_customer_id="cust_123", external_agent_id="agent_456")
|
|
572
|
-
async def agent_workflow():
|
|
573
|
-
...
|
|
574
|
-
|
|
575
|
-
result = await agent_workflow()
|
|
576
|
-
|
|
577
|
-
Or use the async context manager:
|
|
578
|
-
async with paid_tracing(external_customer_id="cust_123", external_agent_id="agent_456"):
|
|
579
|
-
result = await agent_workflow()
|
|
580
|
-
"""
|
|
581
|
-
warnings.warn(
|
|
582
|
-
"AsyncPaid.trace() is deprecated and will be removed in a future version. "
|
|
583
|
-
"Use the @paid_tracing decorator or context manager instead. "
|
|
584
|
-
"See documentation: https://docs.paid.ai/documentation/getting-started/integrate-signals-and-cost-tracking-to-your-codebase",
|
|
585
|
-
DeprecationWarning,
|
|
586
|
-
stacklevel=2,
|
|
587
|
-
)
|
|
588
|
-
return await trace_async_(
|
|
589
|
-
external_customer_id=external_customer_id,
|
|
590
|
-
fn=fn,
|
|
591
|
-
external_agent_id=external_agent_id,
|
|
592
|
-
tracing_token=tracing_token,
|
|
593
|
-
metadata=metadata,
|
|
594
|
-
args=args,
|
|
595
|
-
kwargs=kwargs,
|
|
596
|
-
)
|
|
597
|
-
|
|
598
|
-
def signal(
|
|
599
|
-
self,
|
|
600
|
-
event_name: str,
|
|
601
|
-
*,
|
|
602
|
-
data: typing.Optional[typing.Dict[str, typing.Any]] = None,
|
|
603
|
-
enable_cost_tracing: bool = False,
|
|
604
|
-
) -> None:
|
|
605
|
-
"""
|
|
606
|
-
Deprecated: Import and use signal() directly from paid.tracing.
|
|
607
|
-
|
|
608
|
-
This method is deprecated and will be removed in a future version.
|
|
609
|
-
Use the standalone function instead.
|
|
610
|
-
|
|
611
|
-
Instead of:
|
|
612
|
-
from paid import AsyncPaid
|
|
613
|
-
client = AsyncPaid(token="...")
|
|
614
|
-
client.signal("event_name", data={...})
|
|
615
|
-
|
|
616
|
-
Use:
|
|
617
|
-
from paid.tracing import signal
|
|
618
|
-
signal("event_name", data={...})
|
|
619
|
-
"""
|
|
620
|
-
warnings.warn(
|
|
621
|
-
"AsyncPaid.signal() is deprecated and will be removed in a future version. "
|
|
622
|
-
"Import and use signal() directly from paid.tracing instead.",
|
|
623
|
-
DeprecationWarning,
|
|
624
|
-
stacklevel=2,
|
|
625
|
-
)
|
|
626
|
-
signal(event_name=event_name, enable_cost_tracing=enable_cost_tracing, data=data)
|
|
148
|
+
self.invoices = AsyncInvoicesClient(client_wrapper=self._client_wrapper)
|
|
149
|
+
self.signals = AsyncSignalsClient(client_wrapper=self._client_wrapper)
|
|
627
150
|
|
|
628
151
|
|
|
629
152
|
def _get_base_url(*, base_url: typing.Optional[str] = None, environment: PaidEnvironment) -> str:
|