/libpynexmo

Python library to interact with Nexmo SMS API

Primary LanguagePythonBSD 2-Clause "Simplified" LicenseBSD-2-Clause

nexmomessage

A Python wrapper for the Nexmo API.

Installation

$ pip install -e git+https://github.com/marcuz/libpynexmo.git#egg=nexmomessage

Quick start (sending a message)

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

Troubleshooting

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.