{"id":1429,"library":"configobj","title":"ConfigObj","description":"ConfigObj is a Python library for reading, writing, and validating configuration files. It supports a syntax similar to .ini files but adds features like nested sections, list handling, and comprehensive validation. It is currently at version 5.0.9 and is actively maintained with infrequent but important updates, often addressing security concerns or Python version compatibility.","status":"active","version":"5.0.9","language":"en","source_language":"en","source_url":"https://github.com/DiffSK/configobj","tags":["configuration","ini","config file","validation","nested sections"],"install":[{"cmd":"pip install configobj","lang":"bash","label":"Install latest version"}],"dependencies":[],"imports":[{"symbol":"ConfigObj","correct":"from configobj import ConfigObj"},{"note":"Used for performing validation against a configspec.","symbol":"Validate","correct":"from configobj import Validate"}],"quickstart":{"code":"from configobj import ConfigObj\nimport os\n\n# 1. Create and write a config file\nconfig = ConfigObj()\nconfig.filename = \"example.ini\"\n\nconfig['Section One'] = {\n    'key1': 'value1',\n    'key2': ['itemA', 'itemB', 'itemC']\n}\n\nconfig['Section Two'] = {}\nconfig['Section Two']['nested_key'] = 'nested value'\n\nconfig.write()\n\nprint(f\"Config file 'example.ini' created.\\n\")\n\n# 2. Read the config file\nread_config = ConfigObj('example.ini')\n\nprint(f\"Read config content:\\n{read_config.dict()}\\n\")\nprint(f\"Value from Section One, Key1: {read_config['Section One']['key1']}\")\nprint(f\"List from Section One, Key2: {read_config['Section One']['key2']}\")\n\n# 3. Clean up the created file\nos.remove(\"example.ini\")\nprint(\"example.ini removed.\")","lang":"python","description":"This example demonstrates how to create a ConfigObj instance, populate it with data (including nested sections and lists), write it to a file, and then read it back. It concludes with cleanup of the created file."},"warnings":[{"fix":"Upgrade to `configobj>=5.0.9` and ensure your environment runs Python 3.7 or newer.","message":"Python 2 support was entirely dropped in version 5.0.9, along with associated compatibility code. The minimum required Python version is now 3.7.","severity":"breaking","affected_versions":"<=5.0.8"},{"fix":"Upgrade to `configobj>=5.0.9` immediately to patch the ReDoS vulnerability.","message":"Version 5.0.9 addresses CVE-2023-26112, a Regular Expression Denial of Service (ReDoS) vulnerability. Older versions are susceptible to this vulnerability.","severity":"breaking","affected_versions":"<=5.0.8"},{"fix":"Always define a `configspec` and an instance of `configobj.Validate` to use with the `config.validate()` method, e.g., `config = ConfigObj('my.ini', configspec='my.spec'); config.validate(Validate())`.","message":"Validation is not automatic. To enable validation, you must explicitly pass a `configspec` (a file path or a `ConfigObj` instance representing the specification) and then use a `Validate` object with `config.validate(validator)`.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Define a `configspec` with `list` types (e.g., `key = list`) for keys expected to hold lists. When reading, instantiate `ConfigObj` with the `configspec` to ensure correct type conversion.","message":"When working with lists, ConfigObj automatically converts comma-separated strings to lists upon writing. However, reading them back without a `configspec` will treat elements as strings. For robust type handling, especially with non-string list items, a `configspec` is essential.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}