English ▼
Skip to page content Skip to main navigation
e.g. "templates" or "datastore"

# Functions

This Backends API allows you to retrieve information about the backend handling the current request, and compute the URL and hostname of any other backend or backend instance within the same application. The methods in this API work in both production and the development server.

The `google.appengine.api.backends` package provides the following functions:

get_backend()

  Gets the name (`BACKEND_ID`) of the backend handling the current request. Returns `None` if the request is not handled by a backend.

get_hostname(backend=None, instance=None)

  Returns the hostname of the backend or backend instance.

  backend=None
    The optional backend name, a string. You can identify the name of a backend handling a request using get_backend(). Specifying `backend=None` returns the current backend; this is the default behavior.
  instance=None
    The optional backend instance id, an integer. You can identify the instance id using get_instance(). If provided, the hostname represents the specific instance. If absent, the hostname represents the backend as a whole. Raises the InvalidInstanceError if the instance id is not an integer.
get_instance()

  Gets the id (`INSTANCE_ID`) for the instance handling the current request. Returns the instance ID (numbering starts at `0`), or `None` if the request is not handled by a backend.

get_url(backend=None, instance=None, protocol='HTTP')

  Gets the address of a specific backend. Returns a local address if run in the development server, or a production address if run in production. Returns the HTTP or HTTPS address of a specific backend.

  Arguments:

  backend=None
    The optional backend name. You can identify the name of a backend handling a request using get_backend(). Specifying `backend=None` returns the current backend; this is the default behavior.
  instance=None
    The optional backend instance id, an integer. If provided, the URL targets the specific instance. If absent, the URL points to a load-balancing hostname for the backend. You can identify the instance id using get_instance(). Raises the InvalidInstanceError if the instance id is not an integer.
  protocol='http'
    The protocol to use, either `HTTP` (default) or `HTTPS`. The development server supports only `HTTP`. Production supports both `HTTP` and `HTTPS`. Raises the InvalidBackendError if the provided backend cannot be found.