The App Engine Python 2.7 runtime directly includes several third-party libraries.
| Name | Default version | Supported versions | Description |
|---|---|---|---|
| django | (None) | "1.2" "1.3" "1.4" "1.5" (alpha) "latest" |
A full-featured web application framework for Python. |
| endpoints | (None) | "1.0" "latest" |
Libraries for building APIs in an App Engine application. |
| jinja2 | (None) | "2.6" "latest" |
A modern and designer friendly templating language for Python. |
| lxml | (None) | "2.3" "2.3.5" (alpha) "latest" |
A Pythonic binding for the C libraries libxml2 and libxslt. |
| markupsafe | (None) | "0.15" "latest" |
A XML/HTML/XHTML markup safe string for Python. |
| matplotlib | (None) | "1.2.0" "latest" |
A 2D plotting library which produces publication-quality figures. |
| MySQLdb | (None) | "1.2.4b4" (alpha) "1.2.4" (alpha) "latest" |
A Python DB API v2.0 compatible interface to MySQL. |
| numpy | (None) | "1.6.1" "latest" |
A general-purpose library for array-processing. |
| PIL | (None) | "1.1.7" "latest" |
A library for creating and transforming images. |
| protorpc | "1.0" | "1.0" "latest" |
A framework for implementing HTTP-based remote procedure call (RPC) services. |
| PyAMF | (None) | "0.6.1" "latest" |
A library that provides (AMF) Action Message Format functionality. |
| pycrypto | (None) | "2.3" "2.6" "latest" |
A library of cryptography functions such as random number generation. |
| setuptools | (None) | "0.6c11" "latest" |
A library that provides package and module discovery capabilities. |
| ssl | (None) | "2.7" "latest" |
The SSL socket wrapper built-in module. |
| webapp2 | "2.3" | "2.3" (deprecated) "2.5.1" "2.5.2" "latest" |
A lightweight Python web framework. |
| webob | "1.1.1" | "1.1.1" "1.2.3" "latest" |
A library that provides wrappers around the WSGI request environment. |
| yaml | "3.10" | "3.10" "latest" |
A library for YAML serialization and deserialization. |
Third-party libraries must be specified in app.yaml, and this configuration is different than in Python 2.5 (see Configuring Libraries for details).
Vendoring Third-party Packages
If you want to include additional pure-python third-party packages, you can do so by setting up vendoring. Vendoring allows you to install packages to a subdirectory of your project and include them in your code. To use vendoring, create (or modify)appengine_config.py in the root of your project.
from google.appengine.ext import vendor
# Add any libraries installed in the "lib" folder.
vendor.add('lib')
You can now use pip to install libraries.
$ pip install -t lib gcloudYou can also declare all of your dependencies in a
requirements.txt and install them at once.
Flask==0.10 Markdown==2.5.2 google-api-python-client
$ pip install -t lib -r requirements.txtRead more requirements.txt in pip's documentation.
Note: pip version 6.0.0 or higher is required for vendoring to work properly.
Django Notes
Django is a full-featured web application framework for Python. It provides a full stack of interchangable components, including dispatch, views, middleware, and templating components, and many others.
The Django data modeling interface is not compatible with the App Engine datastore. You can use the App Engine data modeling libraries (db or ndb) in your Django applications. However, third-party Django applications that use the Django data modeling interface—most notably Django's Admin application—may not work with App Engine directly.
To use Django with the
NDB storage API, add
'google.appengine.ext.ndb.django_middleware.NdbDjangoMiddleware',
to the MIDDLEWARE_CLASSES entry in your Django
settings.py file.
It's best to insert it in front of any other middleware classes,
since some other middleware may make datastore calls and those won't be
handled properly if that middleware is invoked before this middleware.
(You can learn more about
Django middleware.)
To use Django, specify the WSGI application and Django
library in app.yaml:
... handlers: - url: /.* script: main.app # a WSGI application in the main module's global scope libraries: - name: django version: "1.2"
The DJANGO_SETTINGS_MODULE environment variable must be set to the name of your Django settings module, typically 'settings', before packages are imported.
If your Django settings module is something other than
settings.py, set the
DJANGO_SETTINGS_MODULE environment
variable accordingly either in your app.yaml file:
env_variables: DJANGO_SETTINGS_MODULE: 'myapp.settings'
or in your Python code:
import os # specify the name of your settings module os.environ['DJANGO_SETTINGS_MODULE'] = 'myapp.settings' import django.core.handlers.wsgi app = django.core.handlers.wsgi.WSGIHandler()
Matplotlib Notes
Note: The experimental release of matplotlib is not supported on the development server. You can still add matplotlib to the libraries list, but it will raise an ImportError exception when imported.
Matplotlib is a plotting library that produces graphs and figures in a variety of image formats. On App Engine, the interactive modes of matplotlib are not supported, and a number of other features are also unavailable. This means you cannot use pyplot.show() as many matplotlib tutorials suggest. Instead, you should use pyplot.savefig() to write image data to the output stream, a cStringIO.StringIO instance, or the Blobstore using the Files API.
Matplotlib allows extensive customization through the use of the matplotlibrc configuration file, which should be placed in the application's top-level directory. Alternatively, you can set the MATPLOTLIBRC environment variable to a path relative to your application's directory.
The default backend is AGG, which allows writing files of all supported formats: PNG (the default format), RAW, PS, PDF, SVG and SVGZ. If you make the PIL library available by adding PIL to the libraries section of app.yaml, then the AGG backend will automatically support writing JPEG and TIFF image formats as well.
Matplotlib comes with a number of fonts which are automatically available. You can use custom fonts by uploading them (in TTF format) along with your application, and setting the TTFPATH environment variable to the path where they are located, relative to your application's directory. (See Defining Environment Variables.)
A number of matplotlib features are not supported on App Engine. In particular:
- There is no
~/.matplotlibdirectory (however, there are alternative locations to place thematplotlibrcconfiguration file, as described above). - Interactive backends and GUI elements are not supported.
- The EMF, Cairo and GDK backends are not supported.
- There is no caching, and therefore a number of mechanisms will re-calculate or re-download data that would normally be cached. Specific caching mechanisms that have been disabled include font data (calculated by
matplotlib.font_manager.FontManager.findfont), sample data (downloaded bymatplotlib.cbook.get_sample_data) and financial data (downloaded bymatplotlib.finance.fetch_historical_yahoo).- Because there is no caching, it is not possible to call
matplotlib.cbook.get_sample_datawithasfileobj=Falseunlessexamples.downloadis set toFalse.
- Because there is no caching, it is not possible to call
- All features that invoke external commands have been disabled.
- Use of
fontconfighas been disabled. Fonts are found through the mechanism described above. - Use of LaTeX for text rendering is not supported. Setting
text.usetextoTruewill not work. - Use of an external PostScript distiller program is not supported. Setting
ps.usedistillertoghostscriptorxpdfwill not work. - Use of an external video encoding program is not supported. The
matplotlib.animation.Animation.savemethod will not work, and therefore, thematplotlib.animationpackage is not useful. - The
matplotlib.cbook.report_memoryfunction andmatplotlib.cbook.MemoryMonitorclass are not supported.
- Use of
- The
matplotlib.testfunction has been disabled.
Note: The pylab and matplotlib.pyplot modules are stateful and not thread-safe. If you use them on App Engine, you must set threadsafe: false in app.yaml, and be aware that the plotter state will be preserved between requests on the same instance. For example, you will need to call pyplot.clf() at the beginning of each request to ensure that previous plots are not visible. It is recommended that you use the thread-safe object-oriented API instead of the stateful pyplot API.