Updated configparser from stdlib for earlier Pythons with enhanced configuration file parsing capabilities.
npx @tessl/cli install tessl/pypi-configparser@7.2.0Updated configparser from stdlib for earlier Pythons with enhanced configuration file parsing capabilities. This backport provides the same interface as Python's standard library configparser module while offering enhanced features and maintaining compatibility across Python versions.
pip install configparserfrom backports import configparserAccess specific classes:
# All classes are accessed through the configparser module
config = configparser.ConfigParser()
raw_config = configparser.RawConfigParser()from backports import configparser
# Create a parser instance
config = configparser.ConfigParser()
# Read configuration from file
config.read('config.ini')
# Access sections and options
sections = config.sections()
options = config.options('section_name')
# Get values with type conversion
value = config.get('section_name', 'option_name')
number = config.getint('section_name', 'numeric_option')
flag = config.getboolean('section_name', 'boolean_option')
# Set values
config.add_section('new_section')
config.set('new_section', 'new_option', 'value')
# Write configuration to file
with open('output.ini', 'w') as f:
config.write(f)
# Dictionary-style access
config['section']['option'] = 'new_value'
value = config['section']['option']ConfigParser follows a hierarchical design:
This design enables flexible configuration file handling with support for various formats, interpolation styles, and access patterns while maintaining backward compatibility with the standard library.
Core configuration parser classes providing the main functionality for reading, writing, and manipulating configuration files.
class ConfigParser(RawConfigParser): ...
class RawConfigParser(MutableMapping): ...
class SectionProxy(MutableMapping): ...
class ConverterMapping(MutableMapping): ...Methods for reading configuration data from various sources (files, strings, dictionaries) and writing configuration data to files.
def read(filenames, encoding=None): ...
def read_file(f, source=None): ...
def read_string(string, source='<string>'): ...
def read_dict(dictionary, source='<dict>'): ...
def write(fp, space_around_delimiters=True): ...Operations for managing configuration sections including creation, removal, and validation of sections.
def sections(): ...
def add_section(section): ...
def remove_section(section): ...
def has_section(section): ...Methods for accessing, setting, and managing configuration options with type conversion support.
def get(section, option, *, raw=False, vars=None, fallback=_UNSET): ...
def getint(section, option, *, raw=False, vars=None, fallback=_UNSET, **kwargs): ...
def getfloat(section, option, *, raw=False, vars=None, fallback=_UNSET, **kwargs): ...
def getboolean(section, option, *, raw=False, vars=None, fallback=_UNSET, **kwargs): ...
def set(section, option, value=None): ...
def has_option(section, option): ...Value substitution capabilities allowing dynamic configuration values that reference other options within the same configuration.
class Interpolation: ...
class BasicInterpolation(Interpolation): ...
class ExtendedInterpolation(Interpolation): ...Complete exception hierarchy for handling various configuration parsing and access errors.
class Error(Exception): ...
class NoSectionError(Error): ...
class DuplicateSectionError(Error): ...
class NoOptionError(Error): ...
class InterpolationError(Error): ...
class ParsingError(Error): ...Module-level constants used throughout the configparser library.
DEFAULTSECT = "DEFAULT"
MAX_INTERPOLATION_DEPTH = 10
UNNAMED_SECTION = _UnnamedSection()