> ## Documentation Index
> Fetch the complete documentation index at: https://commet.co/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Integrar con Python

> Agrega cobros y pagos a tu aplicación de Python con el SDK de Commet, instalado con pip, uv o poetry.

Instala la Commet Skill para que tu agente integre el SDK actual y valide su trabajo contra el contrato vivo de la API.

```bash theme={null}
npx skills add commet-labs/skills --skill commet
```

**1. Instalar**

> [tab] pip
>
> ```bash theme={null}
> pip install commet-sdk
> ```

> [tab] uv
>
> ```bash theme={null}
> uv add commet-sdk
> ```

> [tab] poetry
>
> ```bash theme={null}
> poetry add commet-sdk
> ```

**2. Configurar**

```bash title=".env" theme={null}
COMMET_API_KEY=ck_sandbox_xxx
```

```python title="commet_client.py" theme={null}
import os

from commet import Commet

commet = Commet(
    api_key=os.environ["COMMET_API_KEY"],
)
```

**3. Crear cliente y suscribir**

`customers.create` es idempotente — si ya existe un cliente con el mismo `id`, devuelve el registro existente.

```python theme={null}
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.checkout_url
```

El cliente es redirigido al checkout para completar el pago.

**4. Verificar acceso**

```python theme={null}
sub = commet.subscriptions.get_active(customer_id="user_123")
status = sub.status if sub else None

access = commet.feature_access.get(code="custom_branding", customer_id="user_123")
allowed = access.allowed
```

**5. Trackear uso**

```python theme={null}
commet.usage.track(
    customer_id="user_123",
    feature_code="api_calls",
    value=1,
)
```

El uso se agrega y se cobra al final del período.

**6. Operaciones multiples**

Llama cada recurso directamente con `customer_id`:

```python theme={null}
commet.usage.track(customer_id="user_123", feature_code="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)
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.