Skip to main content

How to Migrate Your Python SMS Application from Twilio to Plivo

Plivo's SMS API and Voice API enables businesses to communicate with their customers at global scale. Sign up for free now.

December 1, 2021 · By Team Plivo
How to Migrate Your Python SMS Application from Twilio to Plivo

Migrating your Python SMS app from Twilio to Plivo is a seamless and painless process. The two companies’ API structures, implementation mechanisms, XML structure, SMS message processing, and voice call processing are similar. We wrote this technical comparison so that you can scope between Twilio and Plivo APIs for a seamless migration.

Understanding the differences between Twilio and Plivo development

Most of the APIs and features that are available on Twilio are also available on Plivo and the implementation mechanism is easier as the steps involved are almost identical. This table gives a side-side comparison of the two companies’ features and APIs. An added advantage with Plivo is that not only can you code using the old familiar API/XML method, you can also implement your use cases using PHLO (Plivo High Level Objects), a visual workflow builder that lets you create workflows by dragging and dropping components onto a canvas — no coding required.

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               
Features and APIsTwilioPlivoSimilaritiesImplementation Interface
SMS API: Send SMS/MMS messagesRequest and response variables’ structure         API
           PHLO
   
Managed number pool for US/CA MessagingCopilotPowerpackFeature parity         API
           Console
   
Geo PermissionsFeature parityConsole
SMS Sender ID registrationFeature parityConsole
Number Lookup APIAPI ParityAPI
Phone number managementFeature parity         API
           Console
   
Validating RequestsFeature parity         API
           XML
   
SubaccountsFeature parityAPI
HTTP callbacksFeature parity            API
           XML
           PHLO
       

 .highlight pre{    background-color: rgb(33, 33, 48);    border-radius: 0;    padding: 15px 18px 15px 18px;  }  pre.lineno{    color: #fff;    opacity: .3;  }  .w-richtext figure {    max-width: 100%;    position: relative; }  

Plivo offers one unique advantage: Not only can you code using APIs and XML, you can also implement your use cases using PHLO (Plivo High Level Objects), a visual workflow builder that lets you create workflows by dragging and dropping components onto a canvas — no coding required.

Plivo account creation

Start by signing up for a free trial account that you can use to experiment with and learn about our services. The free trial account comes with free credits, and you can add more as you go along. You can also add a phone number to your account to start testing the full range of our voice and SMS features. A page in our support portal walks you through the signup process.

You can also port your numbers from Twilio to Plivo, as we explain in this guide.

Migrating your Python SMS application

You can migrate your existing application from Twilio to Plivo by refactoring the code, or you can try our intuitive visual workflow builder PHLO. To continue working with the APIs, use one of the quickstart guides to set up a development environment for your preferred language. Plivo offers server SDKs in seven languages: Python, Node.js, .NET, Java, Python, Ruby, and Go. For another alternative that lets you evaluate Plivo’s SMS APIs and their request and response structure, use our Postman collections.

How to send an SMS message

Let’s take a look at the process of refactoring the code to migrate your app from Twilio to Plivo to set up a simple Python application to send an SMS message by changing just a few lines of code.

Twilio Plivo
   
import os
from twilio.rest import Client

account_sid = os.environ[“TWILIO_ACCOUNT_SID”] auth_token = os.environ[“TWILIO_AUTH_TOKEN”] client = Client(account_sid, auth_token)

message = client.messages.create(    body=“Hi there”,    from_=” 15017122661”,    to=” 15558675310” )

print(message)  

   

   
   
import os, plivo

auth_id = os.environ[“PLIVO_AUTH_ID”] auth_token = os.environ[“PLIVO_AUTH_TOKEN”] client = plivo.RestClient(auth_id, auth_token)

message = client.messages.create(    src=“+14151234567”,    dst=“+14157654321”,    text=“Hi there”, ) print(message)

   

Alternatively, you can implement the same functionality using one of our PHLO templates. For example, if you want to send an SMS message, your PHLO would be this:

Create PHLO for outbound SMS

How to receive and reply to SMS

You can migrate an application for receiving and replying to an incoming SMS from Twilio to Plivo just as seamlessly, as in this example:

Twilio Plivo
   
from flask import Flask, request, redirect
from twilio.twiml.messaging_response
import MessagingResponse

app = Flask(name)

@app.route(“/reply_sms”, methods= [“GET”, “POST”]) def sms_reply():    """Respond to incoming calls with a simple    text message."""    # Start our TwiML response    resp = MessagingResponse()

   # Add a message    resp.message(“Thank you, we have received your request.”)        return str(resp)

if name == main:    app.run(debug=True)  

   

   
   
from flask import Flask, request,
make_response, Response
from plivo import plivoxml

app = Flask(name)

@app.route(“/reply_sms”, methods=[“GET”, “POST”]) def sms_reply():

   from_number = request.values.get(“From”)    to_number = request.values.get(“To”)    text = request.values.get(“Text”)        # Plivo Message XML to handle Reply    response = plivoxml.ResponseElement()    response.add(        plivoxml.MessageElement(            “Thank you, we have received your            request.”,            src=to_number,            dst=from_number        )    )        return Response(response.to_string(),    mimetype=“application/xml”)

if name == main:    app.run(debug=True)

   

Here again, you can implement the same functionality using one of our PHLO templates. Your PHLO would look like:

With Dynamic Payload

For more information about migrating your SMS applications to Plivo, check out our detailed use case guides, available for all seven programming languages and PHLO.

How to send an MMS message

Let’s take a look at the process of refactoring the code to migrate your app from Twilio to Plivo to set up a simple Python application to send an MMS message by changing just a few lines of code.

Twilio Plivo
   
import os
from twilio.rest import Client

account_sid = os.environ[‘TWILIO_ACCOUNT_SID’] auth_token = os.environ[‘TWILIO_AUTH_TOKEN’] client = Client(account_sid, auth_token)

message = client.messages.create(    body=‘This is the ship that made the Kessel Run in fourteen parsecs?’,    from_=‘+15017122661’,    media_url= [https://c1.staticflickr.com/3/2899/14341091933_1e92e62d12_b.jpg],    to=‘+15558675310’) print(message)  

   

   
   
import os, plivo

auth_id = os.environ[“PLIVO_AUTH_ID”] auth_token = os.environ[“PLIVO_AUTH_TOKEN”] client = plivo.RestClient(auth_id, auth_token)

message = client.messages.create(    src=‘+14151234567’,    dst=‘+14157654321’,    text=‘hey there!’,    media_urls= [https://media.giphy.com/media/26gscSULUcfKU7dHq/source.gif],    type_=‘mms’) print(message)

   

Alternatively, you can implement the same functionality using one of our PHLO templates. For example, if you want to send an MMS message, your PHLO would be this:

Create PHLO for outbound MMS

More use cases

You can migrate your applications serving other use cases too.

Simple and reliable

And that’s all there is to migrate your Python SMS app from Twilio to Plivo. Our simple APIs work in tandem with our Premium Communications Network to guarantee the highest possible delivery rates and the shortest possible delivery times for your SMS messages. See for yourself — sign up for a free trial account.

P
Team Plivo
Plivo Blog