[Blog](https://sparetext.dev/blog)

# Send SMS from Python with your own phone, no Twilio account

One requests call sends a text from the phone in your pocket. Then delivery status, a CSV list where everyone gets their own words, replies, rate limits and scheduling, all tested.

Sparetext

5 min read · Nov 9, 2026 · Updated Nov 11, 2026

Search "send SMS from Python" and most answers start the same way: make a Twilio account and buy a number. Then, before US carriers let that number text anyone, there's a registration form. If your texts go to people who know you, there's a shorter way.

Your phone already has a number and a plan that sends texts. Sparetext turns it into an SMS gateway with an HTTP API: Python talks to our server, and the text goes out from your phone. Every sample below ran on 9 November against a test copy of Sparetext, with a simulated phone on the other end.

## What you need

- A Sparetext account. Free is 1 phone and 300 texts a month.
- An Android phone with the Sparetext app, paired in the dashboard. An iPhone works too, through Sparetext for Mac or a Shortcut ([the iPhone guide](https://sparetext.dev/iphone-sms-gateway)).
- An API key from the API keys page, kept in an environment variable: `export SPARETEXT_API_KEY=spt_live_...`
- Python 3 and requests: `pip install requests`.

## Send your first text

send.py

```python
import os

import requests

API = "https://sparetext.dev/api/v1"
HEADERS = {"x-api-key": os.environ["SPARETEXT_API_KEY"]}

r = requests.post(
    f"{API}/messages",
    headers=HEADERS,
    json={"to": "+12025550123", "text": "Your table for 2 is ready. See you soon!"},
    timeout=15,
)
r.raise_for_status()
print(r.json())
```

Put your own number in `to` (with its country code) and run it. Your phone sends the text a moment later, from your number. The answer looks like this, trimmed:

```json
{
  "batchId": "b_6g8v3a2petqn",
  "messages": [
    {
      "id": "msg_20261109_prairimz",
      "contact": "+12025550123",
      "status": "queued",
      "source": "api"
    }
  ],
  "estimatedCompletionAt": "2026-11-09T00:05:18.702Z"
}
```

`queued` means it's waiting for your phone. From there it goes to `dispatched` (the phone has it), `sent`, and `delivered` if your carrier sends delivery reports. If something goes wrong it ends at `failed`, with the reason in `error`.

## Check that it arrived

Keep the id and ask about it until it settles:

status.py

```python
import os
import time

import requests

API = "https://sparetext.dev/api/v1"
HEADERS = {"x-api-key": os.environ["SPARETEXT_API_KEY"]}


def send(to, text):
    r = requests.post(f"{API}/messages", headers=HEADERS, json={"to": to, "text": text}, timeout=15)
    r.raise_for_status()
    return r.json()["messages"][0]


def wait_for_delivery(message_id, timeout=120):
    deadline = time.time() + timeout
    while True:
        r = requests.get(f"{API}/messages/{message_id}", headers=HEADERS, timeout=15)
        r.raise_for_status()
        message = r.json()["message"]
        if message["status"] in ("delivered", "failed", "canceled") or time.time() > deadline:
            return message
        time.sleep(3)


text = send("+12025550124", "Your table for 2 is ready. See you soon!")
print(text["id"], text["status"])
text = wait_for_delivery(text["id"])
print(text["status"], text.get("error", ""))
```

Some carriers never send a delivery report, so a text can rest at `sent`. That's why the loop gives up after two minutes and hands back what it has, instead of waiting forever.

A text to someone goes from the phone they last texted with, or your default phone if there's none. With two phones paired, pass `deviceId` to pick one yourself.

## Text a list from a CSV, each person their own words

Say tomorrow's bookings are in a spreadsheet. Save it as `bookings.csv` with a `name`, `phone` and `time` column, and give everyone their own text in one request:

batch.py

```python
import csv
import os

import requests

API = "https://sparetext.dev/api/v1"
HEADERS = {"x-api-key": os.environ["SPARETEXT_API_KEY"]}

with open("bookings.csv", newline="") as f:
    rows = list(csv.DictReader(f))

messages = [
    {"to": row["phone"], "text": f"Hi {row['name']}, see you tomorrow at {row['time']}. Reply YES to confirm."}
    for row in rows
]

for start in range(0, len(messages), 100):
    r = requests.post(f"{API}/messages", headers=HEADERS, json={"messages": messages[start : start + 100]}, timeout=30)
    r.raise_for_status()
    batch = r.json()
    print(batch["batchId"], len(batch["messages"]), "texts queued, last one out about", batch["estimatedCompletionAt"])
```

One request carries up to 100 people, so the loop sends them a hundred at a time. Your phone then works through them at about 30 texts a minute, under Android's own limit, and `estimatedCompletionAt` says when the last one should go.

## Read the replies

Replies land in the same API. This prints everything that came in over the last ten minutes:

replies.py

```python
import os
from datetime import datetime, timedelta, timezone

import requests

API = "https://sparetext.dev/api/v1"
HEADERS = {"x-api-key": os.environ["SPARETEXT_API_KEY"]}

since = (datetime.now(timezone.utc) - timedelta(minutes=10)).isoformat()
r = requests.get(f"{API}/messages", headers=HEADERS, params={"direction": "inbound", "since": since}, timeout=15)
r.raise_for_status()
for text in r.json()["messages"]:
    print(text["contact"], "said:", text["text"])
```

In our test, the three made-up customers from the CSV answered YES, and the script printed all three. Polling is fine for a script you run by hand. For a bot that answers within seconds, have Sparetext call your server instead: [the webhook guide](https://sparetext.dev/receive-sms-webhook) checks the signature in Python with nothing but the standard library.

## Don't fall over on a 429

An account can make 15 send requests every 5 seconds. Past that, the API answers `429 rate_limited` with a `Retry-After` header saying how many seconds to wait. This helper waits that long and tries again:

retry.py

```python
import os
import time

import requests

API = "https://sparetext.dev/api/v1"
HEADERS = {"x-api-key": os.environ["SPARETEXT_API_KEY"]}


def post(path, payload):
    while True:
        r = requests.post(f"{API}{path}", headers=HEADERS, json=payload, timeout=30)
        if r.status_code == 429 and "Retry-After" in r.headers:
            time.sleep(int(r.headers["Retry-After"]))
            continue
        r.raise_for_status()
        return r.json()
```

We sent 20 single texts through it in a row. It was told to wait once, for 2 seconds, and all 20 went through in two and a half. Better still, put many people in one request: it does the work of a hundred single sends.

One 429 has no `Retry-After` on purpose: `key_daily_limit`, when a key has used its texts for the day. The count starts again at midnight in your account's time zone, so the helper raises an error instead of retrying all night. You set that limit per key on the API keys page.

## Send it later

Add `scheduledAt` with a time zone, and the text waits as `scheduled` until then. `DELETE /messages/{id}` cancels it if plans change.

```python
json={
    "to": "+12025550125",
    "text": "Reminder: your appointment is tomorrow at 9.",
    "scheduledAt": "2026-11-10T09:00:00-05:00",
}
```

## Where a phone fits, and where it doesn't

A phone is right for texts to people who know you: reminders, confirmations, alerts to your team, one-time codes, replies to customers. For codes there's a ready-made [verify endpoint](https://sparetext.dev/sms-otp-verification) that makes and checks them for you.

It's the wrong tool for marketing to a list that didn't ask. Carriers filter business texts sent by software, even from a personal number, and [the 10DLC post](https://sparetext.dev/blog/send-sms-without-10dlc) goes through why. On the plan side, Free covers 300 texts a month and Pro 10,000 on up to 5 phones for $12.74 a month, and a long text counts once against your plan however many parts it takes.

Writing JavaScript instead? [The Node.js post](https://sparetext.dev/blog/send-sms-from-node-js) does the same with the `fetch` built into Node, plus safe retries with an Idempotency-Key. There are also versions for [PHP](https://sparetext.dev/blog/send-sms-from-php), [Go](https://sparetext.dev/blog/send-sms-from-go), [Ruby](https://sparetext.dev/blog/send-sms-from-ruby), [Java](https://sparetext.dev/blog/send-sms-from-java), and [shell scripts with curl](https://sparetext.dev/blog/send-sms-from-bash-with-curl).

## Try it with your own number

Make a key on the API keys page, pair your phone, and run `send.py` with your own number in `to`. When your pocket buzzes, point `batch.py` at tomorrow's list.

More scripts to start from are in our public examples repo, [sparetext-examples/python](https://github.com/eliasayele/sparetext-examples/tree/main/python): send a text, send and wait for the reply, a signed webhook receiver and one-time codes, standard library only and MIT licensed.

python send sms sms api requests tutorial

Try it with the phone you have

Free for 1 phone and 300 texts a month. Pair it in about two minutes.

[Start free](https://sparetext.dev/signup)

## Responses

[Sign in](https://sparetext.dev/login?next=%2Fblog%2Fsend-sms-from-python%23responses) or [create an account](https://sparetext.dev/signup?next=%2Fblog%2Fsend-sms-from-python%23responses) to respond.

## More from the blog

- **[Your first text from code in five minutes, timed against Twilio's steps](https://sparetext.dev/blog/first-text-from-code-in-five-minutes)**
   5 min read
- **[Uptime Kuma SMS alerts from your own phone, with one webhook](https://sparetext.dev/blog/uptime-kuma-sms-alerts)**
   6 min read
- **[We handed our dashboard to two AI agents: this week in Sparetext](https://sparetext.dev/blog/we-handed-our-dashboard-to-two-ai-agents)**
   5 min read

---

This is the Markdown copy of https://sparetext.dev/blog/send-sms-from-python for AI agents. Every public page has one: add .md to its address (the home page is https://sparetext.dev/index.md). Sparetext for agents in one file: https://sparetext.dev/llms.txt
