{"id":7303,"library":"iniparse","title":"INIParse","description":"iniparse is an INI parser for Python designed for API compatibility with the standard library's ConfigParser. It offers enhanced functionality, including preserving the structure of INI files (order of sections & options, indentation, comments, and blank lines) when data is updated, and more convenient dotted notation access to values. The current version is 0.5.1, with infrequent releases primarily focused on Python compatibility updates.","status":"active","version":"0.5.1","language":"en","source_language":"en","source_url":"https://github.com/candlepin/python-iniparse","tags":["ini","config","parser","configuration files","ConfigParser"],"install":[{"cmd":"pip install iniparse","lang":"bash"}],"dependencies":[],"imports":[{"note":"While API compatible, `iniparse` offers extended features; directly importing from `configparser` will not provide `iniparse`'s benefits like structure preservation or dotted notation.","wrong":"from configparser import ConfigParser","symbol":"ConfigParser","correct":"from iniparse import ConfigParser"},{"note":"Provided for API compatibility with the standard library's `ConfigParser` module.","symbol":"RawConfigParser","correct":"from iniparse import RawConfigParser"},{"note":"Provided for API compatibility with the standard library's `ConfigParser` module.","symbol":"SafeConfigParser","correct":"from iniparse import SafeConfigParser"}],"quickstart":{"code":"import os\nfrom iniparse import ConfigParser\n\n# Create a dummy INI file\nini_content = \"\"\"\n[mysection]\nkey = value\nanother_key = another value\n\n[database]\nhost = localhost\nport = 5432\nuser = dbuser\n\"\"\"\n\nconfig_file_path = 'config.ini'\nwith open(config_file_path, 'w') as f:\n    f.write(ini_content)\n\n# Initialize and read the INI file\ncfg = ConfigParser()\ncfg.read(config_file_path)\n\n# Access values using dotted notation or dictionary-like syntax\nprint(f\"Value for mysection.key: {cfg.mysection.key}\")\nprint(f\"Value for database.port: {cfg['database']['port']}\")\n\n# Modify a value\ncfg.mysection.key = 'new_value'\nprint(f\"Modified value for mysection.key: {cfg.mysection.key}\")\n\n# Add a new option\ncfg.database.password = os.environ.get('DB_PASSWORD', 'default_password')\nprint(f\"Added database.password: {cfg.database.password}\")\n\n# Write changes to a new INI file, preserving structure\nnew_config_file_path = 'new_config.ini'\nwith open(new_config_file_path, 'w') as f:\n    cfg.write(f)\n\nprint(f\"Configuration written to {new_config_file_path}\")\n\n# Clean up dummy files\nos.remove(config_file_path)\nos.remove(new_config_file_path)","lang":"python","description":"This quickstart demonstrates how to read an INI file, access and modify values using both dotted notation and dictionary-like syntax, add new options, and write the updated configuration back to a new file, ensuring original structure and comments are preserved. It uses `ConfigParser` from `iniparse`."},"warnings":[{"fix":"Upgrade to `iniparse` version 0.5.1 or newer: `pip install --upgrade iniparse`.","message":"Older versions of `iniparse` may encounter compatibility issues with Python 3.11 due to internal changes in `ConfigParser` or deprecated features. Version 0.5.1 specifically addresses Python 3.11 compatibility.","severity":"breaking","affected_versions":"<0.5.1"},{"fix":"Upgrade to `iniparse` version 0.5.1 or newer to ensure compatibility with Python 3.12+ (though full 3.12+ support might require further updates depending on the extent of internal changes): `pip install --upgrade iniparse`.","message":"When running on Python 3.12 or newer, `iniparse` versions older than 0.5.1 may break due to the removal of `ConfigParser.readfp` and certain `unittest` aliases. `readfp` has been deprecated since Python 3.2 and is removed in 3.12.","severity":"breaking","affected_versions":"<0.5.1"},{"fix":"Be aware that `iniparse.ConfigParser.write()` will attempt to preserve the original file's formatting as much as possible, unlike the standard library's `configparser.ConfigParser.write()` which normalizes the output.","message":"While `iniparse` is API-compatible with `ConfigParser`, its core feature is preserving INI file structure (order, comments, blank lines) upon writing. This might lead to unexpected file modifications if a user expects the default `ConfigParser` behavior of stripping these elements during write operations, which `iniparse` is specifically designed to avoid.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Upgrade `iniparse` to version 0.5.1 or newer to resolve this compatibility issue: `pip install --upgrade iniparse`. The recommended replacement is `read_file`.","cause":"This error occurs in Python 3.12+ because the `readfp` method was removed from the standard `configparser.ConfigParser` class, which `iniparse` internally extends or mimics. Older `iniparse` versions have not adapted to this change.","error":"AttributeError: 'ConfigParser' object has no attribute 'readfp'"},{"fix":"Ensure your import statement is `from iniparse import ConfigParser`. If you already have `iniparse` installed, verify the import path is correct and not shadowed by `configparser`.","cause":"This error typically indicates you've accidentally imported the standard `configparser.ConfigParser` instead of `iniparse.ConfigParser`. The standard library's parser does not support dotted notation for accessing sections/options.","error":"TypeError: 'ConfigParser' object is not subscriptable (when using dotted notation)"}]}