{"id":6575,"library":"config-formatter","title":"Config Formatter","description":"Config-formatter is a Python library designed for automatically formatting `.ini` and `.cfg` configuration files. It aims to standardize indentation, normalize value assignments, and preserve comments. The current version is 1.2.0, released in November 2023. Its release cadence appears to be infrequent but stable.","status":"active","version":"1.2.0","language":"en","source_language":"en","source_url":"https://github.com/Delgan/config-formatter","tags":["configuration","formatter","ini","cfg","configparser"],"install":[{"cmd":"pip install config-formatter","lang":"bash","label":"Install stable version"}],"dependencies":[],"imports":[{"symbol":"ConfigFormatter","correct":"from config_formatter import ConfigFormatter"}],"quickstart":{"code":"import os\nfrom config_formatter import ConfigFormatter\n\n# Create a dummy config file for demonstration\nconfig_content_before = \"\"\"\n[main]\n# A comment here\nkey1: value1\nkey2= value2\n\n[section_one]\n   long_key_name  =   multiline value\\\n  continues here\n# Another comment\n\"\"\"\n\nwith open(\"temp_config.ini\", \"w\") as f:\n    f.write(config_content_before)\n\n# Read, format, and print the content\nwith open(\"temp_config.ini\", \"r\") as file:\n    formatter = ConfigFormatter()\n    formatted_content = formatter.prettify(file.read())\n    print(\"--- Original ---\")\n    print(config_content_before)\n    print(\"\\n--- Formatted ---\")\n    print(formatted_content)\n\n# Clean up the dummy file\nos.remove(\"temp_config.ini\")","lang":"python","description":"Initialize `ConfigFormatter` and use its `prettify` method to format a string containing `.ini` or `.cfg` content. The `prettify` method returns the formatted string, requiring manual file I/O for saving changes."},"warnings":[{"fix":"Implement robust file I/O, such as writing the formatted content to a temporary file first and then atomically replacing the original file only after a successful write operation.","message":"The `prettify` method returns a formatted string; it does not modify files in-place. Users must handle file I/O (reading and writing back to disk) explicitly. Improper handling (e.g., overwriting the original file before a successful write of the formatted content) can lead to data loss.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Always review the formatted output (e.g., via a `diff`) and thoroughly test configurations with the consuming application after formatting, especially for critical files or those with unusual syntax.","message":"While designed for standard `.ini` and `.cfg` files, highly custom or non-standard syntax (e.g., unusual comment styles, non-standard key-value assignments) might be reformatted in unexpected ways. This could potentially alter the intended structure or functionality if the formatter's interpretation differs from the application consuming the config.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Visually inspect generated diffs and test the formatted files with the consuming application if precise whitespace or comment placement is essential for your use case.","message":"The formatter aims to preserve comments. However, minor whitespace adjustments around comments or within multi-line values can occur during the formatting process. If exact byte-for-byte preservation of whitespace or comment positioning is critical (e.g., for `git diff` consistency or specific parser requirements), these subtle changes might be problematic.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-15T00:00:00.000Z","next_check":"2026-07-14T00:00:00.000Z","problems":[]}