Integrar con Python
Instala y configura el SDK de Commet para Python.
Instalar
pip install commet-sdkuv add commet-sdkpoetry add commet-sdkConfigurar
COMMET_API_KEY=ck_sandbox_xxximport os
from commet import Commet
commet = Commet(
api_key=os.environ["COMMET_API_KEY"],
)Crear cliente y suscribir
customers.create es idempotente — si ya existe un cliente con el mismo id, devuelve el registro existente.
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"]El cliente es redirigido al checkout para completar el pago.
Verificar acceso
sub = commet.subscriptions.get("user_123")
status = sub.data["status"]
access = commet.features.check(code="custom_branding", customer_id="user_123")
allowed = access.data["allowed"]Trackear uso
commet.usage.track(
customer_id="user_123",
feature="api_calls",
value=1,
)El uso se agrega y se cobra al final del período.
Contexto del cliente
Acota todas las operaciones para evitar repetir customer_id:
customer = commet.customer("user_123")
customer.usage.track("api_calls")
customer.features.check("custom_branding")
customer.seats.add("editor", count=3)Relacionado
¿Cómo está esta guía?