The ConfigParser Extension provides configuration handling based on the standard ConfigParser, and is the default configuration handler used by Cement.


  • No external dependencies.


This extension does not honor any application configuration settings.


from cement.core.foundation import CementApp

with CementApp() as app:

    # get a config setting
    app.config.get('myapp', 'foo')

    # set a config setting
    app.config.set('myapp', 'foo', 'bar2')

    # etc.
class cement.ext.ext_configparser.ConfigParserConfigHandler(*args, **kw)

Bases: cement.core.config.CementConfigHandler, ConfigParser.RawConfigParser

This class is an implementation of the IConfig interface. It handles configuration file parsing and the like by sub-classing from the standard ConfigParser library. Please see the ConfigParser documentation for full usage of the class.

Additional arguments and keyword arguments are passed directly to RawConfigParser on initialization.

class Meta

Handler meta-data.


alias of cement.core.config.IConfig

label = 'configparser'

The string identifier of this handler.


Parse a configuration file at file_path and store it.

Parameters:file_path – The file system path to the configuration file.
Returns:boolean (True if file was read properly, False otherwise)

Adds a block section to the config.

Parameters:section – The section to add.

Return a dict representation of a section.

Parameters:section – The section of the configuration. I.e. [block_section]
Returns:Dictionary reprisentation of the config section.
Return type:dict

Return a list of configuration sections or [blocks].

Returns:List of sections.
Return type:list

Return a list of keys within ‘section’.

Parameters:section – The config section (I.e. [block_section]).
Returns:List of keys in the section.
Return type:list
merge(dict_obj, override=True)

Merge a dictionary into our config. If override is True then existing config values are overridden by those passed in.

  • dict_obj – A dictionary of configuration keys/values to merge into our existing config (self).
  • override – Whether or not to override existing values in the config.