This is the Python client library for Nexmo's API. To use it you'll need a Nexmo account. Sign up for free at nexmo.com.
To install the Python client library using pip:
pip install nexmo
Alternatively you can clone the repository:
git clone git@github.com:Nexmo/nexmo-python.git
Specify your credentials using the NEXMO_API_KEY and NEXMO_API_SECRET
environment variables; import the nexmo package; and construct a client object.
For example:
import nexmo
client = nexmo.Client()Alternatively you can specify your credentials directly using the key
and secret keyword args:
import nexmo
client = nexmo.Client(key='YOUR-API-KEY', secret='YOUR-API-SECRET')To use Nexmo's SMS API to send an SMS message, call the send_message method with a dictionary containing the API parameters. For example:
response = client.send_message({'from': 'Python', 'to': 'YOUR-NUMBER', 'text': 'Hello world'})
response = response['messages'][0]
if response['status'] == '0':
print 'Sent message', response['message-id']
print 'Remaining balance is', response['remaining-balance']
else:
print 'Error:', response['error-text']You can retrieve a message log from the API using the ID of the message:
message = client.get_message('02000000DA7C52E7')
print 'The body of the message was:', message['body']Nexmo's Verify API makes it easy to prove that a user has provided their own phone number during signup, or implement second factor authentication during signin.
You can start the verification process by calling the start_verification method:
response = client.start_verification(number='441632960960', brand='MyApp')
if response['status'] == '0':
print 'Started verification request_id=' + response['request_id']
else:
print 'Error:', response['error_text']The response contains a verification request id which you will need to store temporarily (in the session, database, url etc).
Call the cancel_verification method with the verification request id to cancel an in-progress verification:
client.cancel_verification('00e6c3377e5348cdaf567e1417c707a5')Call the trigger_next_verification_event method with the verification request id to trigger the next attempt to send the confirmation code:
client.trigger_next_verification_event('00e6c3377e5348cdaf567e1417c707a5')The verification request id comes from the call to the start_verification method.
Call the check_verification method with the verification request id and the PIN code to complete the verification process:
response = client.check_verification('00e6c3377e5348cdaf567e1417c707a5', code='1234')
if response['status'] == '0':
print 'Verification complete, event_id=' + response['event_id']
else:
print 'Error:', response['error_text']The verification request id comes from the call to the start_verification method. The PIN code is entered into your application by the user.
Use Nexmo's Call API to initiate an outbound voice call by calling the initiate_call method with the number to call and the URL to a VoiceXML resource for controlling the call:
response = client.initiate_call(to='447525856424', answer_url='http://example.com/call.xml')
if response['status'] == '0':
print 'Started call', response['call-id']
else:
print 'Error:', response['error-text']- Account
- Balance
- Pricing
- Settings
- Top Up
- Numbers
- Search
- Buy
- Cancel
- Update
- Number Insight
- Basic
- Standard
- Advanced
- Webhook Notification
- Verify
- Verify
- Check
- Search
- Control
- Messaging
- Send
- Delivery Receipt
- Inbound Messages
- Search
- Message
- Messages
- Rejections
- US Short Codes
- Two-Factor Authentication
- Event Based Alerts
- Sending Alerts
- Campaign Subscription Management
- Voice
- Outbound Calls
- Inbound Call
- Text-To-Speech Call
- Text-To-Speech Prompt
This library is released under the MIT License