This page documents the contents of the library.
A simple app configuration scheme using YAML and class based defaults.
Confire class for specifying Confire specific optional items via a YAML configuration file format. The main configuration class provides utilities for loading the configuration from disk and iterating across all the settings. Subclasses of the Configuration specify defaults that can be updated via the configuration files.
General usage:
from confire.conf import settings mysetting = settings.get(‘mysetting’, default)
You can also get settings via a dictionary like access:
mysetting = settings[‘mysetting’]
However, this will raise an exception if the setting is not found.
Note: Keys are CASE insensitive
Note: Settings can be modified directly by settings.mysetting = newsetting however, this is not recommended, and settings should be fetched via the dictionary-like access.
Base configuration class specifies how configurations should be handled and provides helper methods for iterating through options and configuring the base class.
Subclasses should provide defaults for the various configurations as directly set class level properties. Note, however, that ANY directive set in a configuration file (whether or not it has a default) will be added to the configuration.
Example:
class MyConfig(Configuration):
mysetting = True logpath = “/var/log/myapp.log” appname = “MyApp”
The configuration is then loaded via the classmethod load:
settings = MyConfig.load()
Access to properties is done two ways:
settings[‘mysetting’] settings.get(‘mysetting’, True)
Note: None settings are not allowed!
Allows updating of the configuration via a dictionary of configuration terms or a configuration object. Generally speaking, this method is utilized to configure the object from a JSON or YAML parsing.
Fetches a key from the configuration without raising a KeyError exception if the key doesn’t exist in the config, instead it returns the default (None).
Fetch setting from the environment. The bahavior of the setting if it is not in environment is as follows:
- If it is required and the default is None, raise Exception
- If it is requried and a default exists, return default
- If it is not required and default is None, return None
- If it is not required and default exists, return default
Exceptions hierarchy for Confire