Created
April 29, 2015 22:54
-
-
Save gcarothers/758e200f730e1e1efb30 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def engine_from_environ(prefix, settings, application_name=None): | |
"""Setup an SQLAlchemy engine with overrides from environment. | |
Maps KEYS_LIKE_THIS to keys.like.this""" | |
env_prefix = prefix.replace('.', '_').upper() | |
for env in os.environ: | |
if env.startswith(env_prefix): | |
key = env.replace('_', '.').lower() | |
settings[key] = os.environ[env] | |
if application_name is not None: | |
sqlalchemy_url = prefix + 'url' | |
settings[sqlalchemy_url] = add_application_name( | |
settings[sqlalchemy_url], | |
application_name, | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment