Skip to main content

Production-ready Python client for sending SMS via Unitel and Mobicom APIs

Project description

sms-mn

Production-ready Python client for sending SMS in Mongolia.

sms-mn нь Монголын SMS gateway-уудтай (Unitel, Mobicom) холбогдож мессеж илгээхэд зориулсан Python library юм.
Provider pattern ашигласан тул өөр операторуудыг нэмэхэд маш хялбар.


Supported Providers

  • Unitel Premium Number API
  • Mobicom HTTP SMS API

Цаашид дараах операторуудыг нэмэх боломжтой:

  • Skytel
  • Gmobile

Install

pip install sms-mn

Quick Start

Unitel SMS илгээх

from sms_mn import SMSClient, UnitelProvider

client = SMSClient(
    provider=UnitelProvider(
        api_key="YOUR_UNITEL_API_KEY",
    )
)

response = client.send(
    to="88112233",
    message="Hello from sms-mn via Unitel"
)

print(response)
client.close()

Mobicom SMS илгээх

from sms_mn import SMSClient, MobicomProvider

client = SMSClient(
    provider=MobicomProvider(
        servicename="mms",
        username="engineering",
        sender="139562",
    )
)

response = client.send(
    to="99112233",
    message="Hello from sms-mn via Mobicom"
)

print(response)
client.close()

Async Usage

import asyncio
from sms_mn import AsyncSMSClient, UnitelProvider

async def main():
    client = AsyncSMSClient(
        provider=UnitelProvider(api_key="YOUR_API_KEY")
    )

    response = await client.send(
        to="88112233",
        message="async sms"
    )

    print(response)

    await client.aclose()

asyncio.run(main())

Response Object

send() функц дараах SMSResponse object буцаана.

SMSResponse(
    ok=True,
    status_code=200,
    data={"success": True},
    raw_text="...",
    provider="unitel"
)

Fields

Field Description
ok Request амжилттай эсэх
status_code HTTP response code
data JSON response
raw_text Raw response
provider Ашигласан provider

Error Handling

Library дараах exception-уудыг ашигладаг.

from sms_mn import (
    SMSValidationError,
    SMSAPIError,
    SMSNetworkError
)

Example:

try:
    client.send("99112233", "hello")
except SMSValidationError:
    print("Invalid input")
except SMSAPIError:
    print("SMS API error")
except SMSNetworkError:
    print("Network problem")

Project Structure

Project Structure

sms-mn
│
├─ src/
│  └─ sms_mn/
│     ├─ client.py
│     ├─ models.py
│     ├─ exceptions.py
│     ├─ utils.py
│     └─ providers/
│        ├─ base.py
│        ├─ unitel.py
│        └─ mobicom.py
│
├─ tests/
├─ examples/
└─ README.md

Development

Clone repository:

git clone https://github.com/Suldee925/sms-mn
cd sms-mn

Create virtual environment:

python -m venv .venv

Activate environment:

Windows

.venv\Scripts\activate

Linux / Mac

source .venv/bin/activate

Install dependencies:

pip install -e .

Run Tests

pytest

Build Package

python -m build

Publish to PyPI

twine upload dist/*

Future Roadmap

Төлөвлөсөн feature-үүд:

  • Bulk SMS
  • OTP helper
  • Delivery status
  • Webhook receiver
  • Skytel provider
  • Gmobile provider

License

MIT License


Author

Created by Suld-Erdene Erdenebat

GitHub
https://github.com/Suldee925

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

sms_mn-0.2.0.tar.gz (10.2 kB view details)

Uploaded Source

Built Distribution

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

sms_mn-0.2.0-py3-none-any.whl (9.5 kB view details)

Uploaded Python 3

File details

Details for the file sms_mn-0.2.0.tar.gz.

File metadata

  • Download URL: sms_mn-0.2.0.tar.gz
  • Upload date:
  • Size: 10.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for sms_mn-0.2.0.tar.gz
Algorithm Hash digest
SHA256 410c6ac5bc150b2b421498e2431e9f01c24f4b69aaf309f288e501f05a987a9b
MD5 c3dcbc6b3702ef8e27a7e1847acab1eb
BLAKE2b-256 918d74cb846befe20459b2e8a2956921e797a4b40adc0325108674de5cf0e13d

See more details on using hashes here.

File details

Details for the file sms_mn-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: sms_mn-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 9.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for sms_mn-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0408173704d9e450df7ca87344d32f00ea4c0f3a5e36a282bf8ad000407eb51e
MD5 d9eab61dc17350399fbc10eb0c706f53
BLAKE2b-256 129e6fcf12c85d8f85e5db4171e44457cdd3844a63bfd2dd2beb457352c71df4

See more details on using hashes here.

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