Adding the twilio-python library to a Google App Engine project is a little tricky. Let's walk you through one way to do it.
The key is to lay out your project in a way that makes sense.
Create a project folder called
twilio-demo. You can name the folder anything you like, but for the rest of this tutorial, we'll assume it's namedtwilio-demo. At the command line, add a virtualenv inside of that folder, by running:mkdir twilio-demo # Creates a new twilio-demo folder cd twilio-demo # Move into that folder virtualenv . # Create a new virtual environment
You should now have a directory structure that looks like this:
twilio-demo ├── bin ├── include └── lib
We'll get to the Google App Engine part in a few steps.
Now let's install the
twilio-pythonlibrary in our Virtualenv. If your current working directory istwilio-demo, we want to source theactivatefile in thebinfolder, then install the library withpip.source bin/activate # Activate our virtual environment pip install twilio # Install the twilio-python library
Now let's add a new folder called
src. This is the folder that contains yourapp.yamland your other Google App Engine files. You can add this at the command line. If your current directory istwilio-demo:mkdir src
Create a basic
app.yamlfile in yoursrcdirectory, per the instructions Google App Engine provides. Your folder structure should now look something like this:twilio-demo ├── bin │ ├── activate │ └── ... about 20 files ├── include │ └── python2.7 -> /path/to/system/python-2.7 ├── lib │ └── python2.7 # This folder contains a bunch of files └── src ├── app.yaml └── helloworld.py
Link the twilio-python library into your
srcdirectory. We are going to use a symbolic link. Google will pick this up and import the library into the correct place. In the terminal, run these three commands from thesrcdirectory insidetwilio-demo:ln -s ../lib/python2.7/site-packages/twilio . ln -s ../lib/python2.7/site-packages/httplib2 . ln -s ../lib/python2.7/site-packages/six.py .
This should create a symbolic link inside the src directory to the
twilio-pythonmodule. You can test the link as follows. Inside thetwilio-demo/srcfolder, create a file calledhelloworld.pyand put this inside it:import webapp2 import twilio class MainPage(webapp2.RequestHandler): def get(self): self.response.headers['Content-Type'] = 'text/plain' self.response.write("The twilio version is " + twilio.__version__) app = webapp2.WSGIApplication([('/', MainPage)], debug=True)
Finally, configure your app in Google App Engine and deploy it. Here are the settings you want in Google App Engine - Note the folder path ends with
twilio-demo/src.Once App Engine is running locally, in your browser, you should be able to navigate to
http://localhost+ the provided Port and view the twilio library version number, as well as deploy your app to Google. Once you have this set up, adding more complicated actions using thetwiliolibrary should be a snap.Hope that helps! If you have questions, we're always listening at [email protected].
