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

Uploaded Python 3

File details

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

File metadata

  • Download URL: smsir_sdk-1.0.0.tar.gz
  • Upload date:
  • Size: 7.6 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.0.tar.gz
Algorithm Hash digest
SHA256 35d9767e098ae634dfc62fdea4824a4a9de9a1dd091754377b0db23fb72cc5ea
MD5 a27da51e08947206c500fd766f3b76c0
BLAKE2b-256 0571be777d2fe7e47186959559f03bd3a0bee717f37686a5bf270cccee3668ef

See more details on using hashes here.

File details

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

File metadata

  • Download URL: smsir_sdk-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 14.9 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 85668462ff7509a4bd51349360d927236511e82f9153ca75d5739cb2c2674c59
MD5 00dabcef9813c89e9a0bbb31481ea712
BLAKE2b-256 0bd36d74001da253d6094695b95a4edca74b656a9f3673518f6d067523dee0bc

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