{"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":"python","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,"search_vec":"'5.0.9':38 'activ':41 'add':23 'address':49 'compat':55 'comprehens':31 'concern':51 'config':58 'configobj':1,2 'configur':12,56 'current':35 'featur':24 'file':13,21,59 'handl':29 'import':46 'infrequ':44 'ini':20,57 'librari':6 'like':25 'list':28 'maintain':42 'nest':26,61 'often':48 'python':5,53 'read':8 'section':27,62 'secur':50 'similar':18 'support':15 'syntax':17 'updat':47 'valid':11,32,60 'version':37,54 'write':9","created_at":"2026-04-09T03:47:34.064722+00:00","updated_at":"2026-04-16T03:31:30.457340+00:00","problems":[{"fix":"Install the library using pip: `pip install configobj`. If using a specific Python version or virtual environment, ensure `pip` for that environment is used (e.g., `python3 -m pip install configobj`).","cause":"The `configobj` library is not installed in the Python environment being used, or there is a Python version mismatch (e.g., attempting to use it with a Python 2 environment, which `configobj` 5.0.9 no longer supports).","error":"ModuleNotFoundError: No module named 'configobj'"},{"fix":"Review and correct the syntax in the configuration file to adhere to `configobj`'s specification, ensuring proper `key = value` format and valid section headers.","cause":"The configuration file contains a syntax error, such as a malformed `key = value` line, an invalid section marker, or using a colon (`:`) instead of an equals sign (`=`) as a key-value separator, which `configobj` does not support.","error":"ParseError"},{"fix":"Ensure the key or section path is correct and exists in your configuration. Use `config.get('section', {}).get('key', default_value)` for safe access with a fallback, or verify that the `configspec` properly defines default values for keys you intend to restore.","cause":"An attempt was made to access a section or an option within a section using dictionary-like access (`config['section']['key']`) that does not exist in the loaded configuration, or `restore_default(key)` was called for a key that has no default value defined in the `configspec`.","error":"KeyError"},{"fix":"Provide the correct and absolute path to an existing configuration file. Alternatively, set `file_error=False` and `create_empty=True` in the `ConfigObj` constructor if you intend for `configobj` to create an empty file if it doesn't exist.","cause":"The file path provided to the `ConfigObj` constructor does not point to an existing file, and the `file_error` parameter is set to `True` (or implicitly `True` depending on other constructor arguments like `create_empty`).","error":"IOError: [Errno 2] No such file or directory: 'your_config_file.conf'"},{"fix":"Inspect the `configspec` and the corresponding values in your configuration file. Correct the data in the config file to match the validation rules, or adjust the `configspec` if the rules are unintentionally restrictive. Using `config.validate(validator, preserve_errors=True)` and `flatten_errors()` can help get detailed information about specific validation failures.","cause":"During the validation process using `config.validate(validator)`, one or more values in the configuration file failed to meet the criteria (e.g., type, range, allowed options) specified in the associated `configspec`.","error":"validate.ValidateError (or subclasses like VdtValueError, VdtTypeError)"}],"ecosystem":"pypi","meta_description":null,"install_score":100,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"5.0.9","cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/DiffSK/configobj","docs":null,"changelog":null,"pypi":"https://pypi.org/project/configobj/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["serialization","data"],"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"}}