Mandrel provides bootstrapping and configuration tools for consistent, straightforward project config management.
Use Mandrel to:
- bootstrap your python project configuration
- manage configuration file location/access
- manage logging configuration and Logger retrieval
Separate projects can rely on Mandrel for these purposes, and when they're brought together (as eggs, for instance) to a single application, their configuration can be managed simply in an easily-configurable way.
Why and how?
Suppose you want to be able to look for configuration files across several directories, in order of precedence:
Suppose further that you have one aspect of your app that deals with storage, and another that deals with analysis. You configure them separately.
So at the root of your project, you would add a file named
and in it you would say:
Now name your YAML configuration files for the subsections of your app:
You can easily load configuration dictionaries from YAML files if those files exist on the bootstrap.SEARCH_PATH:
analysis_config = mandrel.config.get_configuration('analysis') storage_config = mandrel.config.get_configuration('storage')
If you want a standard configuration system-wide, put it in /etc/whizzies.
But then if you want a configuration for a particular user, put it in ~user/.whizzies. That will completely override the system-wide one when present.
And of course, the SEARCH_PATH just looks in the current working directory, so the most-specific config can go there, again completely overruling the lower-precedence config.
logging.cfg file can be placed somewhere in the search
path, and you can use
get loggers. The bootstrapper will ensure that logging config is
Take it farther:
class StorageConfig(mandrel.config.Configuration): NAME = 'storage'
StorageConfig class easily wraps the lookup of "storage.yaml",
and makes the key/value pairs therein available as attributes on a
Add functionality to your class to enforce particular defaults, ensure values are properly formatted, constrained, etc.
You can fetch a logger named "storage" from it, too:
logger = StorageConfig.get_logger()
Mandrel is free software and is released under the terms of the MIT license (http://opensource.org/licenses/mit-license.php), as specified in the accompanying LICENSE.txt file.