HBNetwork / python-decouple

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

Allow for Multiple Potential Env Var Names #131

Closed dstarner closed 2 years ago

dstarner commented 2 years ago

I am deploying an application to a few different cloud environments, where equivalent environment variables are not named the same.

To get around this, I wrote a small but super-useful multi_config that works the same way as config, but it takes in a variadic number of environment variable names to check. It iterates through these in order and returns the first matching & valid environment variable.

AWS_ACCESS_KEY_ID = multi_config('BUCKETEER_AWS_ACCESS_KEY_ID', 'S3_ACCESS_KEY_ID', cast=str, default=None)

I would like to upstream this to the package. I am creating a PR with the feature shortly and will use this issue as a reference.

henriquebastos commented 2 years ago

Hi. I too deploy to different cloud environments, but I'm always able to specify the env vars names. This seems to me that a design challenge on a lower level is being corrected with decouple. Since this is too specific and against the design decisions of the project, this should not be on upstream. If you find ppl interested, maybe you should publish a complimentary library.

tahayk commented 2 years ago

@dstarner I think the solution for this is:

AWS_ACCESS_KEY_ID = config('BUCKETEER_AWS_ACCESS_KEY_ID', default=config('S3_ACCESS_KEY_ID',default=None), cast=str)

you can wrap this in a function