Plivo
raw JSON → 4.59.6 verified Tue May 12 auth: no python install: verified quickstart: verified
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.
pip install plivo Common errors
error AttributeError: module 'plivo' has no attribute 'RestAPI' ↓
cause This error occurs when using code written for the legacy Plivo Python SDK (version 0.11.3) with the current SDK (version 4.x.x or later). The class name changed from `plivo.RestAPI` to `plivo.RestClient`.
fix
Update your code to use
plivo.RestClient. If you have the legacy version installed, you might need to uninstall it first (pip uninstall plivo) and then install the current version (pip install plivo).
import plivo
# Old (will cause error)
# client = plivo.RestAPI(auth_id='YOUR_AUTH_ID', auth_token='YOUR_AUTH_TOKEN')
# New (correct)
client = plivo.RestClient(auth_id='YOUR_AUTH_ID', auth_token='YOUR_AUTH_TOKEN') error AttributeError: 'Client' object has no attribute 'send_message' ↓
cause This error indicates that you are trying to call a method like `send_message` directly on the `RestClient` object, which is not how message sending is handled in the current Plivo Python SDK. The API for sending messages changed.
fix
In the current Plivo SDK, message sending is done via the
messages resource. You should use client.messages.create().
import plivo
client = plivo.RestClient(auth_id='YOUR_AUTH_ID', auth_token='YOUR_AUTH_TOKEN')
# Old (will cause error)
# response = client.send_message(
# src='YOUR_PLIVO_NUMBER',
# dst='RECIPIENT_NUMBER',
# text='Hello from Plivo!'
# )
# New (correct)
response = client.messages.create(
src='YOUR_PLIVO_NUMBER',
dst='RECIPIENT_NUMBER',
text='Hello from Plivo!'
)
print(response) error ModuleNotFoundError: No module named 'plivo' ↓
cause This error means that the Python interpreter cannot find the 'plivo' library. This typically happens if the library is not installed, installed in a different Python environment, or if there's a naming conflict (e.g., a local file named `plivo.py`).
fix
Ensure the Plivo Python SDK is installed in your active Python environment. If it's already installed but you're still seeing the error, check your environment or ensure there isn't a local file shadowing the
plivo package.
pip install plivo
# If you suspect an issue with a legacy installation, try uninstalling first:
pip uninstall plivo
pip install plivo error plivo.exceptions.PlivoAPIError: status_code=401, message=Invalid Auth ID or Auth Token ↓
cause This error occurs when the Plivo API credentials (Auth ID and Auth Token) provided to the `RestClient` are incorrect, expired, or do not have the necessary permissions.
fix
Verify that your
AUTH_ID and AUTH_TOKEN are correct and active. You can find your credentials on your Plivo Console Dashboard. Ensure there are no typos or leading/trailing spaces.
import plivo
# Replace with your actual Auth ID and Auth Token from the Plivo Console
AUTH_ID = 'YOUR_CORRECT_AUTH_ID'
AUTH_TOKEN = 'YOUR_CORRECT_AUTH_TOKEN'
client = plivo.RestClient(auth_id=AUTH_ID, auth_token=AUTH_TOKEN)
# Attempt an API call to test credentials
try:
response = client.messages.create(
src='YOUR_PLIVO_NUMBER',
dst='RECIPIENT_NUMBER',
text='Test message'
)
print(response)
except plivo.exceptions.PlivoAPIError as e:
print(f"Plivo API Error: {e}") 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. ↓
fix Uninstall first: pip uninstall plivo, then pip install plivo. Rewrite all code from plivo.RestAPI pattern to plivo.RestClient pattern — they are not compatible.
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'. ↓
fix Always use E.164 format: '+' + country_code + local_number. Example: +12025551234 for a US number, +919876543210 for an Indian number.
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. ↓
fix The answer_url endpoint must return Plivo XML with Content-Type: application/xml. Use plivoxml.ResponseElement() to generate the response.
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. ↓
fix Purchase a Plivo number at console.plivo.com. The src parameter must match a number in your Plivo account.
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(). ↓
fix Use offset parameter: client.messages.list(limit=20, offset=20) for page 2. Or iterate manually while response has results.
breaking The Plivo Python SDK requires authentication credentials (PLIVO_AUTH_ID and PLIVO_AUTH_TOKEN) to be set. These are typically read from environment variables or passed directly to the Plivo.RestClient() constructor. Failure to provide them will result in an AuthenticationError. ↓
fix Set the PLIVO_AUTH_ID and PLIVO_AUTH_TOKEN environment variables before running your script. Alternatively, pass auth_id and auth_token directly to the Plivo.RestClient() constructor: client = plivo.RestClient(auth_id='YOUR_AUTH_ID', auth_token='YOUR_AUTH_TOKEN').
breaking The Plivo Python SDK failed to find authentication credentials. It attempts to read PLIVO_AUTH_ID and PLIVO_AUTH_TOKEN from environment variables by default, or they must be passed explicitly to plivo.RestClient(). Failure to provide these results in plivo.exceptions.AuthenticationError and `KeyError: 'PLIVO_AUTH_ID'` or `'PLIVO_AUTH_TOKEN'`. ↓
fix Ensure PLIVO_AUTH_ID and PLIVO_AUTH_TOKEN environment variables are set before running the application, or initialize the client with `client = plivo.RestClient(auth_id='YOUR_AUTH_ID', auth_token='YOUR_AUTH_TOKEN')`.
Install
pip uninstall plivo && pip install plivo Install compatibility verified last tested: 2026-05-12
python os / libc status wheel install import disk
3.10 alpine (musl) - - 0.77s 35.0M
3.10 slim (glibc) - - 0.56s 35M
3.11 alpine (musl) - - 1.00s 37.0M
3.11 slim (glibc) - - 0.84s 37M
3.12 alpine (musl) - - 0.91s 28.8M
3.12 slim (glibc) - - 0.86s 29M
3.13 alpine (musl) - - 0.87s 28.6M
3.13 slim (glibc) - - 0.87s 29M
3.9 alpine (musl) - - 0.72s 34.2M
3.9 slim (glibc) - - 0.61s 35M
Imports
- RestClient wrong
import plivo # Legacy 0.11.3 API — fails on 4.x p = plivo.RestAPI(auth_id='YOUR_AUTH_ID', auth_token='YOUR_AUTH_TOKEN') params = {'src': '+12025551234', 'dst': '+14155551234', 'text': 'Hello'} response = p.send_message(params)correctimport 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 wrong
# Old XML generation pattern from legacy docs from plivo import xml response = xml.PlivoResponse() # AttributeError — xml module renamed to plivoxml in 4.xcorrectfrom plivo import plivoxml response = plivoxml.ResponseElement() response.add(plivoxml.SpeakElement('Hello, welcome to Plivo!')) print(response.to_string())
Quickstart verified last tested: 2026-04-23
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())