Upgrade from Python SDK Legacy to v4.9.0 or Latest Version

Introduction

This is a major application update. Plivo recommends you always use the latest or an active version of our SDKs for guaranteed security, stability, and uptime. The active SDK versions are designed to handle intermittent and regional failures of API requests. In addition, they offer a host of security features, such as protection against DoS attacks and bot detection for suspicious user agents.

Deprecation notice: We’re deprecating Plivo Python SDK legacy versions lower than v4.9.0 on January 31, 2022. If you use a deprecated version of our SDK after that date, your API requests and messaging may fail intermittently. Plivo will no longer provide bug fixes to these versions, and our support team may ask you to upgrade before debugging issues.

Migrate your applications

Python version support

Version 4.x of the Python SDK requires at least Python version 2.7. It will work with later versions, including Python 3.x versions.

Use the command pip install --upgrade plivo==4.9.0 to upgrade to the active version of the SDK, or pip install --upgrade plivo to upgrade to the latest version.

After you upgrade to the latest version of the SDK, you should check every program that depends on it and make changes to the syntax for several kinds of operations. Here are examples of how coding differs between the deprecated legacy version of the SDK and the latest active versions.

Import the SDK

Legacy Latest
import plivo, plivoxml
   
import plivo
from plivo import plivoxml
   

Initialize

Legacy Latest
p = plivo.RestAPI('<auth_id>','<auth_token>')
   
client = plivo.RestClient('<auth_id>','<auth_token>')
   

Access resources

Legacy Latest
response = p.send_message(params)
   
response = client.messages.create(params)
   

Send a message

Legacy Latest
import plivo

auth_id = "<auth_id>"
auth_token = "<auth_token>"

p = plivo.RestAPI(auth_id, auth_token)

params = {
    "src": "+12025551212",
    "dst": "+12025552323",
    "text": "Hello, this is a sample text",
    "url": "https://<yourdomain>.com/sms_status/",
}

response = p.send_message(params)

print str(response)
   
import plivo

client = plivo.RestClient("<auth_id>", "<auth_token>")
response = client.messages.create(
    src="+12025551212",
    dst="+12025552323",
    text="Hello, this is a sample text",
    url="https://<yourdomain>.com/sms_status/",
)
print(response)
   

Retrieve a message

Legacy Latest
import plivo

auth_id = "<auth_id>"
auth_token = "<auth_token>"
p = plivo.RestAPI(auth_id, auth_token)
params = {"message_uuid": "<your_message_uuid>"}

response = p.get_message(params)

print str(response)
   
import plivo

client = plivo.RestClient("<auth_id>", "<auth_token>")
response = client.messages.get(message_uuid="<your_message_uuid>")
print(response)
   

List all messages

Legacy Latest
import plivo

auth_id = "<auth_id>"
auth_token = "<auth_token>"
p = plivo.RestAPI(auth_id, auth_token)

response = p.get_messages()

print str(response)

params = {
    "limit": "5",
    "offset": "0",
}

response = p.get_messages(params)
print str(response)
   
import plivo

client = plivo.RestClient("<auth_id>", "<auth_token>")
response = client.messages.list(
    limit=5,
    offset=0,
)
print(response)