A Python wrapper for the AfroMessage SMS service API that allows you to easily integrate SMS capabilities into your applications.
AfroMessage SDK is a lightweight Python library that provides an easy-to-use interface for the AfroMessage SMS API. With this SDK, you can:
- Send single SMS messages
- Send bulk SMS messages
- Generate and send security codes (OTPs)
- Verify security codes
The library handles authentication, request formatting, and error handling to streamline your integration with AfroMessage's services.
You can install the AfroMessage SDK using pip:
pip install afromessage-service- Python 3.6+
- httpx
To use the AfroMessage SDK, you'll need:
- Your AfroMessage Identifier ID
- Your sender name
- Your authentication token
- Optional callback URL
from afromessage_service import AfroMessage
# Initialize the AfroMessage client
afro_client = AfroMessage(
IdentifierId='your-identifier-id',
senderName='YourCompany',
auth_token='your-auth-token',
callbackUrl='https://your-callback-url.com/webhook'
)# Send a single SMS message
response = afro_client.sendMessage(
to='+251912345678',
message='Hello from AfroMessage SDK!'
)
# Check response
if response.status_code == 200:
print("Message sent successfully!")
print(response.json())
else:
print(f"Failed to send message: {response.text}")# Method 1: Different messages to different recipients
response = afro_client.sendBulkMessage(
messageList=[
{
'to': '+251912345678',
'message': 'Hello User 1!'
},
{
'to': '+251987654321',
'message': 'Hello User 2!'
}
],
campaignTitle='Welcome Campaign',
createCallback="https://your-domain.com/create-callback",
statusCallback="https://your-domain.com/status-callback"
)
# Method 2: Same message to multiple recipients
response = afro_client.sendBulkMessage(
messageList=[
{'to': '+251912345678'},
{'to': '+251987654321'}
],
campaignMessage='Same message to everyone!',
campaignTitle='Announcement Campaign'
)
# Check response
print(response.json())# Generate and send a security code
response = afro_client.sendSecurityCode(
to='+251912345678',
codeLength=4, # Length of the security code
codeType=0, # Type of code (0 = numeric, 1 = alphanumeric)
expires_after=300 # Expiry time in seconds
)
if response.status_code == 200:
verification_code = response.json().get('vc')
print(f"Security code sent successfully. Verification code: {verification_code}")
else:
print(f"Failed to send security code: {response.text}")# Verify a security code
response = afro_client.verifyCode(
to='+251912345678',
vc='verification-code-from-sendSecurityCode',
code='1234' # The code the user entered
)
if response.status_code == 200:
result = response.json()
if result.get('success'):
print("Code verified successfully!")
else:
print("Invalid code or verification failed.")
else:
print(f"Error during verification: {response.text}")AfroMessage(IdentifierId, senderName, auth_token, callbackUrl)IdentifierId(str): Your AfroMessage identifier IDsenderName(str): The name that will appear as the senderauth_token(str): Your AfroMessage authentication tokencallbackUrl(str): URL for delivery status callbacks
Send a single SMS message.
sendBulkMessage(messageList, campaignTitle="", campaignMessage="", createCallback="", statusCallback="")
Send bulk SMS messages.
Generate and send a security code.
Verify a security code.
The SDK returns httpx Response objects that include status codes and response content. You should always check the status code to ensure successful API calls:
response = afro_client.sendMessage(to='+251912345678', message='Hello!')
if response.status_code == 200:
# Success
print(response.json())
else:
# Error
print(f"Error: {response.status_code} - {response.text}")Contributions to the AfroMessage SDK are welcome! If you'd like to contribute, please:
- Fork the repository
- Create a feature branch (
git checkout -b feature/your-feature-name) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin feature/your-feature-name) - Create a new Pull Request
# Clone the repository
git clone https://github.com/p4ndish/afromessage_service.git
cd afromessage_service
# Install development dependencies
pip install -e ".[dev]"
# Run tests
pytestThis project is licensed under the MIT License - see the LICENSE file for details.