comms-sdk Python SDK
A Python implementation of the CommsSDK for sending SMS and managing communications, following the same patterns as the Ruby and Kotlin reference implementations.
Version: 1.1.0
Features
- Consistent API across all supported languages
- Authenticate with username and API key
- Send SMS to one or more recipients
- Optional sender ID and message priority
- Check account balance
- Comprehensive error handling
Installation
Install the package from PyPI:
pip install comms-sdk
Or for development:
pip install .
Usage
Basic Authentication
from comms_sdk.v1 import CommsSDK, MessagePriority
# Authenticate with username and API key
sdk = CommsSDK.authenticate("your_username", "your_api_key")
Sending SMS
# Send SMS to a single number
success = sdk.send_sms("0712345678", "Message to send")
# Send SMS to multiple numbers
success = sdk.send_sms(["0712345678", "0787654321"], "Message to many")
# Send SMS with custom sender ID and priority
success = sdk.send_sms(
"0712345678",
"Hello!",
sender_id="MyApp",
priority=MessagePriority.HIGH
)
# Get full API response
response = sdk.query_send_sms(
["0712345678"],
"Hello!",
"MyApp",
MessagePriority.HIGHEST
)
Checking Balance
# Get balance as a float
balance = sdk.get_balance()
print(f"Balance: {balance}")
# Get full balance response
response = sdk.query_balance()
print(f"Status: {response.Status}")
print(f"Balance: {response.Balance}")
Configuration
# Use sandbox environment
CommsSDK.use_sandbox()
# Use live server (default)
CommsSDK.use_live_server()
# Set custom sender ID
sdk.with_sender_id("MyCustomSender")
API Reference
CommsSDK
Static/Class Methods
CommsSDK.authenticate(user_name: str, api_key: str) -> CommsSDK- Authenticate and return SDK instance.
CommsSDK.use_sandbox()- Switch to sandbox environment.
CommsSDK.use_live_server()- Switch to live environment.
Instance Methods
with_sender_id(sender_id: str) -> CommsSDK- Set sender ID, returns self for chaining.
send_sms(numbers: str | List[str], message: str, sender_id: Optional[str] = None, priority: MessagePriority = MessagePriority.HIGH) -> bool- Send SMS, returns boolean.
query_send_sms(numbers: str | List[str], message: str, sender_id: Optional[str] = None, priority: MessagePriority = MessagePriority.HIGH) -> Optional[ApiResponse]- Same as
send_sms, but returns the full ApiResponse.
- Same as
get_balance() -> Optional[float]- Get account balance as float.
query_balance() -> Optional[ApiResponse]- Get full balance response as ApiResponse.
set_authenticated()- Mark SDK as authenticated (internal use).
Properties
api_key- The API key used for authentication.user_name- The username used for authentication.sender_id- Current sender ID.is_authenticated- Authentication status.
Models
MessagePriority
MessagePriority.HIGHEST- Priority "0"MessagePriority.HIGH- Priority "1"MessagePriority.MEDIUM- Priority "2"MessagePriority.LOW- Priority "3"MessagePriority.LOWEST- Priority "4"
ApiResponse
Status- Response status ("OK" or "Failed")Message- Response messageCost- Message cost (not always a whole number)MsgFollowUpUniqueCode- Unique tracking codeBalance- Account balance
Error Handling
The SDK raises appropriate Python exceptions:
try:
sdk = CommsSDK.authenticate("", "") # Empty credentials
except ValueError as e:
print(f"Authentication error: {e}")
try:
sdk.send_sms([], "") # Empty numbers and message
except ValueError as e:
print(f"Validation error: {e}")
Thread Safety
The SDK is thread-safe for read operations. For write operations or shared state modifications, use appropriate synchronization mechanisms.
Contributing
Bug reports and pull requests are welcome on GitHub.
License
The package is available as open source under the terms of the MIT License.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
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
File details
Details for the file comms_sdk-1.1.0.tar.gz.
File metadata
- Download URL: comms_sdk-1.1.0.tar.gz
- Upload date:
- Size: 7.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.14.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
252c06d338eb3088dfc56397afea5c3991fdf6238cefaffe39d0f792caa83844
|
|
| MD5 |
5f51a16e6f0a51bce566c842d1886966
|
|
| BLAKE2b-256 |
ce7cfcff63b50f9dbe8a9b29520df674b529c891d9588de7881c5149ff90d31b
|
File details
Details for the file comms_sdk-1.1.0-py3-none-any.whl.
File metadata
- Download URL: comms_sdk-1.1.0-py3-none-any.whl
- Upload date:
- Size: 7.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.14.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
345512178ca0b050fe8ff4f7e7fa90ab41b5397b296ddcb27db6bb9248ea51ce
|
|
| MD5 |
84f2ceed84f3891b093157900bf9f02b
|
|
| BLAKE2b-256 |
756ceaeab85e20dbafea49f5d0a9d994f4ee6204a40ab3901e749fd5d291b820
|