Skip to main content

DevStack

Building a phone verificator with the Bandwidth Python SDK

Published:

September 20, 2016

Updated:

March 28, 2023

Share
Graphic of laptop

Notice: This post uses a legacy version of our API. Visit out developer portal to view current API documentation.

During my Summer internship, I tried using the Bandwidth Python SDK.  The app was smaller in scope than the first app I built and is just a phone verificator.  All the user does is put in their number, receive a call/text with a code, and it checks if the user puts in the correct code.

image-1

The biggest difference for making this phone verificator app versus the previous simple phone app was the emphasis on CSS.  Since this is the case, this post will mostly focus on the app.py file, but all files are available to see on github.  For further information about my process with getting started with using services like heroku, micro frameworks, etc I recommend my previous blogpost.

python-blogpost

Again, since this was a project small in scope, I chose to use Flask, a microframework for python.  If you’re reading this after my previous blogpost, then you’ll notice that Spark and Flask have roughly similar ways of defining endpoints.

image-3
image-4

Flask also has it’s own rendering definitions, so it can easily render HTML, which is also similar to how Spark would render.

base2.html

image-5

index.html

image-6

Some notes about working with the Bandwidth Python SDK. Callback events, like the “answer event”, will work the same as they did in Java.  Meaning you’ll need a callbackUrl defined when creating the call.

image-7

Overall, the python part of the app is fairly simple.  An important part of the setup that is worth remarking, is to pay attention to the Procfile.  The Procfile should be set to have only 1 worker for Gunicorn, otherwise there will be issues with multiple threads and the app will be inaccurately keeping track of the verification code.

image-8

To bring this two part article to a conclusion, this is what I learned:

  1. How APIs work and how HTTP requests interact with them.
  2. Between the basic functions of the SDKs and BXML, most any standard task can be accomplished.
  3. Micro frameworks are a thing.
  4. CSS is one of the most aggravating “languages” to work with, but at least it looks pretty.

Try out the app!

image-9

Get the Python SDK