Skip to main content
The Python SDK wraps the Surge HTTP API with a typed client, sync and async variants, automatic pagination, and a webhook verifier. It’s published as surge-sdk on PyPI and supports Python 3.9 and newer. This page covers installing the package, sending your first request with both clients, paginating list endpoints, handling typed errors, and verifying webhook signatures in your handler.

Install and authenticate

Set your API key as an environment variable:
The client reads it automatically:
For async code, use AsyncSurge:

Your first request

Send a message:
With AsyncSurge:

Pagination

The SDK returns auto-paginating iterators for list endpoints. You don’t need to manage cursors manually:
To page manually, use the raw list method:

Retries and timeouts

The SDK retries transient failures (network errors, 5xx responses) with exponential backoff. Default: 3 retries. Configure retries and timeout on the client:
To disable retries for a specific call:

Error handling

Errors raise typed exceptions:
Common exception types:

Webhooks

Verify webhook signatures and parse events:
The Webhook class follows the Standard Webhooks spec and handles replay protection automatically.