Setting up Google App Engine

Cloud computing was briefly mentioned in the introduction to this chapter. Google App Engine (GAE) is one of the offerings in that area. GAE puts each application made by users in separate sandboxes located somewhere in the Google data centers (Google Cloud). GAE automatically scales application resources according to the number of requests. GAE supports several Python web frameworks and numerical software such as NumPy.

To use GAE, we need a Google account, which is free. Download the GAE tools and libraries for various operating systems from https://developers.google.com/appengine/downloads. From this web page, we can download documentation and the GAE Eclipse plugin as well. For developers who use the Eclipse IDE, the plugin is recommended. The GAE Standard Development Kit (SDK) provides a development environment, which mimics the Google Cloud. GAE at the moment supports Python 2.7 only. We can manage GAE apps either with Python scripts or using a GUI, which are part of the SDK.

Create a new application with the launcher (navigate to File | New Application). We will give the project the name gaedemo. In the corresponding folder, GAE creates configuration files and the main.py file, which serves as an entry point for the application. If we check https://developers.google.com/appengine/docs/python/tools/libraries27, we will see that NumPy and matplotlib are supported in GAE, although not the most recent versions. The matplotlib functionality is limited in GAE; for instance, we can't run the show() function. Add NumPy support as given in the app.yaml file in this book's code bundle:

application: gaedemo
version: 1
runtime: python27
api_version: 1
threadsafe: yes

handlers:
- url: /favicon.ico
  static_files: favicon.ico
  upload: favicon.ico

- url: .*
  script: main.app

libraries:
- name: webapp2
  version: "2.5.1"
- name: numpy
  version: "1.6.1"

Add some code that uses NumPy as given in the main.py file in this book's code bundle:

import webapp2
import numpy as np

class MainHandler(webapp2.RequestHandler):
    def get(self):
        self.response.out.write('Hello world!<br/>')
        np.random.seed(42)
        self.response.out.write('NumPy sum = ' + str(np.random.randn(7).sum()))

app = webapp2.WSGIApplication([('/', MainHandler)],
                              debug=True)

If we click on the Run button and then click on the Browse button in the GAE launcher, we should see a web page with the following output in our web browser:

Hello world!

NumPy sum = 3.64009073018

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.219.4.174