Skip to content

Latest commit

 

History

History

README.md

kwtSMS Python: Examples

Step-by-step examples covering everything from a first send to a production OTP system with CAPTCHA, rate limiting, and brute-force protection.


Setup

1. Install

pip install kwtsms
# or with uv:
uv add kwtsms

Requires Python 3.8+, no external dependencies.

2. Configure .env

cp examples/.env.example .env
KWTSMS_USERNAME=your_api_username   # API user, NOT your phone number or website login
KWTSMS_PASSWORD=your_api_password
KWTSMS_SENDER_ID=KWT-SMS            # Replace with a private Sender ID before production
KWTSMS_TEST_MODE=1                  # Set to 0 when ready to deliver real messages
KWTSMS_LOG_FILE=kwtsms.log          # Leave empty to disable request logging

Credentials: kwtsms.com: Account: API.

3. Verify

python examples/01-quickstart.py

Expected output: Connected! Balance: X credits


Examples

# File What it covers Docs
01 01-quickstart.py Verify credentials, send your first SMS docs
02 02-otp.py Generate and send a one-time code (basic) docs
03 03-bulk.py Send to many numbers, auto-batching for >200 docs
04 04-validation.py Local phone validation and API routing check docs
05 05-error-handling.py Handle every error category with the right action docs
06 06-message-cleaning.py What clean_message() strips and why docs
07 07-django.py Service class, view, management command docs
08 08-flask.py Flask blueprint, OTP endpoints, health check docs
09 09-fastapi.py FastAPI router, Pydantic models, Depends injection docs
10 10-otp-production.py Full production OTP: SQLite, CAPTCHA, rate limiting, brute-force docs

Reference


CLI

For a standalone cross-platform CLI, see kwtsms-cli.