What is the best practice for injecting configuration into a python application
I am working on a Flask App. I have a configuration class defined which has configs for Dev, Qa, Prod and Test. I followed the common practice of reading the config file only once and initialising the app with the config data

app.config.from\_object(config object)

Now I need to access urls defined in the config class in other places. I tried accessing these configs using the current app proxy. But I realised that I also have to access these class outside the request/ app context as I have celery tasks which access them.

One approach is to pass this config as a variable to every class it is required, which I dont prefer. Another option is to annotate the config class as singleton and create the config object at every place where I need them.  I also came across this library called Dependency\_Injector. [https://python-dependency-injector.ets-labs.org/](https://python-dependency-injector.ets-labs.org/) This seems a bit heavy weight for my use case though. I am looking forward to know how other solve this problem

Edit: I should add that I am already using environment variables. I create. the config object based on the value of the env vars.