Home » App Engine » Developing a Python App for Google App Engine

Developing a Python App for Google App Engine

The simplest Python application for App Engine is a single directory with two files: a configuration file named app.yaml, and a file of Python code for a request handler. The directory containing the app.yaml file is the application root directory. You’ll refer to this directory often when using the tools.

If you are using the Launcher, you can start a new project by selecting the File menu, New Application.... The Launcher creates a new project with several files, which you may wish to edit to follow along with the
example. Alternatively, you can create the project directory and files by hand, then add the project to the Launcher by selecting the File menu, Add Existing Application....

Create a directory named clock to contain the project. Using your favorite text editor, create a file inside this directory named app.yaml.

The app.yaml configuration file for a simple application

application: clock
version: 1
runtime: python
api_version: 1
- url: /.*
script: main.py

This configuration file is in a format called YAML, an open format for configuration files and network  messages. You don’t need to know much about the format beyond what you see here.

In this example, the configuration file tells App Engine that this is version 1 of an application called clock, which uses version 1 of the Python runtime environment (the “API version”). Every request for this application (every URL that matches the regular expression /.*) is to be handled by a Python script named main.py. Create a file named main.py

Example A simple Python request handler script

import datetime
print 'Content-Type: text/html'
print ''
print '<p>The time is: %s</p>' % str(datetime.datetime.now())