This tutorial creates a tiny application that displays a short message.
Download the App Engine SDK for Python
Before getting started, be sure to download the Python SDK for App Engine.
Creating a Simple Request Handler
Create a directory named
helloworld. All files for this application reside in this directory.
helloworld directory, create a file named
helloworld.py, and give it the following contents:
This Python script responds to a request with an HTTP header that describes the content and the message
Note: Ensure that you save the files you create as plain text. You may encounter errors otherwise.
Creating the Configuration File
An App Engine application has a configuration file called
app.yaml. Among other things, this file describes which handler scripts should be used for which URLs.
helloworld directory, create a file named
app.yaml with the following contents:
From top to bottom, this configuration file says the following about this application:
- This is version number
1of this application's code. If you adjust this before uploading new versions of your application software, App Engine will retain previous versions, and let you roll back to a previous version using the administrative console.
- This code runs in the
python27runtime environment, API version
1. Additional runtime environments and languages may be supported in the future.
- This application is
threadsafeso the same instance can handle several simultaneous requests. Threadsafe is an advanced feature and may result in erratic behavior if your application is not specifically designed to be threadsafe.
- Every request to a URL whose path matches the regular expression
/.*(all URLs) should be handled by the
appobject in the
Testing the Application
With a handler script and configuration file mapping every URL to the handler, the application is complete. You can now test it with the web server included with the App Engine Python SDK.
Start the web server with the following command, giving it the path to the
helloworld directory. If you have symlinks created for dev_appserver, you don't need to include the path:
$ dev_appserver.py helloworld/
The web server is now running, listening for requests on port 8080. You can test the application by visiting the following URL in your web browser:
You can leave the web server running while you develop your application. The web server knows to watch for changes in your source files and reload them if necessary.
Try it now: Leave the web server running, then edit
helloworld.py to change
Hello, World! to something else. Reload http://localhost:8080/.
To shut down the web server, make sure the terminal window is active, then press Control-C.
You can leave the web server running for the rest of this tutorial. If you need to stop it, you can restart it again by running the command above.
Uploading the application
- Sign in to App Engine using your Google account. If you do not have a Google account, you can create a Google account with an email address and password.
If you haven't already done so, create a project for your App Engine app as follows:
- Visit the Google Cloud Platform Console and click Create Project.
- Supply the desired project name in the New Project form. It doesn't have to match your app name, but using the same name as your app might make administration easier.
- Accept the generated project ID or supply your own ID. This project ID is used as the App Engine application ID. Note that this ID can only be used once: if you subsequently delete your project, you won't be able to re-use the ID in a new project.
Note the application ID (project ID) you created above.
Upload your finished application to Google App Engine by invoking the following command. This opens a browser window for you to sign in using your Google account. You'll be providing the project ID as the argument for
appcfg.py -A YOUR_PROJECT_ID update helloworld/
Your app is now deployed and ready for users!
You have completed this tutorial.
The full URL for your application is
http://_your-app-id_.appspot.com/. Optionally, you can instead purchase and use a top-level domain name for your app, or use one that you have already registered.
Expanding on Hello, World!
In the "Creating a Guestbook" tutorial, you expand this simple application to become a fully-fledged Guestbook application that lets authenticated Google accounts post messages to a public page.