2

Just wondering locally, I could access environment variables within google app engine? For example, I've stored an email and password and would like to access it like this:

import os

email = os.environ.get("EMAIL")
password = os.environ.get("PASSWORD")

Is there any way to do this?

Mmm Donuts
  • 9,551
  • 6
  • 27
  • 49

1 Answers1

2

You can define variables in app.yaml to make them available to the os.environ dictionary:

env_variables:
  EMAIL: 'email@example.com'

Then access the variable with:

email = os.environ.get("EMAIL")

More info is in the documentation.

Jeff Deskins
  • 1,650
  • 1
  • 10
  • 9
  • I could, but wouldn't that get committed onto git? I'm trying to keep sensitive data on each developers personal machine. – Mmm Donuts Aug 21 '15 at 21:38
  • Check this out: http://stackoverflow.com/questions/22669528/securely-storing-environment-variables-in-gae-with-app-yaml – Sandeep Dinesh Aug 21 '15 at 22:04
  • If you don't want these values in source code the store it in the datastore and load and cache it on instance startup. It also means you can change these values without deploying new code. though you would have to kill the instance to invalidate the cache, or have a handler you can call to invalidate it. – Tim Hoffman Aug 22 '15 at 00:55