Multi-provider SMS OTP sending with automatic fallback (Fast2SMS, MSG91, Twilio, 2Factor)
Project description
multi-sms
Multi-provider SMS OTP sending with automatic fallback.
Configure a priority-ordered list of SMS providers. The library tries each one in order — on any failure it automatically moves to the next. First success wins.
pip install multi-sms
Supported providers
| Method | Free / Cost | DLT India | Notes |
|---|---|---|---|
| FAST2SMS | Rs50 free credits | ✅ Built-in | Best for India |
| MSG91 | No free tier | ✅ Built-in | Reliable India SMS |
| TWILIO | $15 trial credit | ⚠️ Manual | Global, works everywhere |
| 2FACTOR | No free tier | ✅ Built-in | India only |
DLT = TRAI registration required for Indian SMS delivery.
Quick start
Option 1 — Environment variable
Set SMS_SEND_METHODS to a JSON array:
export SMS_SEND_METHODS='[
{"method":"FAST2SMS", "api_key":"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"},
{"method":"MSG91", "api_key":"xxxxxxxxxx", "sender_id":"MYAPP", "template_id":"1234567890"},
{"method":"TWILIO", "account_sid":"ACxxxxxxxx", "auth_token":"xxxxxxxx", "from_number":"+12345678901"},
{"method":"2FACTOR", "api_key":"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"}
]'
from multi_sms import send_sms_otp
ok = send_sms_otp("+919876543210", "482910")
Option 2 — Pass methods directly
from multi_sms import send_sms_otp
methods = [
{"method": "FAST2SMS", "api_key": "xxx"},
{"method": "TWILIO", "account_sid": "ACxxx", "auth_token": "xxx", "from_number": "+12345678901"},
]
ok = send_sms_otp("+919876543210", "482910", methods=methods)
Test mode (no real sends)
send_sms_otp("+919876543210", "482910", test_mode=True)
API
send_sms_otp(to, otp, *, methods=None, test_mode=False) -> bool
| Parameter | Type | Description |
|---|---|---|
to |
str |
Recipient phone in E.164 format, e.g. "+919876543210" |
otp |
str |
The OTP string to deliver, e.g. "482910" |
methods |
list | None |
Override the env-var provider list for this call |
test_mode |
bool |
If True, log the OTP and return True without sending |
Returns True on first successful send, False only if every provider fails.
load_methods(env_var="SMS_SEND_METHODS") -> list
Re-read and parse the method list from an environment variable.
Provider setup
FAST2SMS (best free option for India)
- Sign up at fast2sms.com
- Dashboard → Dev API → copy your API key
{"method":"FAST2SMS", "api_key":"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}
Phone numbers must be 10-digit Indian numbers. Pass with or without +91 — the library strips the prefix automatically.
MSG91 (reliable India SMS)
- Sign up at msg91.com → get API key
- Create a DLT-approved template containing
{otp}as the variable - Note your 6-character sender ID and the template ID
{"method":"MSG91", "api_key":"xxxxxxxxxx", "sender_id":"MYAPP", "template_id":"1234567890"}
TWILIO (global SMS)
- Sign up at twilio.com → get Account SID and Auth Token
- Buy a phone number to use as
from_number - For India: complete DLT registration separately via Twilio's India SMS guide
{"method":"TWILIO", "account_sid":"ACxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "auth_token":"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "from_number":"+12345678901"}
2FACTOR (India SMS)
- Sign up at 2factor.in → API Keys → copy your key
{"method":"2FACTOR", "api_key":"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"}
Phone numbers must be 10-digit Indian numbers. Pass with or without +91.
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file multi_sms-1.0.0.tar.gz.
File metadata
- Download URL: multi_sms-1.0.0.tar.gz
- Upload date:
- Size: 5.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
379cf3b4ed1f7ccdff806cce7a7078c0e1d551175a36d2c67410565d78c7b54c
|
|
| MD5 |
0679fe65adef5bf625f90e4ba5602fe1
|
|
| BLAKE2b-256 |
bf2812226a152c8224fa1a5bcb9b19457d861834721a5be4f3df1b83d1404ef4
|
File details
Details for the file multi_sms-1.0.0-py3-none-any.whl.
File metadata
- Download URL: multi_sms-1.0.0-py3-none-any.whl
- Upload date:
- Size: 6.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1309600d1bdc19bc2a403f6218386f8421202fef66c8e80d13afd228888c0560
|
|
| MD5 |
e162430c232b6a2af06a607d4a6ebd7e
|
|
| BLAKE2b-256 |
77baba680c9e8b5d3502fdb88d8bbd01233246f2b0251abaab765aad2f76859c
|