Metadata-Version: 2.4
Name: commet-sdk
Version: 3.0.0
Summary: Commet SDK for Python - Billing and usage tracking for SaaS
Author: Commet Team
License-Expression: MIT
Project-URL: Homepage, https://commet.co
Project-URL: Repository, https://github.com/commet-labs/commet-python
Keywords: billing,sdk,payments,invoicing,usage-based-billing,seat-licensing
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Typing :: Typed
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: httpx>=0.27
Provides-Extra: dev
Requires-Dist: pytest; extra == "dev"
Requires-Dist: pytest-asyncio; extra == "dev"
Requires-Dist: ruff; extra == "dev"
Requires-Dist: mypy; extra == "dev"
Requires-Dist: respx; extra == "dev"
Dynamic: license-file

# Commet Python SDK

Billing and usage tracking for SaaS applications.

## Installation

```bash
pip install commet-sdk
```

## Quick start

```python
from commet import Commet

commet = Commet(api_key="ck_xxx")

# Create a customer
commet.customers.create(email="user@example.com", external_id="user_123")

# Create a subscription
commet.subscriptions.create(external_id="user_123", plan_code="pro")

# Track usage
commet.usage.track(feature="api_calls", external_id="user_123")

# Track AI token usage
commet.usage.track(
    feature="ai_generation",
    external_id="user_123",
    model="claude-sonnet-4-20250514",
    input_tokens=1000,
    output_tokens=500,
)
```

## Customer context

Scope all operations to a customer to avoid repeating `external_id`:

```python
customer = commet.customer("user_123")

customer.usage.track("api_calls")
customer.features.check("custom_branding")
customer.seats.add("editor", count=3)
customer.portal.get_url()
```

## Webhook verification

```python
from commet import Webhooks

webhooks = Webhooks()

payload = webhooks.verify_and_parse(
    raw_body=request_body,
    signature=request.headers["x-commet-signature"],
    secret="whsec_xxx",
)

if payload is None:
    raise ValueError("Invalid webhook signature")

if payload["event"] == "subscription.activated":
    # handle activation
    pass
```

## Context manager

```python
with Commet(api_key="ck_xxx") as commet:
    commet.usage.track(feature="api_calls", external_id="user_123")
# connection pool is automatically closed
```

## License

MIT
