• Stars
    star
    193
  • Rank 201,081 (Top 4 %)
  • Language
    Python
  • License
    Apache License 2.0
  • Created over 9 years ago
  • Updated about 1 month ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Vonage Server SDK for Python. API support for Voice, SMS, WhatsApp, Verify (2FA), Video Meetings and more.

Vonage Server SDK for Python

Nexmo is now known as Vonage

PyPI version Build Status Python versions supported Code style: black

This is the Python server SDK for Vonage's API. To use it you'll need a Vonage account. Sign up for free at vonage.com.

Installation

To install the Python client library using pip:

pip install vonage

To upgrade your installed client library using pip:

pip install vonage --upgrade

Alternatively, you can clone the repository via the command line:

git clone [email protected]:Vonage/vonage-python-sdk.git

or by opening it on GitHub desktop.

Usage

Begin by importing the vonage module:

import vonage

Then construct a client object with your key and secret:

client = vonage.Client(key=api_key, secret=api_secret)

For production, you can specify the VONAGE_API_KEY and VONAGE_API_SECRET environment variables instead of specifying the key and secret explicitly.

For newer endpoints that support JWT authentication such as the Voice API, you can also specify the application_id and private_key arguments:

client = vonage.Client(application_id=application_id, private_key=private_key)

To check signatures for incoming webhook requests, you'll also need to specify the signature_secret argument (or the VONAGE_SIGNATURE_SECRET environment variable).

To use the SDK to call Vonage APIs, pass in dicts with the required options to methods like Sms.send_message(). Examples of this are given below.

Simplified structure for calling API Methods

The client now instantiates a class object for each API when it is created, e.g. vonage.Client(key="mykey", secret="mysecret") instantiates instances of Account, Sms, NumberInsight etc. These instances can now be called directly from Client, e.g.

client = vonage.Client(key="mykey", secret="mysecret")

print(f"Account balance is: {client.account.get_balance()}")

print("Sending an SMS")
client.sms.send_message({
    "from": "Vonage",
    "to": "SOME_PHONE_NUMBER",
    "text": "Hello from Vonage's SMS API"
})

This means you don't have to create a separate instance of each class to use its API methods. Instead, you can access class methods from the client instance with

client.CLASS_NAME.CLASS_METHOD

SMS API

Although the Messages API adds more messaging channels, the SMS API is still supported.

Send an SMS

# New way
client = vonage.Client(key=VONAGE_API_KEY, secret=VONAGE_API_SECRET)
client.sms.send_message({
    "from": VONAGE_BRAND_NAME,
    "to": TO_NUMBER,
    "text": "A text message sent using the Vonage SMS API",
})

# Old way
from vonage import Sms
sms = Sms(key=VONAGE_API_KEY, secret=VONAGE_API_SECRET)
sms.send_message({
            "from": VONAGE_BRAND_NAME,
            "to": TO_NUMBER,
            "text": "A text message sent using the Vonage SMS API",
})

Send SMS with unicode

client = vonage.Client(key=VONAGE_API_KEY, secret=VONAGE_API_SECRET)
client.sms.send_message({
    'from': VONAGE_BRAND_NAME,
    'to': TO_NUMBER,
    'text': 'γ“γ‚“γ«γ‘γ―δΈ–η•Œ',
    'type': 'unicode',
})

Submit SMS Conversion

client = vonage.Client(key=VONAGE_API_KEY, secret=VONAGE_SECRET)
response = client.sms.send_message({
    'from': VONAGE_BRAND_NAME,
    'to': TO_NUMBER,
    'text': 'Hi from Vonage'
})
client.sms.submit_sms_conversion(response['message-id'])

Update the default SMS webhook URLs for callbacks/delivery reciepts

client.sms.update_default_sms_webhook({
    'moCallBackUrl': 'new.url.vonage.com',      # Default inbound sms webhook url
    'drCallBackUrl': 'different.url.vonage.com' # Delivery receipt url
    }})

The delivery receipt URL can be unset by sending an empty string.

Messages API

The Messages API is an API that allows you to send messages via SMS, MMS, WhatsApp, Messenger and Viber. Call the API from your Python code by passing a dict of parameters into the client.messages.send_message() method.

It accepts JWT or API key/secret authentication.

