A Python wrapper for the Nexmo API.
$ pip install -e git+https://github.com/marcuz/libpynexmo.git#egg=nexmomessage
First you need to load up the package and construct a dictionary with your API credentials and message, like this:
from nexmomessage import NexmoMessage
msg = {
'reqtype': 'json',
'api_key': YOUR_API_KEY,
'api_secret': YOUR_API_SECRET_KEY,
'from': YOUR_PHONE_NUMBER,
'to': DESTINATION_PHONE_NUMBER,
'text': 'Hello world!'
}
sms = NexmoMessage(msg)
sms.set_text_info(msg['text'])
Then you have a choice. For a "fire and forget" approach to sending a message,
use the send_message
method, like this:
sms.send_request()
This method call returns the message data if the message was sent successfully, or raises an exception if there was an error.
response = sms.send_request()
if response:
# do something with response data
else:
# handle the error
Remember that phone numbers should be specified in international format.
The Nexmo documentation contains a list of error codes which may be useful if you have problems sending a message.
Please report all bugs/issues via the GitHub issue tracker.