Tropo is part of CiscoLearn More

HOWTO: Working with the Python 3 branch of the Tropo Python Web API library

Posted on September 8, 2010 by tropo

Python logoAs we’ve rolled out the python module for the Tropo WebAPI, one of the questions naturally is – which version of python is this for?

Developers who don’t work with python may not be aware that the new python version 3.x is deliberately NOT backwards-compatible with python 2.x. There are many reasons and the reality is that python 2.x will be in usage for many years – even as all the new development happens with 3.x.

So the quick answer is that the main branch of the python library for the Tropo WebAPI is targeted at python 2.5 or later. (Current is 2.7.)

However, for people who want to work with python 3.x, I created a branch in the Github repository called “python3” that includes a version of the Web API that works with python 3.x. There’s a catch, though:

When you download the code or clone the repo from Github, you only get the ‘master’ branch with the 2.x code.

The “git clone” command just pulls the one main master branch. Similarly, if you download the code directly from the website (i.e. not using ‘git’), you will by default get the 2.x code only.

Here’s how to fix that… for both command-line git and for the web download.


If you download the python module from the Github website, it’s a simple process to get the python3 code. Simply go to the module web page, click on the “Switch Branches” link on the nav bar, and choose “python3”:


Now when you click on the “Download Source” button in the upper right of the screen you will get the python 3.x source code.


For command-line git, the process isn’t too much different – and you can nicely have both the 2.x and 3.x code in your same local directory on your system. Github nicely provides this handy “git cheat sheet” that includes these relevant lines:



git fetch origin [remote-branch]:[new-local-branch]

So the magic command to get the python 3 branch into your local clone of the repo is to make sure you are in your local repo and type:

git fetch origin python3:python3

You now will have the python3 branch in your local repo – but the code you see will still be the 2.x until you switch to the new branch.

Here’s how the command-line sequence would look:

$ git fetch origin python3:python3
* [new branch] python3 -> python3 $ git branch
* master
$ git checkout python3
Switched to branch "python3"

The code in your repo will now be the python 3.x code and you can work with it and try it out with your applications.

To switch back to the 2.x code, just do:

git checkout master

And to go back to the 3.x code, just do:

git checkout python3

Alternatively, you could clone the repo twice into two different directories and have one be the python3 branch all the time. Different people have different strategies.

Over time, if you want to pull down any changes that have been made to the Github repo for the python 3 branch, you can type this (MAKE SURE YOU ARE IN THE ‘python3’ BRANCH IN YOUR LOCAL REPO):

git pull origin python3

That’s it.


I created the “python3” branch because I had a personal interest in experimenting with python 3.x for a Tropo app. I plan to do my best to keep it in sync with any changes and improvements that are made to the 2.x track… but any help is welcome! If you work with python 3 and find ways to make the Tropo module work better (or more “Python 3-ish”) please do contact me either via Github (I’m “danyork“) or via email.

P.S. If you are a regular Github user, feel free to fork, make your changes in your fork and then send a pull request. (And if that last sentence made no sense whatsoever to you, don’t worry… it’s all good.)

Leave a Reply