Config Formatter

1.2.0 · active · verified Wed Apr 15

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.

Warnings

Install

Imports

Quickstart

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.

import os
from config_formatter import ConfigFormatter

# Create a dummy config file for demonstration
config_content_before = """
[main]
# A comment here
key1: value1
key2= value2

[section_one]
   long_key_name  =   multiline value\
  continues here
# Another comment
"""

with open("temp_config.ini", "w") as f:
    f.write(config_content_before)

# Read, format, and print the content
with open("temp_config.ini", "r") as file:
    formatter = ConfigFormatter()
    formatted_content = formatter.prettify(file.read())
    print("--- Original ---")
    print(config_content_before)
    print("\n--- Formatted ---")
    print(formatted_content)

# Clean up the dummy file
os.remove("temp_config.ini")

view raw JSON →