A Python SDK for the NigeriaBulkSMS API.
Project description
NigeriaBulkSMS Python SDK
A production-grade Python SDK for the NigeriaBulkSMS.com API. This SDK provides a simple, robust, and type-safe way to integrate bulk SMS, voice messaging, and data fetching functionalities into your Python applications.
Features
- 🚀 Easy to use - Simple and intuitive API
- 🛡️ Robust error handling - Comprehensive error types and validation
- 📱 SMS & Voice - Support for text messages, voice calls, and TTS
- 📊 Data fetching - Access to account balance, history, and more
Installation
Install the package using pip:
pip install nigeriabulksms-sdk
Basic Usage
First, import the NigeriaBulkSMSClient and initialize it with your username and password.
from nigeriabulksms_sdk import NigeriaBulkSMSClient
from nigeriabulksms_sdk.exceptions import NigeriaBulkSMSException
# Replace with your actual API credentials
USERNAME = "YOUR_USERNAME"
PASSWORD = "YOUR_PASSWORD"
client = NigeriaBulkSMSClient(USERNAME, PASSWORD)
print("Testing NigeriaBulkSMS SDK...\n")
try:
# Send an SMS
print("Attempting to send SMS...")
sms_response = client.sms.send(
message="Hello from Python SDK test!",
sender="TestSender",
mobiles=["2348030000000"]
)
print(f"SMS Send Response: {sms_response}\n")
except NigeriaBulkSMSException as e:
print(f"Caught NigeriaBulkSMSException for SMS: {e.message} (Code: {e.code})\n")
except Exception as e:
print(f"Caught unexpected Exception for SMS: {e}\n")
try:
# Get account balance
print("Attempting to get balance...")
balance_response = client.data.get_balance()
print(f"Balance Response: {balance_response}\n")
except NigeriaBulkSMSException as e:
print(f"Caught NigeriaBulkSMSException for Balance: {e.message} (Code: {e.code})\n")
except Exception as e:
print(f"Caught unexpected Exception for Balance: {e}\n")
try:
# Test TTS call
print("Attempting to send TTS call...")
tts_response = client.call.send_tts(
message="This is a test text to speech message.",
sender="2348030000000", # Use a mobile number as sender for TTS
mobiles=["2348030000000"]
)
print(f"TTS Call Response: {tts_response}\n")
except NigeriaBulkSMSException as e:
print(f"Caught NigeriaBulkSMSException for TTS: {e.message} (Code: {e.code})\n")
except Exception as e:
print(f"Caught unexpected Exception for TTS: {e}\n")
API Reference
NigeriaBulkSMSClient(username, password, base_url=None)
The main client class to interact with the NigeriaBulkSMS API.
username(str): Your NigeriaBulkSMS username.password(str): Your NigeriaBulkSMS password.base_url(str, optional): The base URL for the API. Defaults tohttps://portal.nigeriabulksms.com/api/.
SMS Service (client.sms)
send(message, sender, mobiles)
Sends a text message to one or more mobile numbers.
message(str): The content of the SMS message.sender(str): The sender ID (max 11 alphanumeric characters).mobiles(str or list): A single mobile number string or a list of mobile number strings. Numbers should be in international format (e.g.,2348030000000).
Call Service (client.call)
send_tts(message, sender, mobiles)
Sends a Text-to-Speech (TTS) call to one or more mobile numbers.
message(str): The text to be converted to speech.sender(str): The sender ID.mobiles(str or list): A single mobile number string or a list of mobile number strings.
send_audio(audio_reference, sender, mobiles)
Sends a pre-recorded audio call to one or more mobile numbers using an audio reference.
audio_reference(str): The reference ID of the uploaded audio file.sender(str): The sender ID.mobiles(str or list): A single mobile number string or a list of mobile number strings.
Audio Service (client.audio)
upload(url)
Uploads an audio file from a given URL to the NigeriaBulkSMS platform.
url(str): The URL of the audio file (e.g.,https://example.com/audio.mp3).
Data Service (client.data)
get_balance()
Retrieves the current account balance.
get_profile()
Retrieves the customer profile information.
get_contacts()
Retrieves the list of contacts.
get_numbers()
Retrieves the list of saved numbers.
get_groups()
Retrieves the list of groups.
get_audios()
Retrieves the list of saved audio files.
get_history()
Retrieves the message history.
get_scheduled()
Retrieves the list of scheduled messages.
get_reports()
Retrieves the delivery reports.
get_payments()
Retrieves the payment history.
Error Handling
The SDK raises NigeriaBulkSMSException for API-specific errors. You should wrap your API calls in try-except blocks to handle these exceptions gracefully.
from nigeriabulksms_sdk import NigeriaBulkSMSClient
from nigeriabulksms_sdk.exceptions import NigeriaBulkSMSException
client = NigeriaBulkSMSClient("YOUR_USERNAME", "YOUR_PASSWORD")
try:
response = client.sms.send("Test message", "TestApp", ["2348000000000"])
print(response)
except NigeriaBulkSMSException as e:
print(f"API Error: {e.message} (Code: {e.code})")
except Exception as e:
print(f"General Error: {e}")
Common error codes are:
100: Incomplete request parameters101: Request denied110: Login status failed111: Login status denied150: Insufficient funds191: Internal error
For a full list of error codes, refer to the official NigeriaBulkSMS API documentation.
Contributing
Feel free to contribute to this SDK by submitting issues or pull requests on GitHub.
License
This SDK is open-sourced software licensed under the MIT license.
Author: Timothy Dake
- LinkedIn: https://www.linkedin.com/in/timothy-dake-14801571/
- X (formerly Twitter): @timothydake
- Email: timdake4@gmail.com
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
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 nigeriabulksms_sdk-1.0.0.tar.gz.
File metadata
- Download URL: nigeriabulksms_sdk-1.0.0.tar.gz
- Upload date:
- Size: 10.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fd8a5ad94894c4b67682a2ae6ade39156e247ee4a377c1a79d973e45a66cf66a
|
|
| MD5 |
7adb638a3d9756083b93d8e54c5047f6
|
|
| BLAKE2b-256 |
5183586b8837cdc2c62488153b9527b730bc852ab441f300bec97d4c68c7d6d6
|
File details
Details for the file nigeriabulksms_sdk-1.0.0-py3-none-any.whl.
File metadata
- Download URL: nigeriabulksms_sdk-1.0.0-py3-none-any.whl
- Upload date:
- Size: 10.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a4ad224cba77a05a1c671e5d075552506beb3ba81725aab0d04975051372afdf
|
|
| MD5 |
f6c3830018353b3d7019fc1c59427846
|
|
| BLAKE2b-256 |
b87946ae43abc68305ab66188c049d5925fee2c143960b5886e8a08fb48694f0
|