Prerequisites
Before you begin, make sure you have:
- A SpringEdge account with an API key and your SMS service URL (
<SMS_SERVICE_URL>, shared after sign-up) - Python 3.6 or higher installed
- The
requestslibrary:pip install requests - A DLT-registered sender ID and approved template (for India)
3 Lines of Code
Send your first SMS with a single requests.post() call
Webhook Support
Receive delivery reports with Flask or Django
pip Install
Uses the popular requests library — nothing proprietary
import requests
URL = "<SMS_SERVICE_URL>/api/web/send/"
params = {
"apikey": "YOUR_API_KEY",
"sender": "SEDEMO",
"to": "9900XXXXXX",
"message": "Your OTP is 482910",
"format": "json",
}
# data= sends a form-encoded POST
response = requests.post(
URL, data=params, timeout=10
)
try:
result = response.json()
print("Message ID:", result["MessageIDs"])
except ValueError:
# Errors are plain text,
# e.g. "Invalid Sender ID"
print("Error:", response.text)
# Success response (format=json):
# {"groupID": 61, "MessageIDs": "61-1",
# "status": "AWAITED-DLR"}
SEND SMS
Basic Python Example
This example uses the requests library to send an SMS through the SpringEdge API. Install it with pip install requests if you haven't already.
The API takes a form-encoded POST to <SMS_SERVICE_URL>/api/web/send/ with apikey, sender, to and message (matching a DLT-approved template). With format=json it returns the group ID and message IDs; errors are plain-text messages such as Insufficient Credits. See the SMS API documentation for all parameters.
Quick Start:
- Install requests:
pip install requests - Replace
YOUR_API_KEYand<SMS_SERVICE_URL> - Update the sender ID, phone number and message
- Run:
python send_sms.py
WEBHOOKS
Receive Delivery Reports with Flask
Set up an endpoint to receive delivery reports. Add callbackurl (your endpoint URL) and label (your own reference ID) to the send request, and SpringEdge calls your URL with the parameters label, recipient and status (DELIVRD, UNDLIVRD or FAILED).
Read the values from the request parameters and return HTTP 200 quickly. See delivery report webhooks for details.
from flask import Flask, request
app = Flask(__name__)
@app.route("/webhook/dlr", methods=["GET", "POST"])
def delivery_report():
# Plain request parameters, not JSON
label = request.values.get("label")
recipient = request.values.get("recipient")
status = request.values.get("status")
print(f"{label} to {recipient}: {status}")
# Update your database here
# db.update_sms_status(label, status)
return "OK", 200
if __name__ == "__main__":
app.run(port=5000)
# Send with: params["callbackurl"] =
# "https://example.com/webhook/dlr"
# params["label"] = "order-1001"
What You Can Build
OTP Verification
Add phone number verification to Django or Flask sign-up flows with one-time passwords delivered in under 3 seconds.
Scheduled Campaigns
Build bulk SMS campaign scripts with Python's scheduling libraries. Send promotions to thousands of recipients at the optimal time.
Automated Alerts
Trigger SMS notifications from Python scripts monitoring servers, databases, or business metrics. Get alerted before issues escalate.
Data Pipeline Alerts
Send SMS notifications from ETL pipelines, Airflow DAGs, or Celery tasks when jobs complete, fail, or need attention.
