or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

exception-handling.mdfile-operations.mdindex.mdinterpolation.mdoption-access.mdparser-classes.mdsection-management.md
tile.json

tessl/pypi-configparser

Updated configparser from stdlib for earlier Pythons with enhanced configuration file parsing capabilities.

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/configparser@7.2.x

To install, run

npx @tessl/cli install tessl/pypi-configparser@7.2.0

index.mddocs/

ConfigParser

Updated 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.

Package Information

  • Package Name: configparser
  • Language: Python
  • Installation: pip install configparser

Core Imports

from backports import configparser

Access specific classes:

# All classes are accessed through the configparser module
config = configparser.ConfigParser()
raw_config = configparser.RawConfigParser()

Basic Usage

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']

Architecture

ConfigParser follows a hierarchical design:

  • ConfigParser: Main parser class with interpolation support for %(name)s style substitutions
  • RawConfigParser: Base parser without interpolation, suitable for configuration files with literal % symbols
  • SectionProxy: Dictionary-like interface for accessing individual sections
  • Interpolation Classes: Handle value substitution (BasicInterpolation, ExtendedInterpolation)

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.

Capabilities

Parser Classes

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): ...

Parser Classes

File Operations

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): ...

File Operations

Section Management

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): ...

Section Management

Option Access

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): ...

Option Access

Interpolation

Value substitution capabilities allowing dynamic configuration values that reference other options within the same configuration.

class Interpolation: ...
class BasicInterpolation(Interpolation): ...
class ExtendedInterpolation(Interpolation): ...

Interpolation

Exception Handling

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): ...

Exception Handling

Constants

Module-level constants used throughout the configparser library.

DEFAULTSECT = "DEFAULT"
MAX_INTERPOLATION_DEPTH = 10
UNNAMED_SECTION = _UnnamedSection()
  • DEFAULTSECT: Name of the default section that applies to all other sections
  • MAX_INTERPOLATION_DEPTH: Maximum recursion depth for value interpolation
  • UNNAMED_SECTION: Special object representing the unnamed section when allow_unnamed_section=True