Some basic samples are below. For more detailed information and code snippets, please visit the Vonage Developer Documentation.

Send an SMS

responseData = client.messages.send_message({
        'channel': 'sms', 
        'message_type': 'text', 
        'to': '447123456789', 
        'from': 'Vonage',
        'text': 'Hello from Vonage'
    })

Send an MMS

Note: only available in the US. You will need a 10DLC number to send an MMS message.

client.messages.send_message({
        'channel': 'mms', 
        'message_type': 'image', 
        'to': '11112223333', 
        'from': '1223345567',
        'image': {'url': 'https://example.com/image.jpg', 'caption': 'Test Image'}
    })

Send an audio file via WhatsApp

You will need a WhatsApp Business Account to use WhatsApp messaging. WhatsApp restrictions mean that you must send a template message to a user if they have not previously messaged you, but you can send any message type to a user if they have messaged your business number in the last 24 hours.

client.messages.send_message({
        'channel': 'whatsapp', 
        'message_type': 'audio', 
        'to': '447123456789', 
        'from': '440123456789',
        'audio': {'url': 'https://example.com/audio.mp3'}
    })

Send a video file via Facebook Messenger

You will need to link your Facebook business page to your Vonage account in the Vonage developer dashboard. (Click on the sidebar "External Accounts" option to do this.)

client.messages.send_message({
        'channel': 'messenger', 
        'message_type': 'video', 
        'to': '594123123123123', 
        'from': '1012312312312',
        'video': {'url': 'https://example.com/video.mp4'}
    })

Send a text message with Viber

client.messages.send_message({
    'channel': 'viber_service',
    'message_type': 'text',
    'to': '447123456789',
    'from': '440123456789',
    'text': 'Hello from Vonage!'
})

Voice API

Make a call

client = vonage.Client(application_id=APPLICATION_ID, private_key=PRIVATE_KEY)
client.voice.create_call({
  'to': [{'type': 'phone', 'number': '14843331234'}],
  'from': {'type': 'phone', 'number': '14843335555'},
  'answer_url': ['https://example.com/answer']
})

Retrieve a list of calls

client = vonage.Client(application_id=APPLICATION_ID, private_key=PRIVATE_KEY)
client.voice.get_calls()

Retrieve a single call

client = vonage.Client(application_id=APPLICATION_ID, private_key=PRIVATE_KEY)
client.voice.get_call(uuid)

Update a call

client = vonage.Client(application_id=APPLICATION_ID, private_key=PRIVATE_KEY)
response = client.voice.create_call({
  'to': [{'type': 'phone', 'number': '14843331234'}],
  'from': {'type': 'phone', 'number': '14843335555'},
  'answer_url': ['https://example.com/answer']
})
client.voice.update_call(response['uuid'], action='hangup')

Stream audio to a call

client = vonage.Client(application_id=APPLICATION_ID, private_key=PRIVATE_KEY)
stream_url = 'https://nexmo-community.github.io/ncco-examples/assets/voice_api_audio_streaming.mp3'
response = client.voice.create_call({
  'to': [{'type': 'phone', 'number': '14843331234'}],
  'from': {'type': 'phone', 'number': '14843335555'},
  'answer_url': ['https://example.com/answer']
})
client.voice.send_audio(response['uuid'],stream_url=[stream_url])

Stop streaming audio to a call

client = vonage.Client(application_id='0d4884d1-eae8-4f18-a46a-6fb14d5fdaa6', private_key='./private.key')
stream_url = 'https://nexmo-community.github.io/ncco-examples/assets/voice_api_audio_streaming.mp3'
response = client.voice.create_call({
  'to': [{'type': 'phone', 'number': '14843331234'}],
  'from': {'type': 'phone', 'number': '14843335555'},
  'answer_url': ['https://example.com/answer']
})
client.voice.send_audio(response['uuid'],stream_url=[stream_url])
client.voice.stop_audio(response['uuid'])

Send a synthesized speech message to a call

client = vonage.Client(application_id=APPLICATION_ID, private_key=PRIVATE_KEY)
response = client.voice.create_call({
  'to': [{'type': 'phone', 'number': '14843331234'}],
  'from': {'type': 'phone', 'number': '14843335555'},
  'answer_url': ['https://example.com/answer']
})
client.voice.send_speech(response['uuid'], text='Hello from vonage')

