I'm trying to configure Celery using an external file, to separate config from code. Both Celery and Flask have config.from_envvar() / config_from_envvar()
methods except they behave a bit differently and what I am doing only works with Flask.
Flask
Basically, in Flask, I do
app.config.from_object(config_class)
app.config.from_envvar('SETTINGS_FILE', silent=True)
which loads a default configuration stored in application code, then loads a settings file stored anywhere in the filesystem with a few customized settings overriding those in the default file. I just need to write that file and pass its path through an environment variable.
(More on this in Flask docs or in this answer. I find it a bit ambiguous that Flask treats the file as a Python file while the example uses settings.cfg
(no .py
extension) but it works fine).
Celery
When doing the same with Celery, I get this error:
ImportError: No module named '/absolute/path/to/settings'
I named the file settings.py
(.py
extension, in case it matters).
I don't know where to put that file. The examples I've seen, for instance in answers to this question, put the config file in the code, which is precisely what I would like to avoid.