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.0.tar.gz (38.9 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.0-py3-none-any.whl (8.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: msg91_py-0.1.0.tar.gz
  • Upload date:
  • Size: 38.9 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.0.tar.gz
Algorithm Hash digest
SHA256 6c6900c5865bb2accd43c674c9c16165e86a6f59a3ee681fd64d225abc0a20af
MD5 d2300efd5737e428927d8fb58f2fcb02
BLAKE2b-256 ad508f0f55628c71b72f8085a513f22e701aa84d8de8b12f98d9fd79522ed4ca

See more details on using hashes here.

Provenance

The following attestation bundles were made for msg91_py-0.1.0.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.0-py3-none-any.whl.

File metadata

  • Download URL: msg91_py-0.1.0-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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 55cddf3df31e9cbbcb7ce7c044e0d7d6a8beac633d1282c4d0c20891014fbb3a
MD5 9050977280828fc48db5abdafbddaf9e
BLAKE2b-256 bf4e6371db996a068897c5b29ecc5cc4bb00aab8c6a293af471fdd5968dbd04d

See more details on using hashes here.

Provenance

The following attestation bundles were made for msg91_py-0.1.0-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