Metadata-Version: 2.4
Name: fast-billing-sdk
Version: 1.0.1
Summary: Python client for reporting completed business tasks to Seabase Billing
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Requires-Python: >=3.11
Description-Content-Type: text/markdown
Requires-Dist: aiohttp<4,>=3.10

# Fast Billing SDK

Async Python 3.11+ client for reporting completed business tasks.

Set `BILLING_API_URL` to the service origin or its `/api` base. For example,
`https://example.com`, `https://example.com/`, and `https://example.com/api/`
all send reports to `https://example.com/api/v1/events/report`.

```bash
python -m pip install fast-billing-sdk==1.0.1
```

```python
import os

from fast_billing_sdk import AsyncBillingClient


async def report_completed_task(event):
    async with AsyncBillingClient(
        base_url=os.environ["BILLING_API_URL"],
        product_code=os.environ["BILLING_PRODUCT_CODE"],
        source_system=os.environ["BILLING_SOURCE_SYSTEM"],
        source_env=os.environ["BILLING_SOURCE_ENV"],
    ) as billing:
        return await billing.report(event)
```

A task dictionary contains `task_id`, `completed_at` (Unix seconds), `source`, `team_id`, and `usage`. Web tasks supply `user_id`, and open API tasks supply `app_id`. Each usage entry contains a billing point `code` and a positive `quantity`. Optional `ext` carries business metadata. The client sends one report for the entire task.

For durable retries, create a prepared event with `billing.prepare_event(event)`, persist the result of `to_json()`, then send it via `await billing.report(prepared_event)`. Use `PreparedEvent(saved_json)` to restore that exact payload. A `SUCCESS` result confirms API receipt. `processing_status` reflects asynchronous processing. Reuse the saved payload after an `UNKNOWN` result.
