To demonstrate the functionality of the App Engine Administration API, a sample Python client is provided. This example retrieves a list of applications, a list of modules for each app, and a list of versions for each of those modules.
Enable access to the API
You will need to enable access to the API for a Cloud project. Visit the Google Cloud Platform Console. Click on the name of the project which you would like to use.
If you do not have an existing Cloud project
- Click on 'Create Project.'
- If you'd like, you can replace the default name and ID with ones of your choice.
- Click 'Create' to create the project.
Enable the App Engine Admininistration API.
Authenticate with the Google Cloud SDK
This sample obtains authentication information from its environment via
application default credentials
The easiest way to do this is to use the Google Cloud SDK. On Linux/Mac OS X, you can install via:
$ curl https://sdk.cloud.google.com | bash
Once installed, authenticate your environment by running:
$ gcloud auth login
Note: Download and install the Google APIs Client Library for Python if it is not installed on your machine.
Save the following code to a file in the same directory as the JSON file:
# Copyright 2013 Google Inc. All Rights Reserved. """Demo client for the Google App Engine Administration API. This sample client demonstrates how to use the API and manipulate apps deployed on Google App Engine. """ __author__ = 'email@example.com (Sarmad Gilani)' from oauth2client.client import GoogleCredentials from googleapiclient.discovery import build def main(): # Authenticate and construct service. service = build('appengine', 'v1beta2', credentials=GoogleCredentials.get_application_default()) # Get a list of your applications. response = service.apps().list().execute() apps_list = response.get('apps', ) for app in apps_list: print 'App Title: ', app['title'] print 'App ID: ', app['appId'] # List all modules on the application. response = service.apps().modules().list( appId=app['appId']).execute() modules_list = response.get('modules', ) print ' Modules for this app:' for module in modules_list: print ' Module ID: ', module['moduleId'] # List all versions on this module. response = service.apps().modules().versions().list( appId=app['appId'], moduleId=module['moduleId']).execute() versions_list = response.get('versions', ) print ' Versions on this module: ' for version in versions_list: print ' Version ID: ', version['versionId'] print ' Runtime: ', version['runtime'] print ' Deployment Timestamp: ', version['deployedTimestamp'] if version['isDefault']: print ' ** This is the default version. **' if __name__ == '__main__': main()