Notice: Over the next few months, we're reorganizing the App Engine documentation site to make it easier to find content and better align with the rest of Google Cloud products. The same content will be available, but the navigation will now match the rest of the Cloud products. If you have feedback or questions as you navigate the site, click Send Feedback.

Python 2 is no longer supported by the community. We recommend that you migrate Python 2 apps to Python 3.

Using the Modules API

Stay organized with collections Save and categorize content based on your preferences.

The Modules API provides functions that return information about the current operating environment (module, version, and instance).

The Modules API also has functions that retrieve the address of a module, a version, or an instance. This allows an application to send requests from one instance to another, in both the development and production environments.

You must import the google.appengine.api.modules module from the SDK.

from google.appengine.api import modules

The following code sample shows how to get the module name and instance id for a request:

module = modules.get_current_module_name()
instance_id = modules.get_current_instance_id()
self.response.write(
    'module_id={}&instance_id={}'.format(module, instance_id))

The instance ID of an automatic scaled module will be returned as a unique base64 encoded value, e.g. e4b565394caa.

You can communicate between modules in the same app by fetching the hostname of the target module:

backend_hostname = modules.get_hostname(module='my-backend')
url = "http://{}/".format(backend_hostname)
try:
    result = urllib2.urlopen(url).read()
    self.response.write('Got response {}'.format(result))
except urllib2.URLError:
    pass

You can also use the URL Fetch service.