The
App Engine Python SDK
includes a command for interacting with App Engine named
appcfg.py
. You can use this command to upload new versions of the code, configuration and static files for your app to App Engine. You can also use the command to manage datastore indexes and download log data.
Note: If you created your project using the Google Cloud Console, your project has a title and an ID. In the instructions that follow, the project title and ID can be used wherever an application title and ID are mentioned. They are the same thing.
- Uploading the app
- Updating indexes
- Deleting unused indexes
- Updating Task Queue configuration
- Updating the DoS protection configuration
- Managing scheduled tasks
- Downloading source code
- Downloading logs
- Uploading data
- Using an HTTP proxy
- Password-less login with OAuth2
- Command-line arguments
Uploading the app
To upload application files, run the
appcfg.py
command with the
update
action and the name of your application's root directory. The root directory should contain the
app.yaml
file for the application.
appcfg.py update myapp/
appcfg.py
gets the application ID from the
app.yaml
file, and prompts you for the email address and password of your Google account. After successfully signing in with your account,
appcfg.py
stores a "cookie" so that it does not need to prompt for a password on subsequent attempts.
You can specify the email address on the command line using the
--email
option. You cannot specify the password as a command line option.
appcfg.py [email protected] update myapp/
Only application owners and the developer who uploaded the code can download it. If anyone else attempts to download the app, they'll see an error message like the following:
Fetching file list...
Email: [email protected]
Password for [email protected]:
Error 403: --- begin server output ---
You do not have permission to download this app version.
--- end server output ---
If you factor your application into Modules you can specify one or more yaml files for your modules in the update command.
Updating indexes
When you upload an application using
appcfg.py update
, the update includes the app's
index.yaml
file. If the
index.yaml
file defines an index that doesn't exist yet on App Engine, App Engine creates the new index. Depending on how much data is already in the datastore that needs to be mentioned in the new index, the process of creating the index may take a while. If the app performs a query that requires an index that hasn't finished building yet, the query will raise an exception.
To prevent this, you must ensure that the new version of the app that requires a new index is not the live version of the application until the indexes finish building. One way to do this is to give the app a new version number in
app.yaml
whenever you add or change an index in
index.yaml
. The app is uploaded as a new version, and does not become the default version automatically. When your indexes have finished building, you change the default version to the new one using the "Versions" section of the
Admin Console
.
Another way to ensure that new indexes are built before the new app goes live is to upload the
index.yaml
configuration separately before uploading the app. To upload only the index configuration for an app, use the following command:
appcfg.py update_indexes myapp/
You can check the status of the app's indexes from the "Indexes" section of the Admin Console .
Deleting unused indexes
When you change or remove an index from
index.yaml
, the original index is
not
deleted from App Engine automatically. This gives you the opportunity to leave an older version of the app running while new indexes are being built, or to revert to the older version immediately if a problem is discovered with a newer version.
When you are sure that old indexes are no longer needed, you can delete them from App Engine using the following command:
appcfg.py vacuum_indexes myapp/
This command deletes all indexes for the app that are not mentioned in the local version of
index.yaml
.
Updating Task Queue configuration
You can update just the configuration for an app's task queues without uploading the full application. To upload the
queue.yaml
file, use the
appcfg.py update_queues
command:
appcfg.py update_queues myapp/
Updating the DoS protection configuration
You can update just the configuration for the DoS Protection for an app without uploading the full application. To upload the
dos.yaml
file, use the
appcfg.py update_dos
command:
appcfg.py update_dos myapp/
Managing scheduled tasks
App Engine supports scheduled tasks (known as cron jobs). You specify these in a file called
cron.yaml
, and upload them using the
appcfg.py update_cron
command:
appcfg.py update_cron myapp/
appcfg update
will also upload cron job specifications if the file exists. For more on cron jobs, see the
Cron Jobs
documentation.
appcfg cron_info
displays a summary of the scheduled task configuration, and the expected times of the next few runs.
Downloading source code
You can download an application's source code by running appcfg.py with the
download_app
action in the Python SDK command-line tool:
appcfg.py download_app -A <your_app_id> -V <your_app_version> <output-dir>
Output like the following results if the command is successful:
Getting file list...
Email: <admin-id>@example.com
Password for <admin-id>@example.com:
Fetching files...
Getting files...
[1/5] request.py
[2/5] login.py
[3/5] static/screen.css
[4/5] static/print.css
[5/5] images/bird.png
Only the developer who uploaded the code and the application owner(s) can download it. If anyone other than these parties attempts to download the app, they'll see an error message like the following:
Fetching file list...
Email: [email protected]
Password for [email protected]:
Error 403: --- begin server output ---
You do not have permission to download this app version.
--- end server output ---
If you are listed as an owner or a developer for an application, you can permanently disable code downloads from the Versions screen in your development web server. On that page, click permanently prohibit code downloads :
Downloading logs
App Engine maintains a log of messages that your application emits using the
logging
module from the Python standard library, as well as other messages printed to the standard error stream.
App Engine also records
each request in the log. Each
log level
has a fixed buffer size that controls the amount of log information you can access. Normally, you use logging features more at lower log levels; thus, the time window is smaller for log events at these levels. Each request logged is assigned a
request ID
, a globally unique identifier based on the request's start time. You can browse your app's logs of the last 90 days from the "Logs" section of
the Admin Console
.