https://github.com/delgan/config-formatter
An automatic formatter for .ini and .cfg configuration files
https://github.com/delgan/config-formatter
cfg config configuration formatter ini python
Last synced: 9 months ago
JSON representation
An automatic formatter for .ini and .cfg configuration files
- Host: GitHub
- URL: https://github.com/delgan/config-formatter
- Owner: Delgan
- License: mit
- Created: 2022-06-24T11:51:20.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2023-11-27T17:38:31.000Z (over 2 years ago)
- Last Synced: 2024-12-30T01:42:00.515Z (over 1 year ago)
- Topics: cfg, config, configuration, formatter, ini, python
- Language: Python
- Homepage:
- Size: 28.3 KB
- Stars: 12
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
- Security: .github/SECURITY.md
Awesome Lists containing this project
README
# config-formatter
[](https://pypi.python.org/pypi/config-formatter) [](https://pypi.python.org/pypi/config-formatter) [](https://github.com/Delgan/config-formatter/actions/workflows/tests.yml?query=branch:main) [](https://github.com/Delgan/config-formatter/blob/main/LICENSE)
An automatic formatter for .ini and .cfg configuration files.
## Installation
```shell
pip install config-formatter
```
## Usage
```python
from config_formatter import ConfigFormatter
with open("config.ini", "r") as file:
formatter = ConfigFormatter()
formatted = formatter.prettify(file.read())
print(formatted)
```
## Example
Before:
```ini
[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:
```ini
[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.
```