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-sdk

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-1.10.0.tar.gz (18.9 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-1.10.0-py3-none-any.whl (25.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: commet_sdk-1.10.0.tar.gz
  • Upload date:
  • Size: 18.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for commet_sdk-1.10.0.tar.gz
Algorithm Hash digest
SHA256 1fb08a39315536f068defe8b16c08c02a7034ad7fb1e3aeb3089b67b4564aa70
MD5 0fc788d44880f007df8db92e65f14eb3
BLAKE2b-256 3de342bce55a043dd5fcd106674688c5286b6bbe166c1d2c09aea8e6fb79bd2b

See more details on using hashes here.

Provenance

The following attestation bundles were made for commet_sdk-1.10.0.tar.gz:

Publisher: release.yml on commet-labs/commet-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

  • Download URL: commet_sdk-1.10.0-py3-none-any.whl
  • Upload date:
  • Size: 25.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for commet_sdk-1.10.0-py3-none-any.whl
Algorithm Hash digest
SHA256 44cebe9b0bd37d0e45375f7934e016314ce1bde499ad48ff05c9ea1efe1b1728
MD5 ffb179405c07e09e1ac05a59f0b7d6ba
BLAKE2b-256 a8db6c996ec73d8f56db5810c6658f5b3cabffa8eb58fae39be4b6e773bbfa57

See more details on using hashes here.

Provenance

The following attestation bundles were made for commet_sdk-1.10.0-py3-none-any.whl:

Publisher: release.yml on commet-labs/commet-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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