API Documentation¶
We are trying to map the Nexmo API as closely as possible.
Note
Since from
is a reserved keyword in Python, we are using frm
instead.
Nexmo¶
-
class
libnexmo.
Nexmo
(api_key, api_secret)¶ Nexmo low level client.
The class is the main entry point to the library. Once initialized, it provides shortcuts to every feature in the library.
Parameters: - api_key – The Nexmo api key.
- api_secret – The Nexmo api secret.
-
send_request
(url, params, method=u'GET')¶ Sends a raw request to the given api endpoint.
Parameters: - url – A Nexmpo api endpoint (json only)
- params – A parameter dictionnary
Returns a
NexmoResponse
.Raises:
The library uses Requests to perform http requests. Requests exceptions won’t be caught in case of connection error.
Any
NexmoError
subclass.
-
send_sms
(frm, to, text)¶ Sends a simple text message.
Example usage:
>>> msg = "Cherie, n'oublie pas les gauffres !" >>> nexmo.send_sms('+33123456780', '+33987654321', msg)
Parameters: - frm – The from field, a phone number (international format with or without a leading “+” or alphanumerical).
- to – The to field, a phone number, same format as the frm argument.
- text – The message body.
See
send_request()
for return value and exceptions.
Note
Phone number formatting
Nexmo’s api expects phone numbers to be in international format, with the country code at the beginning and no leading “+”.
The library will therefore strip every character that is not a number, so you are free to use whatever format that you want.
Examples:
nexmo.send_sms(frm='33123456789', …)
nexmo.send_sms(frm='+33123456789', …)
nexmo.send_sms(frm='+33.123.456.789', …)
nexmo.send_sms(frm='+331 23 45 67 89', …)
nexmo.send_sms(frm='+331-23-45-67-89', …)
Response¶
-
class
libnexmo.
NexmoResponse
(json_data)¶ A convenient wrapper to manipulate the Nexmo json response.
The class makes it easy to retrieve information about sent messages, total price, etc.
Example:
>>> response = nexmo.send_sms(frm, to, txt) >>> print response.total_price 0.15 >>> print response.remaining_balance 1.00 >>> print response.message_count: 3 >>> for message in response.messages: ... print message.message_id, message.message_price 00000124 0.05 00000125 0.05 00000126 0.05
The class only handles successfull responses, since errors raise exceptions in the
Nexmo
class.