Integrate with Python
Install and configure the Commet Python SDK.
Install
pip install commet-sdkuv add commet-sdkpoetry add commet-sdkConfigure
COMMET_API_KEY=ck_sandbox_xxximport os
from commet import Commet
commet = Commet(
api_key=os.environ["COMMET_API_KEY"],
)Create Customer and Subscribe
customers.create is idempotent — if a customer with the same id already exists, it returns the existing record.
response = commet.customers.create(
email="user@example.com",
id="user_123",
)
subscription = commet.subscriptions.create(
customer_id="user_123",
plan_code="pro",
)
checkout_url = subscription.data["checkout_url"]The customer is redirected to checkout to complete payment.
Check Access
sub = commet.subscriptions.get_active(customer_id="user_123")
status = sub.data["status"]
access = commet.feature_access.get(code="custom_branding", customer_id="user_123")
allowed = access.data.allowedTrack Usage
commet.usage.track(
customer_id="user_123",
feature="api_calls",
value=1,
)Usage is aggregated and billed at end of period.
Multiple Operations
Call each resource directly with customer_id:
commet.usage.track(customer_id="user_123", feature="api_calls", value=1)
commet.feature_access.get(code="custom_branding", customer_id="user_123")
commet.seats.add(customer_id="user_123", feature_code="editor", count=3)Related
How is this guide?