Using the local development server Stay organized with collections Save and categorize content based on your preferences.
You can use the local development server to simulaterunning your App Engine application in production as well as use it toaccess App Engine bundled services.
The simulated environment enforces some sandbox restrictions, such as restrictedsystem functions and Python 2 module imports, but not others, likerequest timeouts or quotas.
The local development server also simulates the services provided by thelibraries in the SDK for App Engine, including Datastore, Memcache, andTask Queues, by performing their tasks locally. When your application isrunning in the development server, you can still make remote API calls to theproduction infrastructure using Google APIs HTTP endpoints.
Before you begin
Since Python 2.7 has reached theend of support, you can no longer use thelatest version ofdev_appserver.py to locally run yourapplications. To download an archived version ofdevapp_server.py, follow thesesteps:
From thearchive, download the zipped folder that contains the
dev_appserver.pyserver for runtimes that have reached the end of support.Extract the directory's contents to your local file system, such as to your
/homedirectory. You can finddev_appserver.pyin thegoogle_appengine/directory.
Set up the local development server
To run the local development server tool, you must set up the following:
Verify that you have installed a Python 2 interpreter of version 2.7.12 or later.
Set the
DEVAPPSERVER_ROOTenvironment variable in your shell tothe path of your Python 2 interpreter.
Run the local development server
Note: Thedev_appserver tool does not support development of Python 3 apps onWindows.Aftersetting up the local development server and creating theapp.yamlconfiguration file for your app, you can use thedev_appserver.py command torun your app locally.
To start the local development server:
In the directory that contains your
app.yamlconfiguration file, runthedev_appserver.pycommand.Specify the directory path to your app, for example:
python2[DEVAPPSERVER_ROOT]/google_appengine/dev_appserver.py[PATH_TO_YOUR_APP]Alternatively, you can specify the configuration file of a specific service, for example:
python2[DEVAPPSERVER_ROOT]/google_appengine/dev_appserver.pyapp.yamlTo change the port, you include the
--portoption:python2[DEVAPPSERVER_ROOT]/google_appengine/dev_appserver.py--port=9999[PATH_TO_YOUR_APP]Replace
[DEVAPPSERVER_ROOT]with the path to the folder where you extract thearchived version ofdevapp_server.py.To learn more about the
dev_appserver.pycommand options, seeLocal development server options.The local development server is now running and listening for requests. Youcan visithttp://localhost:8080/ in your webbrowser to see the app in action.
If you specified a custom port with the
--portoption, remember to openyour browser to that port.
To stop the local server from the command line, press the following:
- macOS or Linux:Control+C
- Windows:Control+Break
Specify application IDs
To access your App ID in the local server, for example to spoof an emailaddress, use theget_application_id()function. To get the hostname of the running app, use theget_default_version_hostname()function.
Detecting application runtime environment
To determine whether your code is running in production or in the localdevelopment server, you can check the value of theSERVER_SOFTWARE environmentvariable:
ifos.getenv('SERVER_SOFTWARE','').startswith('Google App Engine/'):# Productionelse:# Local development serverUsing the local Datastore
Note: We are migrating the local development environment to use theCloud Datastore Emulator, For moreinformation about this change, see themigration guide.The local development server simulates the App Engine datastore using alocal file that persists between invocations of the local server.
For more information on indexes andindex.yaml, see theDatastore IndexesandDatastore IndexConfiguration pages.
Browse the local Datastore
If your app has written data to your local Datastore using the local developmentserver, you can browse it in the local development console.
To browse local Datastore:
Access theDatastore Viewer in thelocal development console. (The URL is
http://localhost:8000/datastore.)View your local Datastore contents.
Specify the ID allocation policy
For production App Engine, you can set the Datastore toautomatically generate entity IDs.
Although the auto ID assignment policies for the production server arecompletely different than those used by the development server, you can also setthe automatic ID allocation policy for the local server.
To specify the automatic ID assignment policy, use the--auto_id_policyoption:
python2DEVAPPSERVER_ROOT/google_appengine/dev_appserver.py--auto_id_policy=sequentialReplace:
DEVAPPSERVER_ROOT with the path to the folder where youextract thearchived version of
devapp_server.py.--auto_id_policywith one of the following:scatteredwhen (default) IDs are assigned from a non-repeating sequence ofapproximately uniformly distributed integers.sequentialwhen IDs are assigned from the sequence of consecutive integers.
Clear the local Datastore
To clear the local datastore for an application, invoke the local developmentserver as follows:
python2DEVAPPSERVER_ROOT/google_appengine/dev_appserver.py--clear_datastore=yesapp.yamlReplaceDEVAPPSERVER_ROOT with the path to the folder where youextract thearchived version ofdevapp_server.py.
Change local Datastore location
To change the location used for the datastore file, use the--datastore_pathoption:
python2DEVAPPSERVER_ROOT/google_appengine/dev_appserver.py--datastore_path=/tmp/myapp_datastoreapp.yamlReplaceDEVAPPSERVER_ROOT with the path to the folder where you extract thearchived version ofdevapp_server.py.
Use the Users service
App Engine provides aUsers Service to simplifyauthentication and authorization for your application. The local developmentserversimulates the behavior of GoogleAccountswith its own sign-in and sign-out pages. While running under the localdevelopment server, theusers.create_login_urlandusers.create_logout_urlfunctions return URLs for/_ah/login and/_ah/logout on the local server.
Use Mail
The local development server can send email for calls to the App Enginemail service using either an SMTP server or a local installation ofSendmail.
Using SMTP
To enable mail support with an SMTP server, invokedev_appserver.py asfollows::
python2[DEVAPPSERVER_ROOT]/google_appengine/dev_appserver.py--smtp_host=smtp.example.com--smtp_port=25 \--smtp_user=ajohnson--smtp_password=k1tt3ns[PATH_TO_YOUR_APP]Replace:
[DEVAPPSERVER_ROOT]with the path to the folder where youextract thearchived version ofdevapp_server.py.--smtp_host,--smtp_port,--smtp_userand--smtp_passwordoptions with your own configuration values.
Using Sendmail
To enable mail support with Sendmail, invokedev_appserver.py as follows:
python2[DEVAPPSERVER_ROOT]/google_appengine/dev_appserver.py--enable_sendmail=yes[PATH_TO_YOUR_APP]Replace[DEVAPPSERVER_ROOT] with the path to the folder where you where youextract thearchived version ofdevapp_server.py.
The local server will use thesendmail command to send email messages withyour installation's default configuration.
dev_appserver.py with either SMTP or Sendmail asdescribed, then attempts to send email from your application will donothing, but the attempt will appear successful in your application.Use URL Fetch
When your application uses the URL fetch API to make an HTTP request, thelocal development server makes the request directly from your computer. TheURL Fetch behavior on the local server may differ from productionApp Engine if you use a proxy server for accessing websites.
Use the Interactive Console
TheInteractive Console allows developers to enter arbitrary Python codeinto a web form and execute it inside their app's environment; it provides thesame access to the application's environment and services as a .py file insidethe application itself.
Important: If you specify the--host argument when you start the localserver instead of using the default address, the Interactive Console is disabledto prevent someone remotely executing arbitrary Python code on your computer.You can bypass this and re-enable the Interactive Console by starting thedevelopment server using the--enable_console argument.To use the Interactive Console:
Access theInteractive console in thein the local development console. (The URL is
http://localhost:8000/console.)Enter any Python code you'd like to run in the text area, then submit theform to execute it. For example the following code will add a Datastore entitycalled
Greetingwith text content ofHello:fromgoogle.appengine.extimportndbclassGreeting(ndb.Model):content=ndb.TextProperty()e=Greeting(content="Hello")e.put()
Debug with the Python debugger
To use thePython debugger (pdb):
Add the following line into your code:
importpdb;pdb.set_trace();dev_appserverwill break at this point and drop into thepdbREPL(read–eval–print loop), allowing you to debug your code from the commandline.If your application makes multiple simultaneous requests that invoke
pdb.set_trace(), multiple debugging sessions will start concurrently, eachof which sends output toSTDOUT. To avoid this, serialize your requests bydisabling thedev_appservermulti-threading and multi-processing support,as follows:Disable multi-threading for:
- All services using the
--threadsafe_override=falseflag. - One service using the
--threadsafe_override=<SERVICENAME>:falseflag. - Multiple services using the
--threadsafe_override=<SERVICE1NAME>:false,<SERVICE2NAME>:falseflag.
- All services using the
Disable multi-processing for:
- All services using the
--max_module_instances=1flag. - One service using the
--max_module_instances=<SERVICENAME>:1flag. - Multiple services using the
--max_module_instances=<SERVICE1NAME>:1,<SERVICE2NAME>:1flag.
- All services using the
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-12-15 UTC.