cfgparse -- python configuration file parser module

Dan Gass (dan.gass@gmail.com)

Version 1.2

Download Source and Documentation: https://sourceforge.net/projects/cfgparse

Requires Python 2.3 -or- Python 2.2 and textwrap module from 2.3

cfgparse is a more convenient, flexible, and powerful module for parsing configuration files than the standard library ConfigParser module. cfgparse uses a more declarative style modelled after the popular optparse standard library module.

cfgparse can optionally cooperate with the optparse module to provide coordination between command line and configuration file options. In addition, the cooperation can be used to allow the user to control features of the parser from the command line.

If you like this module and want to see it in the standard Python distribution, please take the time and add your comments to the Python Configuration File Parser Shootout wiki: http://www.python.org/moin/ConfigParserShootout.

Standard Features

Advanced Features

For example:

# file: intro.ini
retries = 10

And script:

# file: intro.py
import cfgparse
c = cfgparse.ConfigParser()
c.add_option('retries', type='int')
c.add_file('intro.ini')
opts = c.parse()
print 'Number of retries:',opts.retries

Results in:

$ python intro.py
Number of retries: 10