HBNetwork / python-decouple

Strict separation of config from code.
MIT License
2.79k stars 192 forks source link

allow custom config file #113

Closed romado77 closed 3 years ago

romado77 commented 3 years ago

Proposed enhancement allows to pickup configuration file instead of going through fixed list of .env and settings.ini. For example staging environment could have configuration in stage.env, while development environment in dev.env.

Environment could be chosen by following:

test.py

from decouple import config

config.config_file('dev.env')

BROKER_URL = config("BROKER_URL")

dev.env

# Broker settings
BROKER_URL=https://dev-broker.com
heljhumenad commented 3 years ago

You want to create an different env file based on the environment which user or developer make or use in each of his/her development

romado77 commented 3 years ago

You want to create an different env file based on the environment which user or developer make or use in each of his/her development

That is the idea

heljhumenad commented 3 years ago

You want to create an different env file based on the environment which user or developer make or use in each of his/her development

That is the idea

Its nice so we can isolate an .env for production and development branch

henriquebastos commented 3 years ago

Hi. I don’t understand why would this be useful because this change would couple your code with the instance configuration which is precisely what we avoid.

Python decouple works by enabling you to have one code that works in any instance without change.

The proper way to achieve the desired behavior is not via decouple, but outside your source code.

You could have your env files in a contrib dir like contrib/dev.env, contrib/production.env and have a run script that copy the desired file as your .env and executes your code.

This would enable you to have one source code for any instance and enable you to choose between env files.