Skip to main content

Python client for the kwtSMS API (kwtsms.com)

Project description

kwtsms

Python client for the kwtSMS API — Kuwait SMS gateway.

Zero external dependencies. Python 3.8+.

Install

pip install kwtsms

Quick start

from kwtsms import KwtSMS

sms = KwtSMS.from_env()                              # reads .env or env vars
ok, balance, err = sms.verify()                      # test credentials
result = sms.send("96598765432", "Your OTP is: 123456")
result = sms.send("96598765432", "Hello", sender="MY-APP")  # override sender
result = sms.send(["96598765432", "+96512345678"], "Hello!")  # multiple numbers

# Every error response includes an 'action' field with developer guidance
if result["result"] == "ERROR":
    print(result["code"])        # e.g. "ERR003"
    print(result["description"]) # human-readable error
    print(result["action"])      # what to do next

# Invalid numbers are reported per-number, not raised
result = sms.send(["96598765432", "abc", "user@gmail.com"], "Hi")
# result["invalid"] → [{"input": "abc", "error": "..."}, ...]

report = sms.validate(["96598765432", "+96512345678", "123"])
# report["ok"] → valid, report["er"] → format error, report["nr"] → no route
# report["rejected"] → pre-rejected with per-number error messages
balance = sms.balance()

Utility functions

from kwtsms import normalize_phone, validate_phone_input, clean_message

normalize_phone("+965 9876-5432")       # → "96598765432"
validate_phone_input("user@gmail.com")  # → (False, "is an email address...", "")
validate_phone_input("+96598765432")    # → (True, None, "96598765432")
clean_message("OTP: ١٢٣٤٥٦ 🎉")       # → "OTP: 123456 "

Configuration

Create a .env file (or set environment variables):

KWTSMS_USERNAME=your_api_user
KWTSMS_PASSWORD=your_api_pass
KWTSMS_SENDER_ID=YOUR-SENDERID   # use KWT-SMS for testing only
KWTSMS_TEST_MODE=1                # 1 = test (safe default), 0 = live
KWTSMS_LOG_FILE=kwtsms.log

Or run the setup wizard:

kwtsms setup

CLI

kwtsms setup                                  # first-time wizard
kwtsms verify
kwtsms balance
kwtsms send 96598765432 "Your OTP is: 123456"
kwtsms validate 96598765432 +96512345678

Sender ID

KWT-SMS is a shared sender for testing only. Register a private sender ID on kwtsms.com before going live — use a Transactional sender ID for OTP messages to ensure delivery to DND numbers.

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

kwtsms-0.2.0.tar.gz (27.2 kB view details)

Uploaded Source

Built Distribution

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

kwtsms-0.2.0-py3-none-any.whl (14.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: kwtsms-0.2.0.tar.gz
  • Upload date:
  • Size: 27.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.9

File hashes

Hashes for kwtsms-0.2.0.tar.gz
Algorithm Hash digest
SHA256 fbf17bb2d36575ed714d7e03dd61ebd7a03da20ac2727e512be1f3878ffec9d5
MD5 34b4e36fa918db634a7bdffcbb696f65
BLAKE2b-256 9c76b4b50711306e96b7e177d3e93e9c2406d47641a41ae370ed637939c2b87e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kwtsms-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 14.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.9

File hashes

Hashes for kwtsms-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 97a8b2fd18c1028ee956ed4ede4f1493c3abcc92a62e99bcc5dd6634e3f9387a
MD5 bb38921cf3cf645c456b601d6090e861
BLAKE2b-256 7e8e78de55650454ea74e6fb9b783b2bca0925abc68b88ad392d7cc84dba724d

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