Plivo
Python SDK for Plivo communications API — SMS, voice calls, WhatsApp, and Plivo XML generation. Current version is 4.59.6. Legacy version 0.11.3 has a completely different API (plivo.RestAPI vs plivo.RestClient). pip install --upgrade plivo may NOT cleanly upgrade from legacy — manual uninstall required.
Warnings
- breaking Legacy 0.11.3 (plivo.RestAPI) and current 4.x (plivo.RestClient) are completely different APIs. pip install --upgrade plivo from 0.11.3 may fail silently or leave a broken installation. All old code using RestAPI, send_message(), dict-based params will raise AttributeError on 4.x.
- breaking Phone numbers must be in E.164 format (+country_code + number). Passing numbers without the + prefix causes API errors. Common mistake: passing '12025551234' instead of '+12025551234'.
- gotcha calls.create() requires an answer_url that returns valid Plivo XML (ResponseElement). Passing an answer_url that returns JSON or empty response causes the call to fail silently after connecting.
- gotcha The src number for SMS must be a Plivo-owned number in your account, not your personal number. Sending from an unverified or unowned number returns a 400 error.
- gotcha client.messages.list() returns max 20 results by default. For pagination, use limit and offset parameters explicitly. There is no automatic pagination built into list().
Install
-
pip install plivo -
pip uninstall plivo && pip install plivo
Imports
- RestClient
import plivo # Credentials from environment variables (recommended) client = plivo.RestClient() # Or explicit client = plivo.RestClient(auth_id='YOUR_AUTH_ID', auth_token='YOUR_AUTH_TOKEN') # Send SMS response = client.messages.create( src='+12025551234', dst='+14155551234', text='Hello from Plivo!' ) - plivoxml
from plivo import plivoxml response = plivoxml.ResponseElement() response.add(plivoxml.SpeakElement('Hello, welcome to Plivo!')) print(response.to_string())
Quickstart
import plivo
import os
# Use env vars: PLIVO_AUTH_ID and PLIVO_AUTH_TOKEN
client = plivo.RestClient()
# Send SMS
sms = client.messages.create(
src='+12025551234', # Your Plivo number in E.164 format
dst='+14155551234', # Destination in E.164 format
text='Hello from Plivo!'
)
print('SMS sent:', sms)
# Make a call
call = client.calls.create(
from_='+12025551234',
to_='+14155551234',
answer_url='https://yourapp.com/answer_url' # Returns Plivo XML
)
print('Call made:', call)
# Generate Plivo XML (for answer_url endpoint)
from plivo import plivoxml
xml = plivoxml.ResponseElement()
xml.add(plivoxml.SpeakElement('Hello! This call is powered by Plivo.'))
print(xml.to_string())