Skip to main content

Python client for the SMS.ir REST API

Project description

smsir

Python client for the SMS.ir REST API.

Installation

pip install smsir-sdk

Requirements

  • Python >= 3.12
  • httpx
  • pydantic

Usage

Create Client

from smsir import SMSIRClient

client = SMSIRClient("your-api-key")

Async client is also available:

from smsir import AsyncSMSIRClient

async with AsyncSMSIRClient("your-api-key") as client:
    ...

Send Bulk SMS

Send a message to multiple recipients from your dedicated line:

from smsir import SMSIRClient
from smsir.endpoints import BulkSend

client = SMSIRClient("your-api-key")
result = client.execute(BulkSend(
    line_number=30004505000017,
    message_text="Your message here",
    mobiles=["09121234567", "09191234567"],
))
print(result.pack_id, result.message_ids, result.cost)

Send Like-to-Like SMS

Send different messages to different numbers, paired one-to-one:

from smsir.endpoints import LikeToLikeSend

result = client.execute(LikeToLikeSend(
    line_number=30004505000017,
    message_texts=["Message for user 1", "Message for user 2"],
    mobiles=["09121234567", "09191234567"],
))

Send Scheduled SMS

Add send_datetime to any send endpoint for scheduled delivery:

from datetime import datetime, timedelta

result = client.execute(BulkSend(
    line_number=30004505000017,
    message_text="Scheduled message",
    mobiles=["09121234567"],
    send_datetime=datetime.now() + timedelta(hours=2),
))

Cancel Scheduled SMS

from smsir.endpoints import CancelScheduledSend

result = client.execute(CancelScheduledSend(pack_id="2b99e63c-9bf8-4a21-..."))
print(result.returned_credit_count, result.sms_count)

Send Verification Code

Send OTP/verification codes using a predefined template:

from smsir.endpoints import VerifySend

result = client.execute(VerifySend(
    mobile="09191234567",
    template_id=123456,
    parameters={"Code": "12345"},
))
print(result.message_id, result.cost)

Send via URL

Send a single SMS using username/password authentication:

from smsir.endpoints import SendByURL

result = client.execute(SendByURL(
    username="your-username",
    password="your-api-key",
    line=30004505000017,
    mobile="09121234567",
    text="Hello!",
))

Message Report

Get the status of a specific message:

from smsir.endpoints import MessageReport

report = client.execute(MessageReport(message_id=86522023))
print(report.delivery_state, report.cost)

Pack Report

Get all messages in a send pack:

from smsir.endpoints import PackReport

messages = client.execute(PackReport(pack_id="2b99e63c-9bf8-4a21-..."))
for msg in messages:
    print(msg.mobile, msg.delivery_state)

Pack List Report

List all send packs from today:

from smsir.endpoints import PackListReport

packs = client.execute(PackListReport(page_size=50, page_number=1))

Live Send Report

Get today's sent messages:

from smsir.endpoints import LiveSendReport

messages = client.execute(LiveSendReport(page_size=100, page_number=1))

Archived Send Report

Get sent messages from previous days:

from datetime import datetime
from smsir.endpoints import ArchiveSendReport

messages = client.execute(ArchiveSendReport(
    from_date=datetime(2024, 1, 1),
    to_date=datetime(2024, 6, 1),
    page_size=100,
))

Latest Received Messages

Get the most recent unread received messages:

from smsir.endpoints import LatestReceive

messages = client.execute(LatestReceive(count=50))

Live Received Messages

Get today's received messages:

from smsir.endpoints import LiveReceive

messages = client.execute(LiveReceive(
    page_size=20,
    page_number=1,
    sort_by_newest=True,
))

Archived Received Messages

Get received messages from previous days:

from smsir.endpoints import ArchiveReceive

messages = client.execute(ArchiveReceive(
    from_date=datetime(2024, 1, 1),
    to_date=datetime(2024, 6, 1),
))

Get Credit

Get your current account credit:

from smsir.endpoints import GetCredit

credit = client.execute(GetCredit())
print(credit)  # 165.3

Get Line Numbers

Get your available send lines:

from smsir.endpoints import GetLines

lines = client.execute(GetLines())
print(lines)  # [10002155613464, 30004505000017]

Error Handling

from smsir.exceptions import APIError, AuthenticationError, RateLimitError

try:
    client.execute(BulkSend(...))
except AuthenticationError:
    print("Invalid API key")
except RateLimitError:
    print("Too many requests")
except APIError as e:
    print(f"API error: {e.message}")
    print(f"Status code: {e.api_status}")  # StatusCode enum

License

MIT

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

smsir_sdk-1.0.1.tar.gz (8.3 kB view details)

Uploaded Source

Built Distribution

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

smsir_sdk-1.0.1-py3-none-any.whl (15.6 kB view details)

Uploaded Python 3

File details

Details for the file smsir_sdk-1.0.1.tar.gz.

File metadata

  • Download URL: smsir_sdk-1.0.1.tar.gz
  • Upload date:
  • Size: 8.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.12 {"installer":{"name":"uv","version":"0.11.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Arch Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for smsir_sdk-1.0.1.tar.gz
Algorithm Hash digest
SHA256 43dfeb80c460dc8897c67c67e94bffcddf281abf9610993aa058fdab7aff7195
MD5 d633a2581d9c46d43107e23c0f3b561f
BLAKE2b-256 23a38555f02ed4ef7875e50ace7ddefa76b490cd46740778c39340e3230e7b81

See more details on using hashes here.

File details

Details for the file smsir_sdk-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: smsir_sdk-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 15.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.12 {"installer":{"name":"uv","version":"0.11.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Arch Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for smsir_sdk-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 925a01ee8f5075cf6cfc4562891b5919eb5a20700bdee0477e6954e9ce8ae9b7
MD5 62d6061ef02221028d43a16e02bbc07d
BLAKE2b-256 4f32e28dfed4b245f5806bc7fb0b0962503cfa939eec758e765a4acbec8af449

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