Beem SMS Python SDK
A professional Python SDK for sending SMS via the Beem SMS API. This package provides a simple, robust, and feature-rich interface for integrating SMS functionality into your Python applications.
Features
- Easy to use - Simple, intuitive API
- Robust error handling - Comprehensive exception handling and validation
- Phone number validation - Built-in phone number validation and formatting
- Retry logic - Automatic retry on failures with exponential backoff
- Logging support - Detailed logging for debugging and monitoring
- Type hints - Full type hint support for better IDE experience
- Security - Secure credential handling
- Bulk SMS - Efficient bulk SMS sending with batching
- Well tested - Comprehensive test suite
- CLI tool - Command-line interface for quick operations
Installation
pip install beem-sms-python
Development Installation
git clone https://github.com/islandkid-20/beem-sms-python.git
cd beem-sms-python
pip install -e .[dev]
Quick Start
Basic Usage
from beem_sms import BeemSMSClient
# Initialize client
client = BeemSMSClient(
api_key="your_api_key",
secret_key="your_secret_key"
)
# Send SMS
response = client.send_sms(
source_addr="YourApp",
dest_addr="+255742892731",
message="Hello from Beem SMS!"
)
if response.success:
print(f"SMS sent! Request ID: {response.request_id}")
else:
print(f"Failed: {response.message}")
Using Context Manager
from beem_sms import BeemSMSClient
with BeemSMSClient("api_key", "secret_key") as client:
response = client.send_sms(
source_addr="YourApp",
dest_addr="+255742892731",
message="Hello World!"
)
Bulk SMS
recipients = ["+255742892731", "+255783346386", "+255713521250"]
results = client.send_bulk_sms(
source_addr="YourApp",
recipients=recipients,
message="Bulk SMS message",
batch_size=10
)
successful = sum(1 for r in results if r.success)
print(f"Sent {successful}/{len(results)} batches successfully")
Convenience Function
from beem_sms import send_sms
response = send_sms(
api_key="your_api_key",
secret_key="your_secret_key",
source_addr="YourApp",
dest_addr="+255742892731",
message="Quick SMS!"
)
CLI Usage
The package includes a command-line tool for quick SMS operations:
Send SMS
beem-sms send --api-key YOUR_KEY --secret-key YOUR_SECRET \
--sender "YourApp" --message "Hello CLI!" \
--recipients "+255742892731" "+255783346386"
Send Bulk SMS from File
# Create recipients.txt with one phone number per line
echo "+255742892731" > recipients.txt
echo "+255783346386" >> recipients.txt
beem-sms send --sender "YourApp" --message "Bulk message" \
--file recipients.txt --bulk --batch-size 50
Validate Phone Numbers
beem-sms validate --numbers "+255742892731" "0783346386" "invalid"
Configuration File
Create ~/.beem_sms.json:
{
"api_key": "your_api_key",
"secret_key": "your_secret_key"
}
Then use CLI without credentials:
beem-sms send --sender "YourApp" --message "Hello!" \
--recipients "+255742892731"
Error Handling
The SDK provides specific exceptions for different error scenarios:
from beem_sms import (
BeemSMSClient,
AuthenticationError,
ValidationError,
APIError,
NetworkError
)
client = BeemSMSClient("api_key", "secret_key")
try:
response = client.send_sms(
source_addr="YourApp",
dest_addr="+255742892731",
message="Test message"
)
except AuthenticationError:
print("Invalid API credentials")
except ValidationError as e:
print(f"Invalid input: {e}")
except NetworkError:
print("Network connection failed")
except APIError as e:
print(f"API error: {e}")
Phone Number Validation
from beem_sms import PhoneNumberValidator
# Validate single number
is_valid = PhoneNumberValidator.validate("+255742892731")
# Clean and format number
clean_number = PhoneNumberValidator.clean("0742892731")
# Returns: "+255742892731"
# Validate batch
numbers = ["+255742892731", "invalid", "0783346386"]
results = PhoneNumberValidator.validate_batch(numbers)
# Returns: [True, False, True]
Advanced Configuration
import logging
# Custom logger
logger = logging.getLogger("my_app")
client = BeemSMSClient(
api_key="your_api_key",
secret_key="your_secret_key",
base_url="https://custom-endpoint.com/v1/send", # Custom endpoint
timeout=60, # 60 second timeout
max_retries=5, # 5 retry attempts
logger=logger # Custom logger
)
API Reference
BeemSMSClient
Methods
send_sms(source_addr, dest_addr, message, encoding=SMSEncoding.PLAIN_TEXT)- Send SMS to single or multiple recipientssend_bulk_sms(source_addr, recipients, message, encoding, batch_size=100)- Send bulk SMS with batching
Parameters
source_addr(str): Sender ID or phone numberdest_addr(str | List[str]): Recipient phone number(s)message(str): SMS message contentencoding(SMSEncoding): Message encoding (PLAIN_TEXT or UNICODE)
SMSResponse
Response object with the following attributes:
success(bool): Whether the operation succeededstatus_code(int): HTTP status codemessage(str): Response messageresponse_data(dict): Raw API response datarequest_id(str): Request ID for tracking
Exceptions
SMSError- Base exceptionAuthenticationError- Invalid credentialsValidationError- Invalid input parametersAPIError- API request failedNetworkError- Network/connection issues
Testing
Run the test suite:
# Run all tests
make test
# Run with coverage
make test-cov
# Run specific test file
pytest tests/test_client.py -v
Development
Set up development environment:
make dev-setup
Run code quality checks:
make check # Runs format-check, lint, type-check, and test
Format code:
make format
Contributing
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Make your changes
- Run tests and code quality checks (
make check) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Support
- Email: j1997ames@gmail.com
- Issues: GitHub Issues
- Documentation: Read the Docs
Changelog
v1.0.3
- Added Read the Docs documentation support:
- Created
.readthedocs.ymlconfiguration file - Set up Sphinx documentation with MyST parser
- Added documentation dependencies (sphinx, sphinx-rtd-theme, myst-parser)
- Documentation now auto-syncs with README.md content
- Added support for PDF and EPUB formats
- Documentation available at: https://beem-sms-python.readthedocs.io/
- Created
v1.0.2
- Adjusted message length limits to support multi-part SMS:
- Increased
MAX_MESSAGE_LENGTHfrom160to153 * 3 - Increased
MAX_UNICODE_LENGTHfrom70to67 * 3
- Increased
v1.0.1
- Initial release
- Basic SMS sending functionality
- Bulk SMS support
- Phone number validation
- CLI tool
- Comprehensive test suite
Metadata
Release files for beem-sms-python 1.0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| beem_sms_python-1.0.3.tar.gz | 15.6 kB | Without provenance | Details for beem_sms_python-1.0.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| beem_sms_python-1.0.3-py3-none-any.whl | Python 3 | none | any | Details for beem_sms_python-1.0.3-py3-none-any.whl |
Total release size: 30.0 kB
Release files / beem_sms_python-1.0.3.tar.gz
| Download URL | beem_sms_python-1.0.3.tar.gz |
|---|---|
| Size | 15.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c576fd332a0c384e18bc7c0d0f251d6361775fe25dba5c8b6c681f9a2d478f7e
|
|
BLAKE2b-256 checksum How to use checksums |
5a6be810eaf5ce58c3a29539791945671efb5b764af636c07daba729dcc279b6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.5
|
Release files / beem_sms_python-1.0.3-py3-none-any.whl
| Download URL | beem_sms_python-1.0.3-py3-none-any.whl |
|---|---|
| Size | 14.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d3b499840920d784fe85557dbae94ce2e2a3fc1358d350c910c35cec6aecb33f
|
|
BLAKE2b-256 checksum How to use checksums |
a61a6a289fa47c903cc4e02d49f5f96fed226fb200233c30a3e923a34c3cfec4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.5
|
Security for beem-sms-python 1.0.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.