Python decouple is frequently used within Python Web Frameworks (e.g. Django or Flask) to store instance settings, so they can be changed without the need of redeploying the whole project or app.
Decouple claims to work better than enviromental variables. Here's an example:
Let's say you have an envvar
DEBUG=False
. If you run:if os.environ['DEBUG']: print True else: print False
It will print
True
, becauseos.environ['DEBUG']
returns the string"False"
. Since it's a non-empty string, it will be evaluated asTrue
.
Decouple addresses this caveats by allowing casting of values:
config('DEBUG', cast=bool)