Manage dev/prod config in pure Python
I’d like to separate dev/test/prod environments :) so let’s see the real example.
Audience
Developers, DevOps Engineers, and SysAdmins.
Challenges
- Put configs in a simple format (JSON, YAML, …)
- Hide unnecessary config information from other envs
Structure
I will put my configs in “etc” folder in the root of the project:
config.yml
Then specify the current env inside “config.yml”, this is my config.yml file content:
config-dev.yml
Now I want to read the redis configuration from “config-dev.yml”:
config.py
It’s time to read these values inside python, this is my “config.py” file:
main.py
Now we need to load our config loader once then use it anywhere we like, add these lines to you main module:
The final word
The only issue is that you can not change the structure of “config.yml”, and the other files structures just depend on you.