{"id":1231,"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":"python","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,"search_vec":"'7.2.0':59 'activ':63 'allow':29 'also':9 'avail':10 'backport':13,56,86 'chang':70 'configpars':1,2 'configur':23,39,82 'consist':75 'cpython':69 'current':55 'default':49 'earlier':15 'edit':38 'featur':42,73 'file':24,40 'format':27 'handl':22 'ini':26,83 'interpol':53 'key':46 'key-valu':45 'larg':74 'librari':7,80 'like':43 'maintain':64 'make':71 'manag':35 'modul':8 'pair':48 'parser':84 'period':65 'provid':19 'python':5,16,78 'read':32 'recent':77 'section':44 'standard':6,79 'stdlib':85 'support':41 'sync':66 'tool':20 'upstream':68 'user':37 'user-edit':36 'valu':47,50,52 'version':17,57,81 'write':33","created_at":"2026-04-06T16:55:39.526643+00:00","updated_at":"2026-04-16T03:32:03.796008+00:00","problems":[{"fix":"Change the import statement from `import ConfigParser` or `from ConfigParser import ConfigParser` to `import configparser` or `from configparser import ConfigParser` respectively.","cause":"This error occurs when attempting to import the `configparser` module using its old Python 2 naming convention (`ConfigParser`) in a Python 3 environment.","error":"ModuleNotFoundError: No module named 'ConfigParser'"},{"fix":"Ensure the section name in your code exactly matches a section in the INI file (case-sensitive by default for sections), and verify that the `config.read()` method successfully located and parsed the configuration file by checking its return value (a list of successfully read files).","cause":"This error indicates that the requested section does not exist in the configuration file, or the configuration file itself was not successfully read by `configparser`.","error":"configparser.NoSectionError: No section: 'your_section_name'"},{"fix":"Double-check the option name for typos or incorrect casing within the INI file and ensure it exists in the section you are trying to access. Options are case-insensitive by default in `configparser`.","cause":"This error means that the requested option (key) could not be found within the specified section in the configuration file.","error":"configparser.NoOptionError: No option 'your_option'"},{"fix":"Review the specified INI file (`your_file.ini`) for syntax errors. Common issues include missing '=' or ':' between keys and values, unquoted values with special characters, or invalid section headers. If options are intentionally without values, initialize `ConfigParser` with `allow_no_value=True`.","cause":"This error is raised when the configuration file has syntax issues, such as missing values for keys, incorrect delimiters, or malformed sections.","error":"configparser.ParsingError: Source contains parsing errors: 'your_file.ini'"}],"ecosystem":"pypi","meta_description":null,"install_score":100,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"7.2.0","cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/jaraco/configparser","docs":null,"changelog":null,"pypi":"https://pypi.org/project/configparser/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["serialization"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-28","last_verified":"2026-08-27","next_check":"2026-07-28","install_tag":"verified"}}