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.
pip install config-formatterVerified import paths — ran on the pinned version, not inferred.
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.
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.
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.
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.
Install the library using pip: `pip install config-formatter` or correct the import statement to `import config_formatter`.
Ensure the file path is correct and the file exists. Check for typos in the filename or directory path.
Correct the section header in your configuration file to adhere to the INI/CFG format specification, e.g., `[section_with_no_spaces]` or `'[section with spaces]'` if the parser supports quoted headers.
Provide the path to the configuration file when calling the function, e.g., `config_formatter.format_file('my_config.ini')`.No dependency data recorded yet.