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")

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

# Create a subscription
commet.subscriptions.create(customer_id="cus_123", plan_code="pro")

# Track usage
commet.usage.track(feature="api_calls", customer_id="cus_123")

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

Customer context

Scope all operations to a customer to avoid repeating customer_id:

customer = commet.customer("user_123")

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

Quota

# Add to the quota balance (count defaults to 1)
commet.quota.add(feature_code="storage", customer_id="cus_123")

# Set the quota balance to an exact value
commet.quota.set(feature_code="storage", count=10, customer_id="cus_123")

# Remove from the quota balance (count defaults to 1)
commet.quota.remove(feature_code="storage", customer_id="cus_123")

# Read a single allowance
commet.quota.get(feature_code="storage", customer_id="cus_123")

# Read every allowance for a customer
commet.quota.get_all(customer_id="cus_123")

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", customer_id="cus_123")
# connection pool is automatically closed

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-7.9.0.tar.gz (64.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-7.9.0-py3-none-any.whl (76.7 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for commet_sdk-7.9.0.tar.gz
Algorithm Hash digest
SHA256 d5f0278899c0d08daa9fe39eea3ffbb5c3a3051a6d9230888299143eacd16e50
MD5 8387a74747f559a2350ba4f97b68ed8c
BLAKE2b-256 660c5dd216df3504c593577b859b31f2c66993ed57107143903a0f054951dee6

See more details on using hashes here.

Provenance

The following attestation bundles were made for commet_sdk-7.9.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-7.9.0-py3-none-any.whl.

File metadata

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

File hashes

Hashes for commet_sdk-7.9.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b90faac64b7b4994b6959aa8b281419ede7529add3c8a53352dccaf11870e040
MD5 13f417689a32a71041cf8c0fe7723ded
BLAKE2b-256 b3d34bc8d37cddf342613c2934a67f73165e5e46275ca453383c013c3a7bd476

See more details on using hashes here.

Provenance

The following attestation bundles were made for commet_sdk-7.9.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