# Python (REST)

> There is no Python SDK: call the REST API directly with requests. POST a JSON body to /sms/sendSms with a Bearer token, or generate a typed client from the OpenAPI 3.1 spec with openapi-generator.

- Canonical URL: https://www.broadnet.me/developers/python
- Language: en
- Last updated: 2026-10-21
- Publisher: BroadNet (https://www.broadnet.me)

Call the BroadNet REST API from Python with the requests or httpx libraries. There is no BroadNet Python package: the only official SDK is for TypeScript and Node.js, not Python. If you want a typed Python client, generate one from the OpenAPI spec with openapi-generator; otherwise the plain HTTP calls below are all you need.

> **Keep the base URL in configuration** The samples call https://api.broadnet.me. Read the base URL and the access token (BROADNET_TOKEN) from environment variables, not from code. Test credentials, and where to send test traffic, come with your test access: request it at /signup and we reply within one business day.

## Error handling

Errors return an HTTP status code and an ExceptionResponse JSON body (status, error, message, errorCode, requestUri). resp.raise_for_status() turns them into exceptions. Retry only on network errors and 5xx responses, with backoff; once a call has returned a message ID the send was accepted, so don't resubmit it blindly.

## Requirements

Any supported Python 3 version. The synchronous example uses requests and the async example uses httpx; install whichever you use.

## Examples

### terminal

```bash
pip install requests httpx
```

Plain HTTP libraries. No BroadNet package is required.

### send.py

```python
import os, requests

r = requests.post(
    "https://api.broadnet.me/sms/sendSms",
    headers={"Authorization": f"Bearer {os.environ['BROADNET_TOKEN']}"},
    json={
        "senderId": "BroadNet",
        "destinationNumber": "447700900123",
        "message": "Your verification code is 482913",
        "messageType": "TEXT",
    },
)

print(r.status_code, r.text)  # message ID
```

200 OK · the response body is the message ID.

### async.py

```python
import asyncio
import os

import httpx

URL = "https://api.broadnet.me/sms/sendSms"
HEADERS = {"Authorization": f"Bearer {os.environ['BROADNET_TOKEN']}"}

async def send(client: httpx.AsyncClient, number: str, text: str) -> str:
    resp = await client.post(
        URL,
        headers=HEADERS,
        json={
            "senderId": "BroadNet",
            "destinationNumber": number,
            "message": text,
            "messageType": "TEXT",
        },
    )
    resp.raise_for_status()
    return resp.text  # message ID

async def main() -> None:
    recipients = ["447700900123", "447700900124", "447700900125"]
    async with httpx.AsyncClient(timeout=10) as client:
        ids = await asyncio.gather(
            *(send(client, n, "Your code is 482913") for n in recipients)
        )
    print(ids)

if __name__ == "__main__":
    asyncio.run(main())
```

For large lists, use POST /sms/sendbulk with a file upload instead of many single sends.

### terminal

```bash
# Optional: generate a typed Python client from the OpenAPI spec
curl -O https://www.broadnet.me/developers/openapi.yaml
npx @openapitools/openapi-generator-cli generate \
  -i openapi.yaml -g python -o broadnet-python
```

## Related

- [API reference](https://www.broadnet.me/developers/api-reference)
- [Quickstart](https://www.broadnet.me/developers/quickstart)
- [Webhooks](https://www.broadnet.me/developers/webhooks)
