Package: gae-env
gae_envConsole-visible environment variables for Google Appengine projectsOverviewBy default, GAE environment variables may beconfigured in the app.yaml fileor uploaded via a secrets.json.But, for sensitive data, you should not store it in source code as it will be checked into source control.
Even if you dont, the wrong people (inside your organization) may find it there.Also, your development environment probably uses different config values from your production environment.
If these values are stored in code, you will have to run different code in development and production, which is not just messy but also bad practice.gae_envreads environment variables fromCloud Datastore(and/or system environment variables). This way, it becomes more convenient to edit variables in theDeveloper's ConsoleUsage# coding: utf-8importgae_envfromgae_envimportValueNotSetError,NOT_SET_VALUEkey_foo='foo'# get the value stored at key 'key_foo'value_bar=gae_env.get(key_foo)# By default, values are of type str# get value as intvalue_bar=gae_env.get(key_foo,converter_class=int)# get value as floatvalue_bar=gae_env.get(key_foo,converter_class=float)# ******************************************************************************# If there is a value for a key in the system environment variables or datastore,# it will be returned.# Else, a place holder record will be created and ValueNotSetError exception will be raised.# The exception will remind you to go to the Developers Console# and update the placeholder record.# ******************************************************************************# The default error raising behaviour can be turned off with a param# get value without raising any ValueNotSetErrorvalue_bar=gae_env.get(key_foo,raise_value_not_set_error=False)# If no value has been set for a key and raise_value_not_set_error=False,# it will return NOT_SET_VALUE.# To return None instead, pass return_none_for_not_set_value=Truevalue_bar=gae_env.get(key_foo,raise_value_not_set_error=False,return_none_for_not_set_value=True)# There's a convenience method for setting the value of a key at runtime# NB: This sets the value in Cloud Datastore (not system environment variables)value_bar='bar'gae_env.set_value(name=key_foo,value=value_bar)How to set Datastore values in the App Engine console:Go to theconsole.Select your project at the top of the page if it's not already selected.In the Kind dropdown box, selectGaeEnvSettings.Your keys will show up. For those where an exception was raised, they will all have the value__NOT_SET__. Click each one and set its value.What if I am in development?Using the local admin server. This is usually started on the urlhttp://localhost:8000In the admin server page, go to theDatastore ViewerIn the EntityKind dropdown box, selectGaeEnvSettings.Your keys will show up. For those where an exception was raised, they will all have the value__NOT_SET__. Click each one and set its value.Alternatively, you can pass environment variables as arguments todev_appserver.py.The argument--env_var=...can be used to specify the environment variables to use when running the local development server.
Each env_var argument is in the format ofkey=value, and you can define multiple envrionment variables.
For example:--env_var=KEY_1=val1 --env_var=KEY_2=val2Dependenciesgae_envuses thendblibrary which usesMemCacheandCloud Datastoreunder the hood, so it's fast.But this also means it requires the context of a Google Appengine runtime in order to work, and can be used in Google Appengine projects onlyTestingThis project usesnose,nosegaeandcoveragefor testing.You must have these installed:pip install -r test_requirements.txtIn addition, you must have gcloud sdk installed, with google appengine enabled.Run:export GAE_LIB_ROOT=/path/to/local/google-cloud-sdk/platform/google_appengine/
python setup.py nosetests --gae-lib-root=$GAE_LIB_ROOTContributingFork it (https://github.com/Odame/gae-env/fork)Create your feature branch (git checkout -b feature/fooBar)Commit your changes (git commit -am 'Add some fooBar')Push to the branch (git push origin feature/fooBar)Create a new Pull Request