Stop sending a synthesized speech message to a call

client = vonage.Client(application_id=APPLICATION_ID, private_key=APPLICATION_ID)
response = client.voice.create_call({
  'to': [{'type': 'phone', 'number': '14843331234'}],
  'from': {'type': 'phone', 'number': '14843335555'},
  'answer_url': ['https://example.com/answer']
})
client.voice.send_speech(response['uuid'], text='Hello from vonage')
client.voice.stop_speech(response['uuid'])

Send DTMF tones to a call

client = vonage.Client(application_id=APPLICATION_ID, private_key=PRIVATE_KEY)
response = client.voice.create_call({
  'to': [{'type': 'phone', 'number': '14843331234'}],
  'from': {'type': 'phone', 'number': '14843335555'},
  'answer_url': ['https://example.com/answer']
})
client.voice.send_dtmf(response['uuid'], digits='1234')

Get recording

response = client.get_recording(RECORDING_URL)

NCCO Builder

The SDK contains a builder to help you create Call Control Objects (NCCOs) for use with the Vonage Voice API.

For more information, check the full NCCO reference documentation on the Vonage website.

An NCCO is a list of "Actions": steps to be followed when a call is initiated or received.

Use the builder to construct valid NCCO actions, which are modelled in the SDK as Pydantic models, and build them into an NCCO. The NCCO actions supported by the builder are:

  • Record
  • Conversation
  • Connect
  • Talk
  • Stream
  • Input
  • Notify

Construct actions

record = Ncco.Record(eventUrl=['https://example.com'])
talk = Ncco.Talk(text='Hello from Vonage!', bargeIn=True, loop=5, premium=True)

The Connect action has each valid endpoint type (phone, application, WebSocket, SIP and VBC) specified as a Pydantic model so these can be validated, though it is also possible to pass in a dict with the endpoint properties directly into the Ncco.Connect object.

This example shows a Connect action created with an endpoint object.

phone = ConnectEndpoints.PhoneEndpoint(
        number='447000000000',
        dtmfAnswer='1p2p3p#**903#',
    )
connect = Ncco.Connect(endpoint=phone, eventUrl=['https://example.com/events'], from_='447000000000')

This example shows a different Connect action, created with a dictionary.

connect = Ncco.Connect(endpoint={'type': 'phone', 'number': '447000000000', 'dtmfAnswer': '2p02p'}, randomFromNumber=True)

Build into an NCCO

Create an NCCO from the actions with the Ncco.build_ncco method. This will be returned as a list of dicts representing each action and can be used in calls to the Voice API.

ncco = Ncco.build_ncco(record, connect, talk)

response = client.voice.create_call({
    'to': [{'type': 'phone', 'number': TO_NUMBER}],
    'from': {'type': 'phone', 'number': VONAGE_NUMBER},
    'ncco': ncco
})

pprint(response)

Note on from_ parameter in connect action

When using the connect action, use the parameter from_ to specify the recipient (as from is a reserved keyword in Python!)

Verify V2 API

V2 of the Vonage Verify API lets you send verification codes via SMS, WhatsApp, Voice and Email.

You can also verify a user by WhatsApp Interactive Message or by Silent Authentication on their mobile device.

Send a verification code

params = {
    'brand': 'ACME, Inc', 
    'workflow': [{'channel': 'sms', 'to': '447700900000'}]
}
verify_request = verify2.new_request(params)

Use silent authentication, with email as a fallback

params = {
    'brand': 'ACME, Inc', 
    'workflow': [
        {'channel': 'silent_auth', 'to': '447700900000'},
        {'channel': 'email', 'to': '[email protected]', 'from': '[email protected]'}
    ]
}
verify_request = verify2.new_request(params)

Send a verification code with custom options, including a custom code

params = {
    'locale': 'en-gb',
    'channel_timeout': 120,
    'client_ref': 'my client reference',
    'code': 'asdf1234',
    'brand': 'ACME, Inc',
    'workflow': [{'channel': 'sms', 'to': '447700900000', 'app_hash': 'asdfghjklqw'}],
}
verify_request = verify2.new_request(params)

Send a verification request to a blocked network

This feature is only enabled if you have requested for it to be added to your account.

