In Python, how can I test if I'm in Google App Engine SDK?

See: https://cloud.google.com/appengine/docs/python/how-requests-are-handled#Python_The_environment

The following environment variables are part of the CGI standard, with special behavior in App Engine: SERVER_SOFTWARE:

In the development web server, this value is "Development/X.Y" where "X.Y" is the version of the runtime.

When running on App Engine, this value is "Google App Engine/X.Y.Z".


Based on the same trick, I use this function in my code:

def isLocal():
    return os.environ["SERVER_NAME"] in ("localhost", "www.lexample.com")

I have customized my /etc/hosts file in order to be able to access the local version by prepending a "l" to my domain name, that way it is really easy to pass from local to production.

Example:

  • production url is www.example.com
  • development url is www.lexample.com