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_active(customer_id="user_123")
status = sub.data["status"]
access = commet.feature_access.get(code="custom_branding", customer_id="user_123")
allowed = access.data.allowedTrackear 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.
Operaciones multiples
Llama cada recurso directamente con 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)Relacionado
¿Cómo está esta guía?