HBNetwork / python-decouple

Strict separation of config from code.
MIT License
2.83k stars 196 forks source link

Option to set a prefix to environment variables #32

Closed felipemfp closed 6 years ago

felipemfp commented 7 years ago

Hey, thanks for this amazing library.

I think that a option to set a prefix to environment variables is missing. You see, sometimes we have so many projects deployed on a single machine, that requires some settings between them.

~Perhaps I can use Docker to handle this, but Docker requires a kernel upgrade.~

Since this repository does not have a CONTRIBUTING.md, can I implement my needs and submit a PR?

henriquebastos commented 7 years ago

I do deploy many projects to a single machine, but for security reasons I create one linux user for each project isolating all the environments.

If you must deploy everything within a single user, I recommend you to use an ini or .env file.

If you must use prefixes, I would recommend something like:

from decouple import config as decouple_config

def prefixed_config(prefix):
    def config(option, default, cast):
        prefixed_option = prefix + option
        return decouple_config(prefixed_option, default, cast)
    return config

config = prefixed_config('MYPROJECT_')

DEBUG = config('DEBUG', default=False, cast=bool)

I'm not convinced this is a good practice. Seems like a solution for a devops design problem.

PS: Added instructions to contribution to the readme. Tks.