Google Code offered in: English - Español - 日本語 - 한국어 - Português - Pусский - 中文(简体) - 中文(繁體)
This page provides installation and migration instructions for Python 2.7. You can use the information here to configure a new Python 2.7 application or update an existing application. The page has the following sections:
In order to use Python 2.7, an application must meet the following requirements:
Python 2.7 requires a special runtime
configuration element in the header of app.yaml
. Note that the threadsafe:
[true
| false
] element is required for Python 2.7 applications. If true
, App Engine sends requests concurrently; if false
, App Engine sends them serially. The following app.yaml
header enables concurrent requests:
application: myapp version: 1 runtime: python27 api_version: 1 threadsafe: true ...
The Python 2.7 runtime includes some additional third-party modules and makes them available on demand. Other libraries, such as WebOb, are available by default, but you can specify which version you want to use. To specify the latest version, add version: latest
to app.yaml
:
libraries: - name: PIL version: latest - name: webob version: latest
In some cases, new libraries are not backward compatible. To avoid compatibility issues with the new libraries, you can specify an exact version:
libraries: - name: PIL version: "1.1.7"
Python 2.7 supports the following combinations of names and versions:
Name | Default | Supported Versions |
---|---|---|
django | Not Available | "1.2" |
jinja2 | Not Available | "2.6" |
lxml [1] | Not Available | "2.3" |
markupsafe [1] | Not Available | "0.15" |
numpy [1] | Not Available | "1.6.1" |
PIL [1] | Not Available | "1.1.7" |
pycrypto [1] | Not Available | "2.3" |
setuptools | Not Available | "0.6c11" |
webapp2 | 2.3 | "2.3" |
webob | 1.1.1 | "1.1.1" |
yaml | 3.10 | "3.10" |
[1] To test applications using this library with the development web server, you must download and install it on your local machine.
The Python 2.7 runtime supports Web Server Gateway Interface (WSGI) applications natively. Instead of specifying a CGI handler (i.e. a Python script) in app.yaml
and running your web application in your script, you can specify the application directly:
... handlers: - url: /.* script: myapp.app ...
You also need to move your WSGI application object to the global scope:
import webapp2 class MainPage(webapp2.RequestHandler): def get(self): self.response.headers['Content-Type'] = 'text/plain' self.response.out.write('Hello, WebApp World!') app = webapp2.WSGIApplication([('/', MainPage)])
You can still specify CGI script handlers in app.yaml
.
Warning! If you plan to use concurrent requests, you must use WSGI handlers.
To use Python 2.7, you must specify a threadsafe
element in app.yaml
. If true
, App Engine sends requests concurrently; if false
, App Engine sends them serially.
application: myapp version: 1 runtime: python27 api_version: 1 threadsafe: true
The Python 2.7 runtime no longer restricts access to Python bytecode. Libraries that generate or manipulate bytecode (such as the jinja2 templating library) can do so in this runtime.
You can upload and use .pyc
, but not in combination with .py
files. You can upload .zip
files containing .py
or .pyc
files (or a combination).
Threads can be created using the thread or threading modules. Note that threads will be joined by the runtime when the request ends, so the threads cannot run past the end of the request.
After configuring and updating the application, upload it using appcfg.py
:
% appcfg.py update myapp
Once you've uploaded the application, you need to test it extensively to ensure backward compatibility. If you are experiencing issues, see the Considerations when Migrating Your App section below, or check out the forums.
In Python 2.7, you must use specific versions of some App Engine features and third-party libraries. You will encounter backward-compatibility issues unless you test and update the application.
The following list identifies the primary compatibility issues and points to further resources to resolve them. Google recommends testing the application extensively after upgrading any of the following libraries:
app.yaml
.Crypto.Util.randpool
has been deprecated in favor of Crypto.Random
. For more information, see What to do about RandomPool.