params = {
    'brand': 'ACME, Inc', 
    'fraud_check': False, 
    'workflow': [{'channel': 'sms', 'to': '447700900000'}]
}
verify_request = verify2.new_request(params)

Check a verification code

verify2.check_code(REQUEST_ID, CODE)

Cancel an ongoing verification

verify2.cancel_verification(REQUEST_ID)

Verify V1 API

Search for a Verification request

client = vonage.Client(key='API_KEY', secret='API_SECRET')

response = client.verify.search('69e2626cbc23451fbbc02f627a959677')

if response is not None:
    print(response['status'])

Send verification code

client = vonage.Client(key='API_KEY', secret='API_SECRET')

response = client.verify.start_verification(number=RECIPIENT_NUMBER, brand='AcmeInc')

if response["status"] == "0":
    print("Started verification request_id is %s" % (response["request_id"]))
else:
    print("Error: %s" % response["error_text"])

Send verification code with workflow

client = vonage.Client(key='API_KEY', secret='API_SECRET')

response = client.verify.start_verification(number=RECIPIENT_NUMBER, brand='AcmeInc', workflow_id=1)

if response["status"] == "0":
    print("Started verification request_id is %s" % (response["request_id"]))
else:
    print("Error: %s" % response["error_text"])

Check verification code

client = vonage.Client(key='API_KEY', secret='API_SECRET')

response = client.verify.check(REQUEST_ID, code=CODE)

if response["status"] == "0":
    print("Verification successful, event_id is %s" % (response["event_id"]))
else:
    print("Error: %s" % response["error_text"])

Cancel Verification Request

client = vonage.Client(key='API_KEY', secret='API_SECRET')

response = client.verify.cancel(REQUEST_ID)

if response["status"] == "0":
    print("Cancellation successful")
else:
    print("Error: %s" % response["error_text"])

Trigger next verification proccess

client = vonage.Client(key='API_KEY', secret='API_SECRET')

response = client.verify.trigger_next_event(REQUEST_ID)

if response["status"] == "0":
    print("Next verification stage triggered")
else:
    print("Error: %s" % response["error_text"])

Send payment authentication code

client = vonage.Client(key='API_KEY', secret='API_SECRET')

response = client.verify.psd2(number=RECIPIENT_NUMBER, payee=PAYEE, amount=AMOUNT)

if response["status"] == "0":
    print("Started PSD2 verification request_id is %s" % (response["request_id"]))
else:
    print("Error: %s" % response["error_text"])

Send payment authentication code with workflow

client = vonage.Client(key='API_KEY', secret='API_SECRET')

client.verify.psd2(number=RECIPIENT_NUMBER, payee=PAYEE, amount=AMOUNT, workflow_id: WORKFLOW_ID)

if response["status"] == "0":
    print("Started PSD2 verification request_id is %s" % (response["request_id"]))
else:
    print("Error: %s" % response["error_text"])

Meetings API

Full docs for the Meetings API are available here.

Create a meeting room

# Instant room
params = {'display_name': 'my_test_room'}
meeting = client.meetings.create_room(params)

# Long term room
params = {'display_name': 'test_long_term_room', 'type': 'long_term', 'expires_at': '2023-01-30T00:47:04+0000'}
meeting = client.meetings.create_room(params)

Get all meeting rooms

client.meetings.list_rooms()

Get a room by id

client.meetings.get_room('MY_ROOM_ID')

Update a long term room

params = {
    'update_details': {
        "available_features": {
            "is_recording_available": False,
            "is_chat_available": False,
        }
    }
}
meeting = client.meetings.update_room('MY_ROOM_ID', params)

Get all recordings for a session

session = client.meetings.get_session_recordings('MY_SESSION_ID')

Get a recording by id

recording = client.meetings.get_recording('MY_RECORDING_ID')

Delete a recording

client.meetings.delete_recording('MY_RECORDING_ID')

List dial-in numbers

numbers = client.meetings.list_dial_in_numbers()

Create a theme

params = {
    'theme_name': 'my_theme',
    'main_color': '#12f64e',
    'brand_text': 'My Company',
    'short_company_url': 'my-company',
}
theme = client.meetings.create_theme(params)

Add a theme to a room

meetings.add_theme_to_room('MY_ROOM_ID', 'MY_THEME_ID')

