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(
        base_url="YOUR_MOBICOM_BASE_URL",
        servicename="YOUR_SERVICE_NAME",
        username="YOUR_USERNAME",
        sender="YOUR_SENDER_NUMBER",
    )
)

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

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.1.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.1-py3-none-any.whl (9.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: sms_mn-0.2.1.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.1.tar.gz
Algorithm Hash digest
SHA256 503e0f0cda508f09079357f12cbb270a8724a72188a73a91311e4163daddd081
MD5 e81e55d47dd820e18b6c2e65d1e45ec1
BLAKE2b-256 e21d204c37dbc615f9f8c2d37b55e87172816cfdbc9161d79c775aa2de4c086f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: sms_mn-0.2.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 926595d3e7939ee9f1819e414635ec591ff22d97574e53f423923eedd3d02937
MD5 8b02c2f891a16ea54201d470353a774e
BLAKE2b-256 98ed840767b640f02e7952a33b013010777e7a6db1dace9226b349469e66354a

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