Skip to main content

A Python client library for the MSG91 SMS API

Project description

MSG91 Python Client

CI PyPI Version Python Versions

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 still msg91.

Usage

Initialize the client

from msg91 import Client

# Initialize client with your auth key
client = Client("your_auth_key")

Sending SMS

# Send SMS using a template
response = client.sms.send(
    template_id="your_template_id",
    mobile="9199XXXXXXXX",
    variables={"var1": "value1", "var2": "value2"},
    sender_id="SENDER"
)
print(response)

# Send SMS to multiple recipients
response = client.sms.send(
    template_id="your_template_id",
    mobile=["9199XXXXXXXX", "9198XXXXXXXX"],
    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)

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:

  • Send SMS: flow
  • SMS Logs: report/logs/p/sms
  • SMS Analytics: report/analytics/p/sms
  • Create Template: sms/addTemplate
  • Add Template Version: sms/addTemplateVersion
  • Get Template Versions: sms/getTemplateVersions
  • Mark Template as Default: sms/markActive

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

msg91_py-0.1.7.tar.gz (39.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

msg91_py-0.1.7-py3-none-any.whl (8.4 kB view details)

Uploaded Python 3

File details

Details for the file msg91_py-0.1.7.tar.gz.

File metadata

  • Download URL: msg91_py-0.1.7.tar.gz
  • Upload date:
  • Size: 39.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for msg91_py-0.1.7.tar.gz
Algorithm Hash digest
SHA256 34041d1927b6580096b7f70451b56b2d48442cce0221b664def66bd8876242e3
MD5 85dbb86b6ce72de537a410942e97e9ed
BLAKE2b-256 47ca0b5e703ae9d0526a644e4c9755793f867c2e3e2a94b4cf88ca8aa02178cc

See more details on using hashes here.

Provenance

The following attestation bundles were made for msg91_py-0.1.7.tar.gz:

Publisher: publish.yml on karambir/msg91-py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file msg91_py-0.1.7-py3-none-any.whl.

File metadata

  • Download URL: msg91_py-0.1.7-py3-none-any.whl
  • Upload date:
  • Size: 8.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for msg91_py-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 e220bf5e0b32273e04fdc484e1ee0015ffc107c5f1ac2f98676a8adc08c7e7ac
MD5 0e1fc098267ee8662d64e428bc8ebdc8
BLAKE2b-256 a6b92ce0c7b324a3ee7ff62ef255767124b5906aed52b331ec754115823e2ad4

See more details on using hashes here.

Provenance

The following attestation bundles were made for msg91_py-0.1.7-py3-none-any.whl:

Publisher: publish.yml on karambir/msg91-py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page