Official Africa's Talking Python SDK
Maintained. Last release 4 months ago, commits in 1 of the last 26 weeks. Weaker on commit activity and release cadence.
pip install africastalkingafricastalking-python
The SDK provides convenient access to the Africa's Talking APIs to python apps.
Documentation
Take a look at the API docs here.
Install
$ pip3 install africastalking # python 3.8.x
OR
$ python3 -m pip install africastalking # python 3.8.x
Usage
The package needs to be configured with your app username and API key, which you can get from the dashboard. Note that all functions accept an optional timeout argument, but have a set default.
You can use this SDK for either production or sandbox apps. For sandbox, the app username is ALWAYS
sandbox
# import package
import africastalking
# Initialize SDK
username = "YOUR_USERNAME" # use 'sandbox' for development in the test environment
api_key = "YOUR_API_KEY" # use your sandbox app API key for development in the test environment
africastalking.initialize(username, api_key)
# Initialize a service e.g. SMS
sms = africastalking.SMS
# Use the service synchronously
response = sms.send("Hello Message!", ["+2547xxxxxx"])
print(response)
# Or use it asynchronously
def on_finish(error, response):
if error is not None:
raise error
print(response)
sms.send("Hello Message!", ["+2547xxxxxx"], callback=on_finish, timeout=(3, 6))
See example for more usage examples.
Initialization
Initialize the SDK by calling africastalking.initialize(username, api_key). After initialization, you can get instances of offered services as follows:
- SMS:
africastalking.SMS - Airtime:
africastalking.Airtime - Voice:
africastalking.Voice - Token:
africastalking.Token - Application:
africastalking.Application