MSG91 Python Client
A Python client library for the MSG91 API.
Installation
pip install msg91-py
Note: The package name on PyPI is
msg91-py, but the module name for imports is stillmsg91.
Usage
Initialize the client
from msg91 import Client
# Initialize client with your auth key
client = Client("your_auth_key")
Sending SMS
# Send SMS using the standard API
response = client.sms.send(
mobile="919XXXXXXXXX",
message="Hello, this is a test message from MSG91!",
sender="SENDER",
route="4",
country="91"
)
print(response)
# Send bulk SMS
response = client.sms.send(
mobile=["919XXXXXXXXX", "918XXXXXXXXX"],
message="Hello, this is a bulk message!",
sender="SENDER",
route="4"
)
print(response)
# Send SMS using a template (Flow API)
response = client.sms.send_template(
template_id="your_template_id",
mobile="919XXXXXXXXX",
variables={"var1": "value1", "var2": "value2"},
sender_id="SENDER"
)
print(response)
Managing Templates
# Create a new template
response = client.template.create(
template_name="Welcome",
template_body="Welcome to our service, {{var1}}!",
sender_id="SENDER",
sms_type="NORMAL" # Options: NORMAL, UNICODE
)
print(response)
# Get template versions
template_versions = client.template.get("template_id")
print(template_versions)
# Add a new version to an existing template
response = client.template.add_version(
template_id="template_id",
template_body="Welcome to our service, {{var1}}! New version.",
sender_id="SENDER"
)
print(response)
# Set a template version as default
response = client.template.set_default(
template_id="template_id",
version_id="version_id"
)
print(response)
OTP (One-Time Password)
# Send OTP
response = client.otp.send(
mobile="919XXXXXXXXX"
)
print(response)
session_id = response.get("message")
# Send OTP with custom settings
response = client.otp.send(
mobile="919XXXXXXXXX",
message="Your login code is ##OTP##. Valid for 5 minutes.",
sender="MYAPP",
otp_length=6,
otp_expiry=5
)
print(response)
# Verify OTP
response = client.otp.verify(
mobile="919XXXXXXXXX",
otp="123456"
)
print(response)
if response.get("type") == "success":
print("OTP verified successfully!")
# Resend OTP via SMS
response = client.otp.resend(
mobile="919XXXXXXXXX",
retrytype="text"
)
print(response)
# Resend OTP via Voice
response = client.otp.resend(
mobile="919XXXXXXXXX",
retrytype="voice"
)
print(response)
Logs and Analytics
# Get SMS logs
logs = client.sms.get_logs(
start_date="2023-01-01",
end_date="2023-01-31"
)
print(logs)
# Get analytics
analytics = client.sms.get_analytics()
print(analytics)
# Get analytics for specific date range
analytics = client.sms.get_analytics(
start_date="2023-01-01",
end_date="2023-01-31"
)
print(analytics)
API Endpoints
The client uses the following MSG91 API endpoints:
SMS:
- Send SMS:
http://api.msg91.com/api/v2/sendsms(v2 API) - Send Template SMS:
flow(v5 API) - SMS Logs:
report/logs/p/sms - SMS Analytics:
report/analytics/p/sms
Templates:
- Create Template:
sms/addTemplate - Add Template Version:
sms/addTemplateVersion - Get Template Versions:
sms/getTemplateVersions - Mark Template as Default:
sms/markActive
OTP:
- Send OTP:
http://api.msg91.com/api/sendotp.php - Verify OTP:
http://api.msg91.com/api/verifyRequestOTP.php - Resend OTP:
http://api.msg91.com/api/retryotp.php
Requirements
- Python 3.9+
- httpx
License
This project is licensed under the MIT License - see the LICENSE file for details.
Metadata
Release files for msg91-py 0.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| msg91_py-0.2.1.tar.gz | 51.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| msg91_py-0.2.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 61.9 kB
Release files / msg91_py-0.2.1.tar.gz
| Download URL | msg91_py-0.2.1.tar.gz |
|---|---|
| Size | 51.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3500f03450e18bd74d55174d8ad83f7e7cef5dc993239b328e8f04b6ea7a277d
|
|
BLAKE2b-256 checksum How to use checksums |
61448fcf896da17dbf7470f579386fe8c491f7669de07956e3b8d18925043494
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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 Oct 23, 2025.
Transparency logRelease files / msg91_py-0.2.1-py3-none-any.whl
| Download URL | msg91_py-0.2.1-py3-none-any.whl |
|---|---|
| Size | 10.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d0198f20a136195011e923ac1cb1b053e7572f9b60b635e11638bdaa1548ec17
|
|
BLAKE2b-256 checksum How to use checksums |
48e2abc86cc0bcf18ae32689fb5e42e9a88d42a7de82a5b603fef764117c05a5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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 Oct 23, 2025.
Transparency log