List themes

themes = client.meetings.list_themes()

Get theme information

theme = client.meetings.get_theme('MY_THEME_ID')

Delete a theme

client.meetings.delete_theme('MY_THEME_ID')

Update a theme

params = {
    'update_details': {
        'theme_name': 'updated_theme',
        'main_color': '#FF0000',
        'brand_text': 'My Updated Company Name',
        'short_company_url': 'updated_company_url',
    }
}
theme = client.meetings.update_theme('MY_THEME_ID', params)

List all rooms using a specified theme

rooms = client.meetings.list_rooms_with_theme_id('MY_THEME_ID')

Update the default theme for your application

response = client.meetings.update_application_theme('MY_THEME_ID')

Upload a logo to a theme

response = client.meetings.upload_logo_to_theme(
        theme_id='MY_THEME_ID',
        path_to_image='path/to/my/image.png',
        logo_type='white', # 'white', 'colored' or 'favicon'
    )

Number Insight API

Basic Number Insight

client.number_insight.get_basic_number_insight(number='447700900000')

Docs: https://developer.nexmo.com/api/number-insight#getNumberInsightBasic

Standard Number Insight

client.number_insight.get_standard_number_insight(number='447700900000')

Docs: https://developer.nexmo.com/api/number-insight#getNumberInsightStandard

Advanced Number Insight

client.number_insight.get_advanced_number_insight(number='447700900000')

Docs: https://developer.nexmo.com/api/number-insight#getNumberInsightAdvanced

Proactive Connect API

Full documentation for the Proactive Connect API is available here.

These methods help you manage lists of contacts when using the API:

Find all lists

client.proactive_connect.list_all_lists()

Create a list

Lists can be created manually or imported from Salesforce.

params = {'name': 'my list', 'description': 'my description', 'tags': ['vip']}
client.proactive_connect.create_list(params)

Get a list

client.proactive_connect.get_list(LIST_ID)

Update a list

params = {'name': 'my list', 'tags': ['sport', 'football']}
client.proactive_connect.update_list(LIST_ID, params)

Delete a list

client.proactive_connect.delete_list(LIST_ID)

Sync a list from an external datasource

params = {'name': 'my list', 'tags': ['sport', 'football']}
client.proactive_connect.sync_list_from_datasource(LIST_ID)

These methods help you work with individual items in a list:

Find all items in a list

client.proactive_connect.list_all_items(LIST_ID)

Create a new list item

data = {'firstName': 'John', 'lastName': 'Doe', 'phone': '123456789101'}
client.proactive_connect.create_item(LIST_ID, data)

Get a list item

client.proactive_connect.get_item(LIST_ID, ITEM_ID)

Update a list item

data = {'firstName': 'John', 'lastName': 'Doe', 'phone': '447007000000'}
client.proactive_connect.update_item(LIST_ID, ITEM_ID, data)

Delete a list item

client.proactive_connect.delete_item(LIST_ID, ITEM_ID)

Download all items in a list as a .csv file

FILE_PATH = 'path/to/the/downloaded/file/location'
client.proactive_connect.download_list_items(LIST_ID, FILE_PATH)

Upload items from a .csv file into a list

FILE_PATH = 'path/to/the/file/to/upload/location'
client.proactive_connect.upload_list_items(LIST_ID, FILE_PATH)

This method helps you work with events emitted by the Proactive Connect API when in use:

List all events

client.proactive_connect.list_events()

Account API

Get your account balance

client.account.get_balance()

Top up your account

This feature is only enabled when you enable auto-reload for your account in the dashboard.

# trx is the reference from when auto-reload was enabled and money was added
client.account.topup(trx=transaction_reference) 

Subaccounts API

This API is used to create and configure subaccounts related to your primary account and transfer credit, balances and bought numbers between accounts.

The subaccounts API is disabled by default. If you want to use subaccounts, contact support to have the API enabled on your account.

Get a list of all subaccounts

client.subaccounts.list_subaccounts()

Create a subaccount

client.subaccounts.create_subaccount(name='my subaccount')

# With options
client.subaccounts.create_subaccount(
    name='my subaccount', 
    secret='Password123', 
    use_primary_account_balance=False,
)

Get information about a subaccount

