A Python wrapper for the SMSWapi WhatsApp API
Project description
SMSWapi Python SDK
A production-ready Python wrapper for the SMSWapi WhatsApp & SMS API.
Installation
pip install smswapi
Or install from source:
git clone https://github.com/yourusername/smswapi.git
cd smswapi
pip install .
Quick Start
import smswapi
# Set your API secret globally (from Tools -> API Keys in dashboard)
smswapi.API_SECRET = "your_api_secret_here"
# Create client
client = smswapi.SMSWapi()
# Check credits
credits = client.get_credits()
print(f"Balance: {credits['data']['credits']} {credits['data']['currency']}")
# Send WhatsApp message
response = client.send_whatsapp(
recipient="+40712034567",
message="Hello from SMSWapi!",
account="your_whatsapp_account_unique_id"
)
# Send SMS
response = client.send_sms(
phone="+40712034567",
message="Hello via SMS!",
mode="credits",
gateway="your_gateway_id"
)
Configuration
import smswapi
# Required: Your API secret
smswapi.API_SECRET = "your_api_secret"
# Optional: Default country code (auto-prefixes phone numbers)
smswapi.DEFAULT_COUNTRY_CODE = "40" # Romania
# Optional: Request timeout in seconds (default: 30)
smswapi.TIMEOUT = 60
# Optional: Custom base URL
smswapi.BASE_URL = "https://smswapi.com/api"
Client Initialization
# Use global config
client = smswapi.SMSWapi()
# Or provide config per-client
client = smswapi.SMSWapi(
secret="your_api_secret",
default_country_code="40",
timeout=60
)
API Methods
Account
# Get remaining credits
client.get_credits()
# Get subscription info
client.get_subscription()
# Get partner earnings
client.get_earnings()
Contacts
# Create contact
client.create_contact(phone="+40712034567", name="John Doe", groups="1,2")
# Create group
client.create_group(name="My Group")
# Get contacts/groups
client.get_contacts(limit=10, page=1)
client.get_groups(limit=10, page=1)
client.get_unsubscribed(limit=10, page=1)
# Delete
client.delete_contact(contact_id=123)
client.delete_group(group_id=456)
client.delete_unsubscribed(contact_id=789)
OTP (One-Time Password)
# Send OTP via SMS
response = client.send_otp(
phone="+40712034567",
message="Your OTP is {{otp}}",
otp_type="sms",
mode="credits",
gateway="your_gateway_id",
expire=300
)
otp_code = response['data']['otp']
# Send OTP via WhatsApp
client.send_otp(
phone="+40712034567",
message="Your OTP is {{otp}}",
otp_type="whatsapp",
account="your_wa_account_id"
)
# Verify OTP
client.verify_otp(otp="123456")
SMS
# Send single SMS
client.send_sms(
phone="+40712034567",
message="Hello!",
mode="credits", # or "devices"
gateway="gateway_id", # for credits mode
# device="device_id", # for devices mode
# sim=1, # SIM slot for devices mode
priority=0 # 0/1=immediate, 2=queued
)
# Send bulk SMS
client.send_sms_bulk(
message="Hello everyone!",
campaign="My Campaign",
mode="credits",
gateway="gateway_id",
numbers=["+40712034567", "+40712034568"],
# groups=["1", "2"], # or use contact groups
)
# Get messages
client.get_sms_sent(limit=10, page=1)
client.get_sms_received(limit=10, page=1)
client.get_sms_pending(limit=10, page=1)
client.get_sms_campaigns(limit=10, page=1)
client.get_sms_message(message_id=123, message_type="sent")
# Campaign control
client.start_sms_campaign(campaign_id=123)
client.stop_sms_campaign(campaign_id=123)
# Delete
client.delete_sms_sent(message_id=123)
client.delete_sms_received(message_id=456)
client.delete_sms_campaign(campaign_id=789)
# Send single message
client.send_whatsapp(
recipient="+40712034567",
message="Hello!",
account="wa_account_unique_id",
msg_type="text", # "text", "media", or "document"
priority=2 # 1=immediate, 2=queued
)
# Send with media
client.send_whatsapp(
recipient="+40712034567",
message="Check this image!",
account="wa_account_id",
msg_type="media",
media_url="https://example.com/image.jpg",
media_type="image"
)
# Send with document
client.send_whatsapp(
recipient="+40712034567",
message="Here's the document",
account="wa_account_id",
msg_type="document",
document_url="https://example.com/file.pdf",
document_type="pdf",
document_name="report.pdf"
)
# Send bulk WhatsApp
client.send_whatsapp_bulk(
message="Hello everyone!",
campaign="My WA Campaign",
account="wa_account_id",
recipients=["+40712034567", "+40712034568"],
# groups=["1", "2"],
)
# Get chats
client.get_wa_accounts(limit=10, page=1)
client.get_wa_sent(limit=10, page=1)
client.get_wa_received(limit=10, page=1)
client.get_wa_pending(limit=10, page=1)
client.get_wa_campaigns(limit=10, page=1)
client.get_wa_message(message_id=123, message_type="sent")
# WhatsApp groups
client.get_wa_groups(unique="wa_account_unique_id")
client.get_wa_group_contacts(unique="wa_account_id", gid="group_id")
# Validate phone number
client.validate_whatsapp(phone="+40712034567", unique="wa_account_id")
# Campaign control
client.start_wa_campaign(campaign_id=123)
client.stop_wa_campaign(campaign_id=123)
# Delete
client.delete_wa_sent(chat_id=123)
client.delete_wa_received(chat_id=456)
client.delete_wa_campaign(campaign_id=789)
client.delete_wa_account(unique="wa_account_id")
WhatsApp Account Linking
# Get available servers
client.get_wa_servers()
# Link new account (returns QR code)
result = client.link_whatsapp()
print(f"Scan QR: {result['data']['qrimagelink']}")
# Relink existing account
client.relink_whatsapp(unique="wa_account_id")
# Get account info after linking
client.get_wa_info(token="token_from_link")
Android Devices
# Get linked devices
client.get_devices(limit=10, page=1)
# Send USSD request
client.send_ussd(code="*123#", sim=1, device="device_unique_id")
# Get USSD requests
client.get_ussd(limit=10, page=1)
client.delete_ussd(ussd_id=123)
# Delete notification
client.delete_notification(notification_id=123)
Gateways & Utilities
# Get gateway rates
client.get_rates()
# Get URL shorteners
client.get_shorteners()
Error Handling
from smswapi import (
SMSWapiError,
AuthenticationError,
PermissionError,
InsufficientCreditsError
)
try:
client.send_whatsapp(...)
except AuthenticationError:
print("Invalid API secret")
except PermissionError as e:
print(f"Missing permission: {e}")
except InsufficientCreditsError:
print("Not enough credits")
except SMSWapiError as e:
print(f"API error: {e}")
License
MIT License - see LICENSE file.
Links
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
smswapi-1.0.0.tar.gz
(13.7 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
smswapi-1.0.0-py3-none-any.whl
(12.0 kB
view details)
File details
Details for the file smswapi-1.0.0.tar.gz.
File metadata
- Download URL: smswapi-1.0.0.tar.gz
- Upload date:
- Size: 13.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4a64179f053cd00d7caaac1dd32feca44907d7aa054f807c9f9cbda4e08fae86
|
|
| MD5 |
7e3671656f4d5efb760561a56eb42d4b
|
|
| BLAKE2b-256 |
3b8c14655441dd8a1805396564790083acec1500d83496ea0a0083754db5cf9f
|
File details
Details for the file smswapi-1.0.0-py3-none-any.whl.
File metadata
- Download URL: smswapi-1.0.0-py3-none-any.whl
- Upload date:
- Size: 12.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4b8e17e94f1691ad95ed42ab34a957230970b769e5e02591162ffbaab528a4e7
|
|
| MD5 |
3c448c675787f5f5441521123abd8890
|
|
| BLAKE2b-256 |
08b272de6f52d807c136dab4df1492ed2bb86e05e5f994d341cf298aa389bf59
|