{"id":27662,"library":"commented-configparser","title":"commented-configparser","description":"A custom ConfigParser class that preserves comments and most formatting when writing loaded config out. Version 3.0.0 supports Python >=3.9. Release cadence is irregular.","status":"active","version":"3.0.0","language":"python","source_language":"en","source_url":"https://github.com/jeffbarr/commented-configparser","tags":["configparser","ini","comments","preserve"],"install":[{"cmd":"pip install commented-configparser","lang":"bash","label":"Install via pip"}],"dependencies":[],"imports":[{"note":"CommentedConfigParser is a separate library, not part of stdlib configparser.","wrong":"from configparser import CommentedConfigParser","symbol":"CommentedConfigParser","correct":"from commented_configparser import CommentedConfigParser"}],"quickstart":{"code":"from commented_configparser import CommentedConfigParser\n\nconfig = CommentedConfigParser()\nconfig.read('example.ini')\n# Modify or add values\nconfig.set('section', 'key', 'new_value')\n# Write back preserving comments\nwith open('example.ini', 'w') as f:\n    config.write(f)\n","lang":"python","description":"Read, modify, and write an INI file preserving comments and formatting."},"warnings":[{"fix":"Upgrade to Python >=3.9 and adapt any custom subclasses to new internal representation.","message":"Version 2.x to 3.0.0 dropped Python 2 and older Python 3 versions; requires Python >=3.9. Also, the internal storage changed; any custom subclasses relying on internal data structures may break.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Always use CommentedConfigParser for both reading and writing if you want to preserve comments.","message":"Comments are preserved only if you use the same CommentedConfigParser to read and write. Using the stdlib ConfigParser will lose comments.","severity":"gotcha","affected_versions":"all"},{"fix":"Check the written file if exact formatting of multiline values is critical.","message":"Multiline values may not preserve original formatting (e.g., indentation) after writing. The library attempts to preserve but edge cases exist.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-05-09T00:00:00.000Z","next_check":"2026-08-07T00:00:00.000Z","problems":[{"fix":"Install with pip install commented-configparser and import with `from commented_configparser import CommentedConfigParser`.","cause":"Package installed as 'commented-configparser' (dash) but imported as 'commented_configparser' (underscore).","error":"ModuleNotFoundError: No module named 'commented_configparser'"},{"fix":"Ensure you are using the CommentedConfigParser instance directly and not a different object.","cause":"The library's write method is inherited from ConfigParser; if you override or use a different instance, it might be missing.","error":"AttributeError: 'CommentedConfigParser' object has no attribute 'write'"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}