client.subaccounts.get_subaccount(SUBACCOUNT_API_KEY)

Modify a subaccount

client.subaccounts.modify_subaccount(
    SUBACCOUNT_KEY,
    suspended=True,
    use_primary_account_balance=False,
    name='my modified subaccount',
)

List credit transfers between accounts

All fields are optional. If start_date or end_date are used, the dates must be specified in UTC ISO 8601 format, e.g. 1970-01-01T00:00:00Z. Don't use milliseconds.

client.subaccounts.list_credit_transfers(
    start_date='2022-03-29T14:16:56Z',
    end_date='2023-06-12T17:20:01Z',
    subaccount=SUBACCOUNT_API_KEY, # Use to show only the results that contain this key 
)

Transfer credit between accounts

Transferring credit is only possible for postpaid accounts, i.e. accounts that can have a negative balance. For prepaid and self-serve customers, account balances can be transferred between accounts (see below).

client.subaccounts.transfer_credit(
    from_=FROM_ACCOUNT, 
    to=TO_ACCOUNT, 
    amount=0.50, 
    reference='test credit transfer',
)

List balance transfers between accounts

All fields are optional. If start_date or end_date are used, the dates must be specified in UTC ISO 8601 format, e.g. 1970-01-01T00:00:00Z. Don't use milliseconds.

client.subaccounts.list_balance_transfers(
    start_date='2022-03-29T14:16:56Z',
    end_date='2023-06-12T17:20:01Z',
    subaccount=SUBACCOUNT_API_KEY, # Use to show only the results that contain this key 
)

Transfer account balances between accounts

client.subaccounts.transfer_balance(
    from_=FROM_ACCOUNT, 
    to=TO_ACCOUNT, 
    amount=0.50, 
    reference='test balance transfer',
)

Transfer bought phone numbers between accounts

client.subaccounts.transfer_balance(
    from_=FROM_ACCOUNT, 
    to=TO_ACCOUNT, 
    number=NUMBER_TO_TRANSFER, 
    country='US',
)

Number Management API

Get numbers associated with your account

client.numbers.get_account_numbers(size=25)

Get numbers that are available to buy

client.numbers.get_available_numbers('CA', size=25)

Buy an available number

params = {'country': 'US', 'msisdn': 'number_to_buy'}
client.numbers.buy_number(params)

# To buy a number for a subaccount
params = {'country': 'US', 'msisdn': 'number_to_buy', 'target_api_key': SUBACCOUNT_API_KEY}
client.numbers.buy_number(params)

Cancel your subscription for a specific number

params = {'country': 'US', 'msisdn': 'number_to_cancel'}
client.numbers.cancel_number(params)

# To cancel a number assigned to a subaccount
params = {'country': 'US', 'msisdn': 'number_to_buy', 'target_api_key': SUBACCOUNT_API_KEY}
client.numbers.cancel_number(params)

Update the behaviour of a number that you own

params = {"country": "US", "msisdn": "number_to_update", "moHttpUrl": "callback_url"}
client.numbers.update_number(params)

Pricing API

Get pricing for a single country

client.account.get_country_pricing(country_code='GB', type='sms') # Default type is sms

Get pricing for all countries

client.account.get_all_countries_pricing(type='sms') # Default type is sms, can be voice

Get pricing for a specific dialling prefix

client.account.get_prefix_pricing(prefix='44', type='sms')

Managing Secrets

An API is provided to allow you to rotate your API secrets. You can create a new secret (up to a maximum of two secrets) and delete the existing one once all applications have been updated.

List Secrets

secrets = client.account.list_secrets(API_KEY)

Get information about a specific secret

secrets = client.account.get_secret(API_KEY, secret_id)

Create A New Secret

Create a new secret (the created dates will help you know which is which):

client.account.create_secret(API_KEY, 'awes0meNewSekret!!;');

Delete A Secret

Delete the old secret (any application still using these credentials will stop working):

client.account.revoke_secret(API_KEY, 'my-secret-id')

Application API

Create an application

response = client.application.create_application({name='Example App', type='voice'})

Docs: https://developer.nexmo.com/api/application.v2#createApplication

Retrieve a list of applications

response = client.application.list_applications()

Docs: https://developer.nexmo.com/api/application.v2#listApplication

Retrieve a single application

