Please note that the contents of this offline web site may be out of date. To access the most recent documentation visit the online version .
Note that links that point to online resources are green in color and will open in a new window.
We would love it if you could give us feedback about this material by filling this form (You have to be online to fill it)



Third-party Python Libraries in Python 2.5

In addition to the Python standard library, the App Engine APIs and tools, the App Engine Python runtime environment includes several third-party libraries that your application can use. Some of these libraries have been customized or reimplemented to run within the App Engine sandbox restrictions. This page documents which libraries are available and how the App Engine implementations differ from the original versions.

  1. Django
  2. PyCrypto
  3. WebOb
  4. YAML
  5. zipimport

Django

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 .)

The App Engine Python environment includes these versions of Django: 1.2, 1.1, 1.0, and 0.96. Django 1.2 and 0.96 are included with the App Engine SDK. Legacy Django version 0.96 is currently imported by default when an app imports the django package. However, this default may change in future SDK releases, so it's important to declare which version you wish to use, as described below.

Note: If you currently use version 0.96 or 1.0, you are strongly encouraged to upgrade your application and use version 1.2 to take advantage of the most recent features and security developments.

Django 1.2, 1.1, 1.0, and 0.96 are all available in the runtime when running on App Engine. To use one of these with your app, call the use_library() function provided by the google.appengine.dist package to declare which version to use. Subsequent attempts to import the django package will use the selected version of Django.

The use_library() function takes the name of the package ( 'django' ), and a version identifier argument. For Django 1.2, use '1.2' . For Django 1.1, use '1.1' . For Django 1.0, use '1.0' . For Django 0.96, use '0.96' .

For example, to use Django 1.1, add the following lines to the beginning of your script handler ( main.py ):

import os
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'

from google.appengine.dist import use_library
use_library('django', '1.1')

Django versions 1.1 and above require that the DJANGO_SETTINGS_MODULE environment variable 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 , adjust the DJANGO_SETTINGS_MODULE environment variable accordingly.

It is also important to use the webapp_django_version setting in appengine_config.py if you wish to use django as well as any code which uses webapp.template such as appstats or other builtin libaries. For example, to use Django 1.1, add the following line to appengine_config.py :

webapp_django_version = '1.1'

Note: It's important to declare the version of Django you wish to use even if you use the current default. The default version may change in future SDK releases. Explicitly declaring the version you are using protects your application from breaking if the default version changes.

Django versions 0.96 and 1.2 are included in the SDK but Django versions 1.0 and 1.1 are not included and must be downloaded first. To test your app with a version of Django on your computer, you must download and install Django from the Django website . Django 1.0.2 is available here . You do not need to add the versions you download to your application directory.

See the following articles for more information about using Django with App Engine. Note that these articles have not been updated with instructions for using the versions of Django 1.0 and later included with the runtime environment.

PyCrypto

App Engine includes a custom version of the Python Cryptography Toolkit , also known as PyCrypto. The version included with App Engine is based on pycrypto 2.0.1. This is not the latest version , but should be largely compatible with more recent versions.

For reasons both technical and legal, the App Engine version of PyCrypto has the following differences from the original PyCrypto 2.0.1:

  • The RC5 and IDEA ciphers have been removed.

  • The MODE_PGP encryption mode has been removed.

  • All public key cryptography routines are implemented in pure Python code. They do not use any native acceleration (C code).

WebOb

WebOb is an object-oriented interface for HTTP requests and responses. App Engine uses WebOb as part of the webapp web application framework . The environment provides WebOb 0.9.

YAML

YAML is a data format for human-readable message serialization. The App Engine Python SDK uses YAML as the format for its configuration files . The environment provides the YAML parsing libraries for Python, PyYAML 3.05.

zipimport

zipimport is a feature of the Python standard library for importing Python modules from Zip archive files. You can use zipimport to save space and reduce the number of files used when including packages with your application. For example, you can use zipimport to bundle Django with your application so the Django code only uses 1 megabyte of storage and 1 file, instead of several megabytes and hundreds of files.

App Engine provides a custom implementation of the zipimport library that runs within the environment's sandbox restrictions. It functions similarly to the version included with the Python standard library, with the following exceptions:

  • zipimport can only import modules stored in the archive as .py source files. It cannot import modules stored as .pyc or .pyo files.

  • zipimport is implemented in pure Python, and does not use native code for decompression (C code).

Note: The local development server uses the standard library version of zipimport, not the custom version used when running on App Engine. If you use features of zipimport, be sure to test your application on App Engine.

Authentication required

You need to be signed in with Google+ to do that.

Signing you in...

Google Developers needs your permission to do that.