Skip to main content

curl-sms for Python

CI PyPI Python versions License: MIT

Official Python client for the curl-sms SMS API: send an SMS with one line of Python.

  • Zero dependencies, standard library only
  • Fully typed (py.typed), Python 3.10+
  • Safe automatic retries with idempotency keys
  • Webhook signature verification built in

Install

pip install curl-sms

Quickstart

from curl_sms import CurlSMS

client = CurlSMS("cs_test_example")  # or set CURLSMS_API_KEY

message = client.send("+4915123456789", "Hello from Python")
print(message["id"], message["status"])  # 01JDQ8M3V6R1T5ZK2X9N4C7B0A queued

Test keys (cs_test_…) run all checks, send nothing and cost nothing. Their status changes are simulated (sent, then delivered). Switch to a live key (cs_live_…) when you are ready.

Configuration

client = CurlSMS(
    api_key="cs_test_example",  # default: env CURLSMS_API_KEY, then CURLSMS_KEY
    base_url="https://curl-sms.com",  # default
    timeout=30,  # seconds per attempt
    max_retries=2,  # retries on network errors, 429 and 5xx
    language="en",  # language of error messages: "en" or "de"
)

If no key is passed and none is set in the environment, the constructor raises ValueError. Client is an alias of CurlSMS.

Methods

All methods return plain dictionaries with TypedDict type hints (Message, SendManyResponse, Estimate, ListResponse, Account). Money amounts are strings in euros, exactly as the API returns them (for example "0.09").

send

Send one SMS:

message = client.send("+4915123456789", "Your code is 123456")

Send the same text to up to 100 receivers:

result = client.send(
    receivers=["+4915123456789", "+4917612345678"],
    body="Server backup finished.",
)
print(result["ids"])

Schedule an SMS (at most one year ahead) with a timezone-aware datetime or an RFC 3339 string:

from datetime import datetime, timezone

client.send(
    "+4915123456789",
    "Reminder: maintenance starts in 10 minutes.",
    send_at=datetime(2026, 12, 1, 7, 50, tzinfo=timezone.utc),
)
client.send("+4915123456789", "Good morning", send_at="2026-12-01T08:00:00+01:00")

estimate

Get encoding, number of parts and price without sending. With receiver, the result also says whether the SMS would be allowed right now:

estimate = client.estimate("Grüße aus Brühl 👋", receiver="+4915123456789")
print(estimate["encoding"], estimate["segments"], estimate["price"], estimate["allowed"])

get

message = client.get("01JDQ8M3V6R1T5ZK2X9N4C7B0A")
# scheduled, queued, dispatched, sent, delivered, failed, expired or canceled
print(message["status"])

cancel

Cancel a scheduled or queued SMS (it is refunded). For any other SMS only the text is deleted:

message = client.cancel("01JDQ8M3V6R1T5ZK2X9N4C7B0A")

list

List SMS ordered by last change, optionally filtered by status. Pass next_cursor back as since to poll for changes:

page = client.list(status="delivered", limit=50)
for message in page["data"]:
    print(message["id"], message["status"])

changes = client.list(since=page["next_cursor"])

account

account = client.account()
print(account["plan"], account["included_left"], account["balance"])

health

Does not send the API key, so it works with any key:

print(client.health())  # {'ok': True, 'version': '1.0.0'}

Error handling

Every failure raises CurlSMSError:

from curl_sms import CurlSMS, CurlSMSError

client = CurlSMS("cs_test_example")

try:
    client.send(receivers=["+4915123456789", "12345"], body="Hello")
except CurlSMSError as err:
    print(err.status)  # 422
    print(err.code)  # "invalid_receiver"
    print(err.message)  # "Invalid receiver number."
    print(err.index)  # 1, the failing entry in receivers
    print(err.error_id)  # set for "internal" errors; quote it to support
    print(err.retry_after)  # seconds from Retry-After, if sent

code is one of the API error codes (see the API reference) or one of these client-side codes:

Code Meaning
network_error The API could not be reached.
timeout No response within timeout seconds.
invalid_response The response was not a valid API response.
invalid_signature A webhook signature was missing, wrong or expired (parse_webhook).

Invalid arguments (for example both receiver and receivers) raise ValueError or TypeError before any request is made.

Retries and idempotency

Requests are retried up to max_retries times (default 2) on network errors, timeouts, 429 and 5xx, with exponential backoff (0.5 s, 1 s, 2 s, …). A Retry-After header is honored, capped at 30 seconds. Other 4xx errors are never retried.

send always sends an Idempotency-Key header. If you do not pass one, a random UUID is generated and reused for every retry of that call, so a retry never sends the SMS twice. Pass your own key to make sends idempotent across processes too, for example per order:

client.send("+4915123456789", "Your order has shipped.", idempotency_key="order-4711-shipped")

The same key and request within 24 hours returns the stored response.

Webhooks

curl-sms signs every webhook request with the X-CurlSMS-Signature header. Verify it against the raw request body with your endpoint secret (whsec_…):

import os

from flask import Flask, abort, request

from curl_sms import CurlSMSError, parse_webhook

app = Flask(__name__)
WEBHOOK_SECRET = os.environ["CURLSMS_WEBHOOK_SECRET"]


@app.post("/webhooks/curl-sms")
def curl_sms_webhook():
    try:
        event = parse_webhook(
            WEBHOOK_SECRET,
            request.headers.get("X-CurlSMS-Signature"),
            request.get_data(),  # raw bytes, before JSON parsing
        )
    except CurlSMSError:
        abort(400)

    if event["type"] == "sms.status_changed":
        data = event["data"]
        print(data["id"], data["status"])
    return "", 204

verify_webhook(secret, signature_header, raw_body) returns True or False if you only need the check. Timestamps older than 300 seconds are rejected (tolerance= to change). Delivery is at-least-once: deduplicate on the event id (also sent as X-CurlSMS-Event-Id).

Examples

See examples/ for runnable scripts.

License

MIT

Metadata

Release files for curl-sms 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for curl-sms 1.0.0
File Size Uploaded Provenance Actions
curl_sms-1.0.0.tar.gz 18.7 kB With provenance Details for curl_sms-1.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for curl-sms 1.0.0
File Interpreter ABI Platform Actions
curl_sms-1.0.0-py3-none-any.whl Python 3 none any Details for curl_sms-1.0.0-py3-none-any.whl

Total release size: 33.4 kB

Release files / curl_sms-1.0.0.tar.gz

Download URL curl_sms-1.0.0.tar.gz
Size 18.7 kB
Tags Source
SHA-256 checksum
How to use checksums
1bd5c18c91142f0842af23f7cb2f8ff1385cd3e2d90ff95b87a191259b0e4792
BLAKE2b-256 checksum
How to use checksums
b629bb8fe51bd8c24fa28037ffe4ccc641c228718bb1c9ceaefee7f305ef44dd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 25, 2026.

Transparency log

Release files / curl_sms-1.0.0-py3-none-any.whl

Download URL curl_sms-1.0.0-py3-none-any.whl
Size 14.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e75627fdda7c5c78a871a886d627a7c6e9f3d2cd928234d76e3c9f9c5ad9b807
BLAKE2b-256 checksum
How to use checksums
3283781b29c91a6401e36bb3e89b10f9d50d1aaaa16bf3f5f91872faf0035531
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 25, 2026.

Transparency log

Security for curl-sms 1.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for curl_sms-1.0.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 25, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page