response = client.application.get_application(uuid)

Docs: https://developer.nexmo.com/api/application.v2#getApplication

Update an application

response = client.application.update_application(uuid, answer_method='POST')

Docs: https://developer.nexmo.com/api/application.v2#updateApplication

Delete an application

response = client.application.delete_application(uuid)

Docs: https://developer.nexmo.com/api/application.v2#deleteApplication

Validate webhook signatures

client = vonage.Client(signature_secret='secret')

if client.check_signature(request.query):
  # valid signature
else:
  # invalid signature

Docs: https://developer.nexmo.com/concepts/guides/signing-messages

Note: you'll need to contact [email protected] to enable message signing on your account before you can validate webhook signatures.

JWT parameters

By default, the library generates 15-minute tokens for JWT authentication.

Use the auth method of the client class to specify custom parameters:

client.auth(nbf=nbf, exp=exp, jti=jti)
# OR
client.auth({'nbf': nbf, 'exp': exp, 'jti': jti})

Overriding API Attributes

In order to rewrite/get the value of variables used across all the Vonage classes Python uses Call by Object Reference that allows you to create a single client to use with all API classes.

An example using setters/getters with Object references:

from vonage import Client

# Define the client
client = Client(key='YOUR_API_KEY', secret='YOUR_API_SECRET')
print(client.host()) # using getter for host -- value returned: rest.nexmo.com

# Change the value in client
client.host('mio.nexmo.com') # Change host to mio.nexmo.com - this change will be available for sms
client.sms.send_message(params) # Sends an SMS to the host above

Overriding API Host / Host Attributes

These attributes are private in the client class and the only way to access them is using the getters/setters we provide.

from vonage import Client

client = Client(key='YOUR_API_KEY', secret='YOUR_API_SECRET')
print(client.host()) # return rest.nexmo.com
client.host('newhost.vonage.com') # rewrites the host value to newhost.vonage.com
print(client.api_host()) # returns api.vonage.com
client.api_host('myapi.vonage.com') # rewrite the value of api_host to myapi.vonage.com

Frequently Asked Questions

Supported APIs

The following is a list of Vonage APIs and whether the Python SDK provides support for them:

API API Release Status Supported?
Account API General Availability βœ…
Alerts API General Availability βœ…
Application API General Availability βœ…
Audit API Beta ❌
Conversation API Beta ❌
Dispatch API Beta ❌
External Accounts API Beta ❌
Media API Beta ❌
Meetings API General Availability βœ…
Messages API General Availability βœ…
Number Insight API General Availability βœ…
Number Management API General Availability βœ…
Pricing API General Availability βœ…
Redact API Developer Preview ❌
Reports API Beta ❌
SMS API General Availability βœ…
Subaccounts API General Availability βœ…
Verify API General Availability βœ…
Voice API General Availability βœ…

asyncio Support

asyncio is a library to write concurrent code using the async/await syntax.

We don't currently support asyncio in the Python SDK but we are planning to do so in upcoming releases.

Contributing

We ❀️ contributions! But if you plan to work on something big or controversial, please contact us first!

We recommend working on vonage-python-sdk with a virtualenv. The following command will install all the Python dependencies you need to run the tests:

make install

The tests are all written with pytest. You run them with:

make test

License

This library is released under the Apache License.

More Repositories

1

vonage-php-sdk-core

Vonage REST API client for PHP. API support for SMS, Voice, Text-to-Speech, Numbers, Verify (2FA) and more.
PHP
917
star
2

vonage-node-sdk

Vonage API client for Node.js. API support for SMS, Voice, Text-to-Speech, Numbers, Verify (2FA) and more.
TypeScript
382
star
3

vonage-ruby-sdk

Vonage REST API client for Ruby. API support for SMS, Voice, Text-to-Speech, Numbers, Verify (2FA) and more.
Ruby
218
star
4

Grafana_Status_panel

A panel plugin for Grafana to monitor multiple parameters at once
TypeScript
179
star
5

vonage-php-sdk

Wrapper package to bring in the vonage/client-core code and an HTTP client
109
star
6

vonage-dotnet-sdk

Vonage REST API client for .NET, written in C#. API support for SMS, Voice, Text-to-Speech, Numbers, Verify (2FA) and more.
C#
106
star
7

