Skip to content

Instantly share code, notes, and snippets.

@mattupstate
Last active January 4, 2016 03:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattupstate/8559844 to your computer and use it in GitHub Desktop.
Save mattupstate/8559844 to your computer and use it in GitHub Desktop.
A helper function for grabbing pseudo-namespaced configuration options from a Flask application
def namespaced_config_options(app, prefix):
"""Returns a dictionary of configuration options built from
the specified Flask application and string prefix. Keys in the
resulting dictionary will be lowercase.
:param app: a Flask application
:param prefix: a configuration namespace prefix. e.g. `IMAGE_STORE`
"""
rv = {}
for key, value in app.config.iteritems():
if not key.startswith(prefix):
continue
rv[key[len(prefix):].lower()] = value
return rv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment