English | Site Directory

The Development Web Server

The App Engine SDK includes a web server application for developing and testing App Engine applications. The web server reproduces the App Engine Python runtime environment including sandbox restrictions, and emulates the App Engine services such as the datastore.

The SDK and web server run on any computer with Python 2.5. You can get Python for your operating system at the Python website.

If you haven't already, you can download the App Engine SDK.

Running the Development Web Server

Once you have a directory for your application and an app.yaml configuration file, you can start the development web server with the dev_appserver.py command:

dev_appserver.py myapp

The web server listens on port 8080 by default. You can visit the application at this URL: http://localhost:8080/

To change which port the web server uses, use the --port option:

dev_appserver.py --port=9999 myapp

To stop the web server: With Windows, press Control-Break in your command prompt window. With Mac OS X or Unix, press Control-C.

While it is running, the web server watches for changes you make to your files, and reloads them if needed. For most kinds of changes, you can simply edit files, then reload the web page in your browser. Under certain circumstances, such as if the application does dynamic imports, you may need to restart the web server to reset module import caching.

Using the Datastore

The development web server simulates the App Engine datastore using a file on your computer. This file persists between invocations of the web server, so data you store will still be available the next time you run the web server.

To clear the local datastore for an application, use the --clear_datastore option when you start the web server:

dev_appserver.py --clear_datastore myapp

The web server prints the location of the datastore file it is using to the terminal when it starts up. You can make a copy of the file, then restore them later to reset the datastore to a known state. Be sure to restart the web server after replacing the datastore file.

To change the location used for the datastore file, use the --datastore_path option:

dev_appserver.py --datastore_path=/tmp/myapp_datastore myapp

When your application performs a query on the datastore, the development web server checks that the query is supported by the application's index.yaml file. If the query requires that its index be mentioned in the file, the server generates one and adds it to the file. You may want to edit this file if your application may attempt queries that are not exercised by your tests.

index.yaml is generated from every query made since the datastore file was created or last cleared. The query history is stored in a separate file. To change the location of the history file, use the --history_path option similarly to the --datastore_path option.

For more information on indexes and index.yaml, see Queries and Indexes, and Configuring Indexes.

Using Users

The development web server simulates Google Accounts with its own sign-in and sign-out pages. While running under the development web server, the users.create_login_url and users.create_logout_url functions return URLs for /_ah/login and /_ah/logout on the local server.

The development sign-in page includes a form where you can enter an email address. Your session uses whatever email address you enter as the active user.

To have the application believe that the logged-in user is an administrator, check the checkbox on the form.

Using Mail

The development web server can send email for calls to the App Engine mail service. To enable email support, the web server must be given options that specify a mail server to use. The web server can use an SMTP server, or it can use a local installation of Sendmail.

To enable mail support with an SMTP server, use the --smtp_host, --smtp_port, --smtp_user and --smtp_password options with the appropriate values.

dev_appserver.py --smtp_host=smtp.example.com --smtp_port=25 \
    --smtp_user=ajohnson --smtp_password=k1tt3ns myapp

To enable mail support with Sendmail, use the --enable_sendmail option. The web server will use the sendmail command to send email messages, with your installation's default configuration.

dev_appserver.py --enable_sendmail myapp

If mail is not enabled with either SMTP or Sendmail, then attempts to send email from the application will do nothing, and appear successful in the application.

Using URL Fetch

When your application uses the URL fetch API to make an HTTP request, the development web server makes the request directly from your computer. The behavior may differ from when your application runs on App Engine if you use a proxy server for accessing websites.

Note: dev_appserver.py can only serve one request at a time. If your application makes URL fetch requests to itself while processing a request, these requests will fail when using the development web server. (They will not fail when running on App Engine.) To test such requests, you can run a second instance of dev_appserver.py on a different port, then code your application to use the other server when making requests to itself.

The Development Console

The development web server includes a console web application. With the console, you can browse the local datastore, and interact with the application by submitting Python code to a web form.

To access the console, visit the URL /_ah/admin on your server: http://localhost:8080/_ah/admin

Command-Line Arguments

The dev_appserver.py command supports the following command-line arguments:

--datastore_path=...

The path to use for the local datastore data file. The server creates this file if it does not exist.

--history_path=...

The path to use for the local datastore history file.

--debug

Prints verbose debugging messages to the console while running.

--help

Prints a helpful message then quits.

--login_url=...

The relative URL to use for the Users sign-in page. Default is /_ah/login.

--port=...

The port number to use for the server. Default is 8080.

--address=...

The host address to use for the server. You may need to set this to be able to access the development server from another computer on your network. An address of 0.0.0.0 allows both localhost access and hostname access. Default is localhost.

--clear_datastore

Clears the datastore before starting the web server.

--require_indexes

Disables automatic generation of entries in the index.yaml file. Instead, when the application makes a query that requires that its index be defined in the file and the index definition is not found, an exception will be raised, similar to what would happen when running on App Engine.

--smtp_host=...

The hostname of the SMTP server to use for sending email messages.

--smtp_port=...

The port number of the SMTP server to use for sending email messages.

--smtp_user=...

The username to use with the SMTP server for sending email messages.

--smtp_password=...

The password to use with the SMTP server for sending email messages.

--enable_sendmail

Uses the local computer's Sendmail installation for sending email messages.

--debug_imports

Prints debugging messages related to importing modules, including search paths and errors.