GAE: Application Run time environment in Python 3

160 views
Skip to first unread message

Sajal Gupta

unread,
Dec 22, 2021, 12:52:11 AM12/22/21
to Google App Engine
Hi,

Python 2,7 had the option to specify run time environment as follows:

if os.getenv('SERVER_SOFTWARE', '').startswith('Google App Engine/'):
  # Production
else:
  # Local development server


The above does not seem to work in Python 3. Is there an equivalent in python 3 for the same?

Thanks

Felipe Bergallo Corral

unread,
Dec 22, 2021, 4:20:35 AM12/22/21
to Google App Engine
If you're looking for the Python3 equivalent of that command, I believe I found your answer here

In short, it's the platform library, platform.system gives the OS and platform.release gives the version.
Alternatively, there's the os library and the sys library.

Sajal Gupta

unread,
Dec 23, 2021, 2:33:53 AM12/23/21
to Google App Engine
Thanks Felipe. Actually I was looking for another variable and found it at this link:


From this, I took the following code and it seems to work on localhost. Will try to cloud next and see what happens.

# module: appengine_config ... if os.getenv('GAE_ENV', '').startswith('standard'): pass else:

Maybe, the GAE documentation team can consider adding this info to Python 3 guide as it is there in python 2.7 guide.

Regards

Sajal

Felipe Bergallo Corral

unread,
Dec 24, 2021, 9:21:09 AM12/24/21
to Google App Engine
In which document is this found? Asking so I can report this if that's the case (and if there isn't already a feature request for this to be included, which I'd be surprised if there wasn't)

Sajal Gupta

unread,
Dec 24, 2021, 11:13:53 AM12/24/21
to google-a...@googlegroups.com
Please see this page: 

On this page, you can check the section on detecting application run time environment. 

I am suggesting that similar section be added for python 3 local development server page with the python 3 related key value. 

Regards

--
You received this message because you are subscribed to a topic in the Google Groups "Google App Engine" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-appengine/EpFWzENvdSs/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-appengi...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-appengine/6ff931e6-edb5-4330-a3db-104ad1aec35fn%40googlegroups.com.

Felipe Bergallo Corral

unread,
Dec 29, 2021, 9:57:42 AM12/29/21
to Google App Engine
Ok, for a moment I thought you meant that this section existing in one version of the document and not in the other, which might make sense if detecting the environment isn't necessary anymore for some reason, but in fact, it's there and it's blank. Thank you for letting us know, I'll create an issue on Issue Tracker and see about having that fixes (either remove it completely if it's not necessary or implement whatever codeblock is missing).
Reply all
Reply to author
Forward
0 new messages