ANN: config module v0.3.4 released

Vinay Sajip vinay_sajip at
Thu Nov 11 23:22:49 CET 2004

A new version of the Python config module has been released.

What Does It Do?
The config module allows you to implement a hierarchical configuration
scheme with support for mappings and sequences, cross-references
between one part of the configuration and another, the ability to
flexibly access real Python objects, facilities for configurations to
include and cross-reference one another, simple expression evaluation
and the ability to change, save, cascade and merge configurations. You
can easily integrate with command line options using optparse.

This module has been developed on python 2.3 but should work on
version 2.2 or greater. A test suite using unittest is included in the

A very simple configuration file (simple.cfg):

# starts here
message: Hello, world!
#ends here

a very simple program to use it:

from config import Config

cfg = Config(file('simple.cfg'))
print cfg.message

results in:

Hello, world!

Configuration files are key-value pairs, but the values can be
containers that contain further values.

A simple example - with the example configuration file: 

    stream : `sys.stderr`
    message: 'Welcome'
    name: 'Harry'
    stream : `sys.stdout`
    message: 'Welkom'
    name: 'Ruud'
    stream : $messages[0].stream
    message: 'Bienvenue'
    name: Yves

a program to read the configuration would be:

from config import Config

f = file('simple.cfg')
cfg = Config(f)
for m in cfg.messages:
    s = '%s, %s' % (m.message,
        print >>, s
    except IOError, e:
        print e

which, when run, would yield the console output:

Welcome, Harry
Welkom, Ruud
Bienvenue, Yves

The above example just scratches the surface. There's more information
about this module available at

Comprehensive API documentation is available at

As always, your feedback is most welcome (especially bug reports,
patches and suggestions for improvement). Enjoy!


Vinay Sajip
Red Dove Consultants Ltd.

Changes since the last release posted on comp.lang.python:
Added ConfigInputStream to provide better Unicode support.
Added ConfigReader.setStream().
Renamed config.get() to getByPath(), and likewise for ConfigList.
Added Mapping.get() to work like dict.get().
Added and logconfig.cfg to distribution.
Simplified parseMapping().
Allowed Config.__init__ to accept a string as well as a stream. If a
string is passed in, streamOpener is used to obtain the stream to be
Changed addNamespace/removeNamespace to make name specification
Refactored save(), added Container.writeToStream and
Container.writeValue() to help with this.

More information about the Python-announce-list mailing list