Skip to main content

Library for reading configuration from file and environment

Project description

module mergeconf

mergeconf - build a single configuration by merging multiple configuration sources with order of precedence, based on immediacy. Currently: Default values are overridden by values read from configuration file which in turn are overridden by values read from environment variables.

class MergeConf

Configuration class. Initialized optionally with configuration items, then additional items may be added explicitly (and must be if they are mandatory, a specific type, etc.). Once all items have been added the configuration is finalized with parse(), validation checks are performed, and the realized values can be extracted.

function __init__

Initializes MergeConf class.

Args:

  • codename (str): Simple string which is assumed to prefix any related environment variables associated with the configuration (along with an underscore as separator), in order to avoid collisions in the environment's namespace. For example, for an app_name configuration key, with a codename MYAPP, the corresponding environment variable would be MYAPP_APP_NAME.
  • map (dict): Configuration options which are neither mandatory nor of a specified type, specified as key, value pairs.

Note: The map argument is probably to be deprecated and removed at a later date. Its utility is limited and should be avoided.

function add

Add a configuration item.

Args:

  • key (str): Name of configuration item
  • value (whatever): Default value, None by default
  • mandatory (boolean): Whether item is mandatory or not, defaults to False.
  • type (type): Type of value

function add_boolean

Deprecated. Add a configuration item of type Boolean.

Args:

  • key (str): Name of configuration item
  • value (boolean): Default value, None by default
  • mandatory (boolean): Whether item is mandatory or not, defaults to False.

Note: This is deprecated; simply use add with type=bool. This will be removed in a future release.

function parse

Takes configuration definition and default configuration file and reads in configuration, overriding default values. These are in turn overridden by corresponding variables found in the environment, if any. Basic validations are performed.

Args:

  • default_config_file (str): Path to default configuration file. This may be overridden if an alternative configuration file is specified in the environment.

Returns: A dict of key-value configuration items.

class MergeConfValue

Basic configuration item and base class for more complex types.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mergeconf-0.3.tar.gz (5.5 kB view hashes)

Uploaded Source

Built Distribution

mergeconf-0.3-py3-none-any.whl (6.9 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page