Skip to main content

Official Python SDK for the Tuseme SMS API

Project description

Tuseme Python SDK

Official Python client for the Tuseme SMS API.

PyPI version Python 3.8+ License: MIT

Installation

pip install tuseme-sdk

Quick Start

from tuseme import TusemeClient

client = TusemeClient(
    api_key="tk_test_your_api_key",
    api_secret="sk_test_your_api_secret",
)

# Send an SMS
response = client.messages.send(
    content="Hello from Tuseme! Your OTP is 482910.",
    sender_id="TUSEME-LTD",
    recipients=[
        {"msisdn": "+254712345678", "name": "John Doe"}
    ],
    type="transactional",
    priority="HIGH",
)

print(f"Message ID: {response.message_id}")
print(f"Status: {response.status}")

Authentication

The SDK handles authentication automatically. Just provide your API Key and Secret (from the Tuseme Dashboard):

# Sandbox credentials (for testing)
client = TusemeClient(api_key="tk_test_...", api_secret="sk_test_...")

# Production credentials
client = TusemeClient(api_key="tk_live_...", api_secret="sk_live_...")

The SDK will:

  1. Automatically obtain an access token on the first request
  2. Cache the token until it expires
  3. Transparently refresh expired tokens

Usage

Send SMS

# Single recipient
response = client.messages.send(
    content="Your verification code is 123456",
    sender_id="TUSEME-LTD",
    recipients=[{"msisdn": "+254712345678"}],
    type="transactional",
)

# Multiple recipients
response = client.messages.send(
    content="Flash sale! 50% off today only.",
    sender_id="TUSEME-LTD",
    recipients=[
        {"msisdn": "+254712345678", "name": "Alice"},
        {"msisdn": "+254798765432", "name": "Bob"},
    ],
    type="promotional",
    priority="MEDIUM",
)

# With metadata
response = client.messages.send(
    content="Your order #12345 has shipped!",
    sender_id="TUSEME-LTD",
    recipients=[{"msisdn": "+254712345678"}],
    metadata={"order_id": "12345", "campaign": "order_updates"},
)

Check Delivery Status

status = client.messages.get("msg_a1b2c3d4...")
print(f"Status: {status.status}")
print(f"Delivered at: {status.delivered_at}")

List Messages

result = client.messages.list(page=1, page_size=20, status="delivered")
for msg in result["data"]:
    print(f"{msg['recipient']}: {msg['status']}")

Error Handling

from tuseme import TusemeClient, AuthenticationError, ValidationError, RateLimitError

client = TusemeClient(api_key="...", api_secret="...")

try:
    response = client.messages.send(
        content="Hello!",
        recipients=[{"msisdn": "+254712345678"}],
    )
except AuthenticationError:
    print("Invalid credentials — check your API key and secret")
except ValidationError as e:
    print(f"Invalid request: {e}")
except RateLimitError as e:
    print(f"Rate limited — retry after {e.retry_after}s")

Configuration

client = TusemeClient(
    api_key="...",
    api_secret="...",
    base_url="https://api.tuseme.co.ke/api/v1",  # default
    timeout=30,       # request timeout in seconds
    max_retries=3,    # automatic retries on failure
)

License

MIT — see LICENSE.

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

tuseme_sdk-1.0.0.tar.gz (9.4 kB view details)

Uploaded Source

Built Distribution

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

tuseme_sdk-1.0.0-py3-none-any.whl (9.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: tuseme_sdk-1.0.0.tar.gz
  • Upload date:
  • Size: 9.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for tuseme_sdk-1.0.0.tar.gz
Algorithm Hash digest
SHA256 6220e51351b3d9305c75db3945246b1c4471198cbe15a10bd68013d29eddd416
MD5 f06825266d2f188d809240a20691ba11
BLAKE2b-256 e9a825d0b56bc07241c5799a4555de38bc87536d6331ee48e9460462c41ef327

See more details on using hashes here.

File details

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

File metadata

  • Download URL: tuseme_sdk-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 9.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for tuseme_sdk-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d4397d98cdc04dfdc7a23d063aad72cf8cd0dee386ff233d942f523c6b8b6afe
MD5 b18f3afdaf766c87d395fa04b93ab2bd
BLAKE2b-256 c103423ad80ed43df99a0ef75112b95742292c877beba0498cbb3548da51d5af

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