Skip to main content

Commet SDK for Python - Billing and usage tracking for SaaS

Project description

Commet Python SDK

Billing and usage tracking for SaaS applications.

Installation

pip install commet

Quick start

from commet import Commet

commet = Commet(api_key="ck_xxx", environment="production")

# 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:

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

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

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

Environments

The SDK defaults to sandbox. Set environment="production" for live operations:

commet = Commet(api_key="ck_xxx", environment="production")

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

commet_sdk-0.1.0.tar.gz (10.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

commet_sdk-0.1.0-py3-none-any.whl (14.0 kB view details)

Uploaded Python 3

File details

Details for the file commet_sdk-0.1.0.tar.gz.

File metadata

  • Download URL: commet_sdk-0.1.0.tar.gz
  • Upload date:
  • Size: 10.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for commet_sdk-0.1.0.tar.gz
Algorithm Hash digest
SHA256 d0075b0bc35e36a57a27f818ca39f25d559cd0186768e0887bbdd0bd665619d3
MD5 eb422010677e96c5736277bd822f0c73
BLAKE2b-256 4cd5ffcc677867c9cb9e2092e00b7acc5152f1083da82af3f8e930fc7541ab0d

See more details on using hashes here.

File details

Details for the file commet_sdk-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: commet_sdk-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 14.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for commet_sdk-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 45a9facd7e9d5f53461a4249e9d7590890399936856cbf2aab07c85723b8be27
MD5 63edd011f3cbe300dfc7fcc8de95008f
BLAKE2b-256 0aee2b74eb30bebb545b08989a4a58f61b50c5ce1c5df201150fb4e4a71b338c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page