by BandwidthExamples


Python Bandwidth v2 Messaging Reference App

Basic demonstration on using Python with Bandwidth.

ℹ️Does not support responding to group messages quite yet!

Table of Contents


Setup Environment Variables

How to setup environment variables

Environment Variable Description Example BANDWIDTH_ACCOUNT_ID Bandwidth Account Id 997891 BANDWIDTH_API_TOKEN Bandwidth API Token asdklgajl3ujahlkujas BANDWIDTH_API_SECRET Bandwidth API Secret asdfkljasd2305jsdlkf

How It Works

Basic demonstration on responding to a text message with the Bandwidth v2 Messaging API.



If you want to run locally, see more on ngrok

Account Setup

At this point you should have a callback URL for your python application.

Head to to create a new application & location

Application Creation

Set the application type to:

  • Name: python-messaging-v2-reference
  • Messaging callback URL: {Your-url}

create app

Location Creation

Set these parameters on the location:

  • Name : python messaging v2 reference
  • Default : false (unless you want it to be)
  • Everything until SMS Settings is for voice
  • SMS Settings
    • Enable
    • Toll Free : enable
    • SMS Protocol HTTP
    • International (will depend on your settings)
    • Proxy Peer ID : ProdV2Messaging-HTTPV2
    • HTTPV2 Messaging : enable
    • Application : python-messaging-v2-reference (the one we just created)
  • MMS Settings
    • Enable
    • Proxy Peer ID : ProdV2Messaging-HTTPV2

create app

Assign a phone number to the location

To order a new phone number from the dashboard:

  • Select the type of phone number (you can search if you like)
  • Create the new phone number order
  • Check the order status
  • Once status is complete πŸ‘

Assign number

πŸ‘πŸ‘ Then text that number πŸ“² πŸ‘πŸ‘

Local Installation

Setup with ngrok

Ngrok is an awesome tool that lets you open up local ports to the internet.

Once you have ngrok installed, open a new terminal tab and navigate to it's location on the file system and run:

$ ./ngrok http 5000

You'll replace the heroku URL in the tutorials above with your ngrok url.

Clone this repo

$ git clone

$ cd python-messaging-v2-reference

Install requirements

$ pipenv shell

Launch the App

$ pipenv run flask run

To Exit

Just close the shell by either ^d or:

$ exit