Announcing the release of a new open source library: Confire is a simple but powerful configuration scheme that builds on the configuration parsers of Scapy, elasticsearch, Django and others. The basic scheme is to have a configuration search path that looks for YAML files in standard locations. The search path is hierarchical (meaning that system configurations are overloaded by user configurations, etc). These YAML files are then added to a default, class-based configuration management scheme that allows for easy development.
Full documentation can be found here: http://confire.readthedocs.org/
In a fit of procrastination, I put my first project on PyPI (the Python Package Index): Confire, a simple app configuration scheme using YAML and class based defaults. It was an incredible learning experience into the amount of work that goes into Python developers being simply able to
pip install something! I wanted to go the whole nine yards, and set up documentation on Read The Docs and an open source platform on Github and even though it took a while, it was well worth the effort!
There are many configuration packages available on PyPI – it seems that everyone has a different way of doing it. However, this is my prefered way, and I found that after I copy and pasted this code into more than 3 projects that it was time to add it as a dependency via PyPI. The configuration builds on what I’ve learned/done in configuring Scapy, elasticsearch, and Django – and builds on these principles:
- Configuration should not be Python (sorry Django). It’s too easy to screw stuff up, and anyway, you don’t want to deal with importing a settings file from /etc!
- Configuration should be on a per-system basis. This means that there should be an /etc/app.yaml configuration file as well as a $HOME/.app.yaml configuration file that overwrites the system defaults for a particular user. For development purposes there should also be a $(pwd)/app.yaml file so that you don’t have to sprinkle things throughout the system if not needed.
- Developers should be able to have reasonable defaults already written in code if no YAML file has been provided. These defaults should be added in an API like way that is class based and modularized.
- Accessing settings from the code should be easy.
So there you have it, with these things in mind I wrote confire and I hope you enjoy it!
The awesome details:
The regular details:
Needless to say, this means you can do the following:
pip install confire
Hopefully this means you will be able to quickly deploy sensible configuration defaults in your code!