This page documents the contents of the library.
A simple app configuration scheme using YAML and class based defaults.
Prints the version.
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.
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.
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).
Insantiates the configuration by attempting to load the configuration from YAML files specified by the CONF_PATH module variable. This should be the main entry point for configuration.
Returns an iterable of sorted option names in order to loop through all the configuration directives specified in the class.
environ_setting(name, default=None, required=True)¶
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
Warn the user that an optional configuration is missing.
Base class for configuration exceptions.
Base class for configuration warnings.
The user did not properly set a configuration value.
This file is an example file that you might put into your code base to have a configuration library at your fingertips!
This object contains the default connections to a Postgres Database.
This object contains an example configuration.
debug: allow debug checking testing: are we in testing mode?