vonage-java-sdk

Vonage Server SDK for Java. API support for SMS, Messages, Voice, Text-to-Speech, Numbers, Verify (2FA), Video and more.
Java
97
star
8

vonage-node-code-snippets

NodeJS code examples for using Vonage
JavaScript
70
star
9

vivid-3

Vonage's web UI 🎨 toolbelt
TypeScript
54
star
10

vonage-go-sdk

A lightweight library to help Go users everywhere integrate with the Vonage APIs. Issues and PRs all really welcome!!
Go
51
star
11

vivid

Vonage's web UI 🎨 toolbelt
JavaScript
42
star
12

rxzu

RxZu Diagrams
TypeScript
41
star
13

vonage-laravel

Laravel Service Provider for integrating Vonage APIs
PHP
34
star
14

vonage-python-code-snippets

Python code examples for using Vonage communications APIs
Python
32
star
15

vonage-php-code-snippets

PHP code examples for using Vonage APIs
PHP
29
star
16

micro-frontends

TypeScript
27
star
17

vonage-curl-code-snippets

Curl examples for working with Vonage APIs
Shell
26
star
18

gosrvlib

Go library to provide base service components
Go
20
star
19

vonage-cli

Vonage CLI tool.
TypeScript
18
star
20

vonage-java-code-snippets

Java code examples for using Vonage
Java
11
star
21

vonage-dotnet-code-snippets

.NET code samples for using Nexmo
C#
11
star
22

kafka-glue

Kafka Glue is a collection of libraries for kafka consumers and producers integrated with AWS Glue schema registry with RXJS to expose streaming of the kafka.
TypeScript
8
star
23

vonage-ruby-code-snippets

Ruby code examples for working with Vonage
Ruby
8
star
24

vbc-developer

Vonage Developer Portal documentation
HTML
6
star
25

vivid-react

Typescript friendly Reactjs :atom: wrappers/bindings for Vonage's web UI 🎨 toolbelt
JavaScript
5
star
26

acl-express

A stateless Access Control List middleware for Express
JavaScript
5
star
27

vonage-go-code-snippets

Repo of "howto" examples for using Vonage APIs with Go.
Go
4
star
28

cloud-runtime-cli

Vonage cloud runtime - CLI
Go
4
star
29

vonage-firebase-extensions

Firebase Extensions created by Vonage
JavaScript
3
star
30

sippy

A mirror of python-sippy b2bua library (and rtp_cluster): http://b2bua.org/
Python
3
star
31

aws-systems-manager-toolkit

aws-systems-manager-toolkit is a Python library that provides wrapper tools around AWS Systems Manager functionality.
Python
3
star
32

verify-silent-auth-sdk-android

This SDK enables making a HTTP request over cellular even when on WiFi.
Kotlin
3
star
33

vonage-media-transformers-samples

Vonage Media Transformers Examples
TypeScript
3
star
34

numkey

Numerical Encoding for Short Codes or E.164 LVN
C
3
star
35

video-express-plus-sample

This Repository demonstrates how to use Vonage Video Express Plus
HTML
2
star
36

vonage-python-jwt

A JWT Generator for Python. Creates JWTs for use with Vonage APIs.
Python
2
star
37

vivid-bindings-vue

Fully automated typescript bindings generated for Vivid web components to be used in VueJS
TypeScript
2
star
38

vivid-react-wrapper

A thin wrapper around an arbitrary custom HTML element to mitigate the gaps in :atom: React versions until 19.x
TypeScript
2
star
39

vonage-client-sdk-ios

Swift
1
star
40

vscode

A Visual Studio Code extension for accessing the Vonage communication APIs.
TypeScript
1
star
41

api-specification

JavaScript
1
star
42

cli-plugin-scaffold

TypeScript
1
star
43

vivid-design-tokens-properties

JavaScript
1
star
44

exprees-socket-server

JavaScript
1
star
45

vonage-jwt-jdk

Library to assist with generating JWT tokens in JVM-based languages for use with the Vonage API.
Kotlin
1
star
46

vonage-kotlin-sdk

Vonage Server SDK for Kotlin. API support for SMS, RCS, Messages, Voice, Text-to-Speech, Numbers, Verify (2FA), Video and more.
Kotlin
1
star