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.
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
MIDDLEWARE_CLASSES entry in your Django
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
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.
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
For example, to use Django 1.1, add the following lines to the beginning of your script handler (
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
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.
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).
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 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
.pysource files. It cannot import modules stored as
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.