Skip to content

[Proposal] Type-safe sync/async Python library #8

Description

@YouKnow-sys

Hi,

I recently needed to integrate sms.ir into one of my projects and used the official library. It works, but it lacks any type safety, essentially it's a thin wrapper around raw HTTP requests, leaving callers to deal with untyped JSON responses directly.

I ended up writing a full replacement. Here's what it offers over the current library:

  • Fully type-safe: every endpoint, request payload, and response is a typed and response are Pydantic models.
  • Both sync and async support via httpx
  • Minimal dependencies: only httpx and pydantic
  • No raw JSON handling: response fields are accessible as typed attributes
  • Clean exception hierarchy: the library never leaks underlying dependency errors (httpx, pydantic). Everything surfaces as a library-specific exception type: NetworkError, APIError, AuthenticationError, RateLimitError, ResponseParsingError, and ResponseValidationError, all under a common SMSIRError base

Example (sync):

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)

The source is available at https://github.com/YouKnow-sys/smsir and published on PyPI as smsir-sdk.

I'm open to contributing this as a replacement for the official library if there's interest. Happy to discuss the design or adapt it to fit the project's direction.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions