{"library":"configparser","title":"Configparser","description":"Configparser is a Python standard library module (also available as a backport for earlier Python versions) that provides tools for handling configuration files in INI format. It allows you to read, write, and manage user-editable configuration files, supporting features like sections, key-value pairs, default values, and value interpolation. The current backport version is 7.2.0 and it's actively maintained, periodically syncing with upstream CPython changes, making its features largely consistent with recent Python standard library versions.","status":"active","version":"7.2.0","language":"en","source_language":"en","source_url":"https://github.com/jaraco/configparser","tags":["configuration","ini","parser","stdlib","backport"],"install":[{"cmd":"pip install configparser","lang":"bash","label":"Install the backport"}],"dependencies":[{"reason":"Required by the latest version of the backport library.","package":"Python","optional":false}],"imports":[{"note":"The module was renamed from `ConfigParser` to `configparser` in Python 3. `import configparser` followed by `configparser.ConfigParser()` is also common and correct.","wrong":"import ConfigParser","symbol":"ConfigParser","correct":"from configparser import ConfigParser"}],"quickstart":{"code":"import configparser\nimport os\n\n# Create a configuration file programmatically\nconfig = configparser.ConfigParser()\nconfig['DEFAULT'] = {\n    'ServerAliveInterval': '45',\n    'Compression': 'yes',\n    'ForwardX11': 'yes'\n}\nconfig['production.server'] = {\n    'User': 'prod_user',\n    'Port': '50022',\n    'ForwardX11': 'no'\n}\n\nconfig_file_path = 'example.ini'\nwith open(config_file_path, 'w') as configfile:\n    config.write(configfile)\n\nprint(f\"Configuration written to {config_file_path}\")\n\n# Read the configuration file\nread_config = configparser.ConfigParser()\nread_config.read(config_file_path)\n\n# Access values using dictionary-like syntax\nprint(f\"Compression for DEFAULT: {read_config['DEFAULT']['Compression']}\")\nprint(f\"User for production.server: {read_config['production.server']['User']}\")\n\n# Get a value with fallback\nport = read_config.get('development.server', 'Port', fallback='22')\nprint(f\"Port for development.server (with fallback): {port}\")\n\n# Clean up the created file\nos.remove(config_file_path)\nprint(f\"Cleaned up {config_file_path}\")","lang":"python","description":"This quickstart demonstrates how to create a configuration, write it to an INI file, and then read values back using the `ConfigParser` class. It shows basic section and option access, as well as using fallback values for non-existent options."},"warnings":[{"fix":"Use `configparser.ConfigParser()` directly. The `read()` method now takes a path-like object or a list of path-like objects.","message":"The `SafeConfigParser` class and the `filename` parameter in `read()` were removed in version 6.0.0. The main `ConfigParser` class now incorporates the features previously found in `SafeConfigParser`.","severity":"breaking","affected_versions":">=6.0.0"},{"fix":"On Python versions 3.9+, always use the standard library's `configparser`. The `pip install configparser` package is primarily for older Python versions (e.g., 3.6-3.8) to get updated features, or for specific pinning scenarios on newer Pythons where the stdlib version is masked by design.","message":"As of version 7.0.0, the `configparser` top-level name from the backport package is removed for Python versions where `configparser` is already in the standard library (Python 3.9+). This ensures consistency with the standard library module.","severity":"breaking","affected_versions":">=7.0.0"},{"fix":"Instead of `config['section']['key']`, use `config.getint('section', 'key')`, `config.getfloat('section', 'key')`, or `config.getboolean('section', 'key')`. Boolean values are case-insensitive and recognize '1', 'yes', 'true', 'on' as `True` and '0', 'no', 'false', 'off' as `False`.","message":"ConfigParser treats all values as strings by default. To retrieve values as specific data types (integers, floats, booleans), use the dedicated `getint()`, `getfloat()`, and `getboolean()` methods.","severity":"gotcha","affected_versions":"All"},{"fix":"Always refer to options using lowercase for consistency, or be aware that `config['Section']['Key']` and `config['Section']['key']` will access the same value (assuming 'Section' matches case-sensitively).","message":"Option names (keys) within sections are case-insensitive and are normalized to lowercase when accessed via dictionary-like syntax. However, section names *are* case-sensitive.","severity":"gotcha","affected_versions":"All"},{"fix":"Access `DEFAULT` section options directly via `config.get('section', 'option', fallback=config['DEFAULT']['option'])` or treat `config['DEFAULT']` as a separate dictionary.","message":"The special `[DEFAULT]` section, while providing default values for other sections, is not returned by `config.sections()` or `config.has_section()`.","severity":"gotcha","affected_versions":"All"},{"fix":"For Python 3.9 and newer, rely on the standard library `configparser` module unless you have a specific reason to install the backport (e.g., to access features not yet in your Python version's stdlib or for version pinning). For Python versions 2.6-3.8, `pip install configparser` (an older version of the backport) is necessary to use modern `configparser` features.","message":"The `configparser` package is a backport. While `pip install configparser` works on Python >= 3.9 (as per its `requires_python` metadata), the module `configparser` is built into the standard library for all Python 3.x versions. Installing the backport on Python 3.9+ is often redundant unless specific backport features or fixes are needed that aren't yet in the stdlib of that particular Python version.","severity":"gotcha","affected_versions":"All, particularly Python >= 3.9"}],"env_vars":null,"last_verified":"2026-04-06T00:00:00.000Z","next_check":"2026-07-05T00:00:00.000Z"}