Billing and usage tracking for SaaS applications.
pip install commet-sdkfrom commet import Commet
commet = Commet(api_key="ck_xxx")
# Create a customer
customer = commet.customers.create(email="user@example.com")
# Create a subscription
commet.subscriptions.create(customer_id=customer.id, plan_code="pro")
# Track usage
commet.usage.track(
feature_code="api_calls",
customer_id=customer.id,
value=1,
)
# Track AI token usage
commet.usage.track(
feature_code="ai_generation",
customer_id=customer.id,
model="claude-sonnet-4-20250514",
input_tokens=1000,
output_tokens=500,
)SDK v9 exposes independent Offers, top-level Markets, and selectable price_id variants:
market = commet.markets.create(
name="Argentina",
country_codes=["AR"],
)
offer = commet.offers.create(
name="First three months at 25% off",
phases=[{"type": "percentage", "percentage": 2500, "duration_cycles": 3}],
)Promo Codes reference compatible Offers. Omitting price_id during subscription creation keeps normal default-price resolution.
# 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")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
passwith Commet(api_key="ck_xxx") as commet:
commet.usage.track(
feature_code="api_calls",
customer_id="cus_123",
value=1,
)
# connection pool is automatically closedMIT