Project: config-formatter

An automatic formatter for .ini and .cfg configuration files

Project Details

Latest version
1.2.0
Home Page
https://github.com/Delgan/config-formatter
PyPI Page
https://pypi.org/project/config-formatter/

Project Popularity

PageRank
0.0018419961058473836
Number of downloads
67898

config-formatter

Pypi version Python version Build status License

An automatic formatter for .ini and .cfg configuration files.

Installation

pip install config-formatter

Usage

from config_formatter import ConfigFormatter

with open("config.ini", "r") as file:
    formatter = ConfigFormatter()
    formatted = formatter.prettify(file.read())
    print(formatted)

Example

Before:

[main]        # Comments are preserved.

    # Error-prone indentation is removed.
    [section1]
    key1: value1
    key2=value2  # Value assignment is normalized.


[section2]
lists =
 are
 indented
# including
 comments

multiline =    text that spans
 on several lines
      is properly aligned.

After:

[main]  # Comments are preserved.

# Error-prone indentation is removed.
[section1]
key1 = value1
key2 = value2  # Value assignment is normalized.

[section2]
lists =
    are
    indented
    # including
    comments

multiline = text that spans
            on several lines
            is properly aligned.