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

# Send SMS with Python: Android SMS Gateway

> Send, schedule, list, and delete SMS from Python through your own Android phone and SIM card. The Hypersender SMS API works as an Android SMS gateway.

## Overview

Use the Hypersender Python SDK to send SMS through the Hypersender SMS app on your Android phone, list your messages, and delete them. Set `HYPERSENDER_SMS_API_KEY` and `HYPERSENDER_SMS_INSTANCE_ID` first, as described in [Installation](https://docs.hypersender.com/v2/packages-and-sdks/python/installation.md).

Every method returns the parsed JSON response body as a plain `dict`. If the API answers with an error, the method raises a `HypersenderError` (imported with `from hypersender import HypersenderError`) with the `status_code`, `message`, and `body` of the response.

> [!NOTE]
>
> If the instance is offline, the API answers `403`. If the phone has no push registration, it answers `422` with the code `PHONE_PUSH_NOT_REGISTERED`. See the [SMS heartbeats guide](https://docs.hypersender.com/v2/hypersender/overview/sms/sms-heartbeats-guide.md) and [How it works](https://docs.hypersender.com/v2/hypersender/overview/sms/how-it-works.md).

## Methods

### Send SMS Message

Queue an SMS to be sent by your Android phone. [(learn more)](https://docs.hypersender.com/v2/api-reference/sms/messages/send-message.md)

> [tab] Basic Usage
>
> ```python theme={null}
> from hypersender import Hypersender
>
> hs = Hypersender()
>
> result = hs.sms.send_message(
>     "+201001234567",
>     "Hello, this is a test message!",
>     request_id="order-1042-confirmation",
>     # Optional parameters
>     # schedule_send_at="2025-01-01 12:00:00",
>     # max_send_attempts=3,
>     # message_expiration_seconds=300,
> )
>
> print(result["data"]["id"], result["data"]["status"])
> ```

> [tab] Parameters
>
> | Parameter | Type | Required | Description |
> | - | - | - | - |
> | to | str | yes | The recipient's number, preferably in international format (for example `+201001234567`). Spaces, dashes, dots, and parentheses are removed. |
> | content | str | yes | The text of the SMS. Up to 1600 characters. |
> | request\_id | str | no | Your own ID for this message, up to 255 characters. Sending again with the same `request_id`, number, and text returns the first message with `200` instead of sending a second SMS. If you leave it out, a UUID is generated. |
> | schedule\_send\_at | str | no | Send later, in `Y-m-d H:i:s` format. Must be in the future and less than 3 days away. |
> | max\_send\_attempts | int | no | How many times to try sending if it fails, from 1 to 15. |
> | message\_expiration\_seconds | int | no | Seconds the message stays valid. If the phone has not sent it by then, it is marked expired and never sent. Minimum 60. Useful for OTP codes. |

### List Messages

Get a paginated list of messages, with filters. [(learn more)](https://docs.hypersender.com/v2/api-reference/sms/messages/index-messages.md)

> [tab] Basic Usage
>
> ```python theme={null}
> from hypersender import Hypersender
>
> hs = Hypersender()
>
> result = hs.sms.list_messages()
>
> for message in result["data"]:
>     print(message["id"], message["status"], message["content"])
> ```

> [tab] Basic Usage with Filters
>
> ```python theme={null}
> from hypersender import Hypersender
>
> hs = Hypersender()
>
> result = hs.sms.list_messages(
>     per_page=50,
>     page=2,
>     sort="-updated_at",
>     include="messageThread",
>     filters={
>         "request_id": "order-1042-confirmation",
>         "status": "delivered",
>         # other filters (check Parameters tab)
>     },
> )
>
> meta = result["meta"]
> print(meta["current_page"], meta["last_page"], meta["total"])
> ```

> [tab] Parameters
>
> All parameters are optional and keyword-only. Each key in `filters` is sent as `filter[key]`.
>
> | Parameter | Type | Description |
> | - | - | - |
> | per\_page | int | Items per page (max 50) |
> | page | int | Page number |
> | sort | str | `created_at`, `updated_at`, `delivered_at`, `received_at`, `expired_at`, `failed_at`, or `schedule_send_at`. Add `-` for descending, for example `-updated_at`. |
> | include | str | `messageThread` to add the thread to each message, `phone` to add the phone, or both separated by a comma |
> | filters\["request\_id"] | str | Exact `request_id` you sent |
> | filters\["message\_thread\_id"] | str | Exact thread ID |
> | filters\["from\_phone\_number"] | str | Exact sender number |
> | filters\["to\_phone\_number"] | str | Exact recipient number |
> | filters\["content"] | str | Part of the message text |
> | filters\["status"] | str | `pending`, `scheduled`, `sending`, `sent`, `delivered`, `failed`, `expired`, `received`, or `deleted` |
> | filters\["type"] | str | `sent` (outgoing) or `received` (incoming) |
> | filters\["delivered\_at"] | str | Date or range. A range is two dates separated by a comma, for example `2025-01-01 00:00:00,2025-01-01 23:59:59`. |
> | filters\["received\_at"] | str | Date or range |
> | filters\["expired\_at"] | str | Date or range |
> | filters\["failed\_at"] | str | Date or range |
> | filters\["schedule\_send\_at"] | str | Date or range |
> | filters\["created\_at"] | str | Date or range |
> | filters\["updated\_at"] | str | Date or range |

### Delete Message

Delete a message by its ID. [(learn more)](https://docs.hypersender.com/v2/api-reference/sms/messages/delete-sms-message.md)

> [tab] Basic Usage
>
> ```python theme={null}
> from hypersender import Hypersender
>
> hs = Hypersender()
>
> hs.sms.delete_message("9e03fc6b-ce90-4399-a472-6b029857e15b")
> ```

> [tab] Parameters
>
> | Parameter | Type | Required | Description |
> | - | - | - | - |
> | message\_id | str | yes | The ID of the message to delete |


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