Class Documentation

This page documents the contents of the library.

Confire Module

A simple app configuration scheme using YAML and class based defaults.

confire.get_version()[source]

Returns a string containing the version number

Config Module

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.

class confire.config.Configuration[source]

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!

configure(conf={})[source]

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.

get(key, default=None)[source]

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).

classmethod load(klass)[source]

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.

options()[source]

Returns an iterable of sorted option names in order to loop through all the configuration directives specified in the class.

confire.config.environ_setting(name, default=None, required=True)[source]

Fetch setting from the environment. The bahavior of the setting if it is not in environment is as follows:

  1. If it is required and the default is None, raise Exception
  2. If it is requried and a default exists, return default
  3. If it is not required and default is None, return None
  4. If it is not required and default exists, return default

Exceptions

Exceptions hierarchy for Confire

exception confire.exceptions.ConfigurationMissing[source]

Warn the user that an optional configuration is missing.

exception confire.exceptions.ConfireException[source]

Base class for configuration exceptions.

exception confire.exceptions.ConfireWarning[source]

Base class for configuration warnings.

exception confire.exceptions.ImproperlyConfigured[source]

The user did not properly set a configuration value.

Examples

This file is an example file that you might put into your code base to have a configuration library at your fingertips!

class confire.example.DatabaseConfiguration[source]

This object contains the default connections to a Postgres Database.

class confire.example.ExampleConfiguration[source]

This object contains an example configuration.

debug: allow debug checking testing: are we in testing mode?

Table Of Contents

Previous topic

Configuring Apps with Confire

Next topic

Changelog

This Page