# Python SDK

> Install whabuzz from PyPI, send your first message in ten lines, verify webhooks.

Canonical: https://docs.whabuzz.com/sdks/python/

The `whabuzz` package for Python 3.9+. No dependencies (urllib by default; add the `httpx` extra to use httpx). Request bodies and responses are Meta's own.

```bash
pip install whabuzz
export WHABUZZ_API_KEY="wb_live_..."   # your key
```

## First message {#first-message}

```python
import os
from whabuzz import WhaBuzz

wb = WhaBuzz()  # reads WHABUZZ_API_KEY
res = wb.messages.send({
    "from": "+14692311132",  # your connected number
    "to": os.environ["TO"],  # the recipient, E.164
    "type": "text",
    "text": {"body": "Hello from WhaBuzz"},
})
print(res["messages"][0]["id"])
```

Outside the 24-hour customer window send a [template](https://docs.whabuzz.com/guides/templates.md) instead.

## Options and resources {#surface}

`WhaBuzz(api_key, base_url, tenant, timeout, transport)`; `transport="httpx"` needs `pip install whabuzz[httpx]`. Pass `idempotency_key=` on `send`, `batch` and `create` calls; see [Idempotency](https://docs.whabuzz.com/guides/idempotency.md).

`tenant.get`, `messages` (`send`, `batch`, `get_batch`, `list_batch_items`, `cancel_batch`, `mark_read`), `templates` (`list`, `create`, `get`), `numbers` (`list`, `get`), `webhooks.endpoints` (`list`, `create`, `get`, `update`, `delete`, `verify`, `rotate_secret`), `events` (`list`, `get`, `iterate`), `media.get`.

## Errors {#errors}

Failures raise `WhaBuzzError` with `status`, `source` (`meta`, `whabuzz`, `client`), `code`, `meta` (Meta's error object, verbatim) and `request_id`. See [Errors](https://docs.whabuzz.com/errors.md).

## Verify a webhook {#verify}

```python
from whabuzz import verify_webhook

# raw_body must be the exact bytes received, before JSON parsing
event = verify_webhook(raw_body, request.headers, WEBHOOK_SECRET)
print(event["type"])
```

Raises `WebhookVerificationError` with a `reason` when the signature, timestamp (300 s) or header is wrong. Details of the scheme: [Webhooks](https://docs.whabuzz.com/guides/webhooks.md#verify-python).
