configs Package

configs Package

Configs

Configs is an INI configuration parsing package, written for humans.

Basic usage

Load a config file:

>>> import configs
>>> c = configs.load('sample.conf')
>>> c['general']
{'foo': 'baz'}

Load a config file with a fallback config file (with default values):

>>> fc = configs.load('sample.conf', fallback_file='default.conf')
>>> fc['general']['spam']
eggs

See the full documentation at configs.rtfd.org.

The repo is at bitbucket.org/moigagoo/configs.

api Module

configs.api

This module implements the configs API.

configs.api.load(config_file, fallback_file=None, defaults={})[source]

Constructs and returns a Config instance.

Parameters:
  • config_file – configuration file to be parsed
  • fallback_file – (optional) fallback configuration file with default values to be used if missing in the config_file
  • defaults – (optional) dict of default values to be used if missing in both config_file and fallback_file

Usage:

>>> import configs

>>> fc = configs.load('sample.conf', fallback_file='default.conf')

>>> fc['general']['spam']
eggs

config Module

configs.config

This module contains the Config class.

class configs.config.Config(config_file, fallback_file=None, defaults={})[source]

Bases: builtins.object

Parsed configuration.

Config instance includes a list of Section instances.

get(key)[source]

Tries to get a value from the root section dict_props by the given key.

Parameters:key – lookup key.
Returns:value if key exists, None otherwise.
get_config()[source]

Gets all section items.

load(config_file)[source]

Parse an INI configuration file.

Parameters:config_file – configuration file to be loaded.
Returns:Config instance.

section Module

configs.section

This module contains the Section class.

class configs.section.Section[source]

Bases: builtins.object

INI configuration section.

A Section instance stores both key-value and flag items, in dict_props and list_props attributes respectively.

It is possible to iterate over a section; flag values are listed first, then key-value items.

get(key)[source]

Tries to get a value from the dict_props by the given key.

Parameters:key – lookup key.
Returns:value if key exists, None otherwise.
get_section()[source]

Gets section values.

If section contains only flag values, a list is returned.

If section contains only key-value items, a dictionary is returned.

If section contains both flag and key-value items, a tuple of both is returned.

Table Of Contents

Previous topic

API Docs

This Page