A Python client library for the MSG91 SMS API
Project description
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.
Project details
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 msg91_py-0.2.1.tar.gz.
File metadata
- Download URL: msg91_py-0.2.1.tar.gz
- Upload date:
- Size: 51.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3500f03450e18bd74d55174d8ad83f7e7cef5dc993239b328e8f04b6ea7a277d
|
|
| MD5 |
e45b1f7e20a3f5a7f3d9b501ae8be25c
|
|
| BLAKE2b-256 |
61448fcf896da17dbf7470f579386fe8c491f7669de07956e3b8d18925043494
|
Provenance
The following attestation bundles were made for msg91_py-0.2.1.tar.gz:
Publisher:
publish.yml on karambir/msg91-py
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
msg91_py-0.2.1.tar.gz -
Subject digest:
3500f03450e18bd74d55174d8ad83f7e7cef5dc993239b328e8f04b6ea7a277d - Sigstore transparency entry: 633522891
- Sigstore integration time:
-
Permalink:
karambir/msg91-py@aadbd8235169224c748028c2fd22ee1dce73d1b3 -
Branch / Tag:
refs/tags/v0.2.1 - Owner: https://github.com/karambir
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@aadbd8235169224c748028c2fd22ee1dce73d1b3 -
Trigger Event:
push
-
Statement type:
File details
Details for the file msg91_py-0.2.1-py3-none-any.whl.
File metadata
- Download URL: msg91_py-0.2.1-py3-none-any.whl
- Upload date:
- Size: 10.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d0198f20a136195011e923ac1cb1b053e7572f9b60b635e11638bdaa1548ec17
|
|
| MD5 |
27bfb698d758fbc5cb648923269aa4e7
|
|
| BLAKE2b-256 |
48e2abc86cc0bcf18ae32689fb5e42e9a88d42a7de82a5b603fef764117c05a5
|
Provenance
The following attestation bundles were made for msg91_py-0.2.1-py3-none-any.whl:
Publisher:
publish.yml on karambir/msg91-py
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
msg91_py-0.2.1-py3-none-any.whl -
Subject digest:
d0198f20a136195011e923ac1cb1b053e7572f9b60b635e11638bdaa1548ec17 - Sigstore transparency entry: 633522897
- Sigstore integration time:
-
Permalink:
karambir/msg91-py@aadbd8235169224c748028c2fd22ee1dce73d1b3 -
Branch / Tag:
refs/tags/v0.2.1 - Owner: https://github.com/karambir
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@aadbd8235169224c748028c2fd22ee1dce73d1b3 -
Trigger Event:
push
-
Statement type: