skillfed

imperfect

A CST-based config editor for configparser

imperfect v0.4.0 745.7K downloads/30d#5,171 on PyPI3
Permissive license MIT AGING released

What it is and what it does

imperfect is a CST-based configuration file editor designed to work with files that follow the configparser format (INI-style). Unlike standard configparser, which reads and discards formatting, imperfect parses the file into a tree of nodes that preserves every detail—whitespace, comments, line breaks—so you can make surgical edits and write the file back without losing its original structure and readability.

You parse a file with `parse_string()`, then manipulate sections and entries directly. For simple cases, you can use `set_value()` to add or change a key-value pair. For precise control over placement and formatting, you construct `ConfigEntry` and `ValueLine` objects with explicit whitespace control, then insert them into the tree. The package follows configparser's quirks for compatibility, including lenient section name parsing and specific whitespace handling conventions. It requires Python 3.8 or later and depends only on moreorless for diff utilities.

Use it for:

  • Programmatically update setup.cfg while preserving developer comments and formatting
  • Build configuration management tools that need to edit INI files without destroying readability
  • Automated code generation or build-system integration that modifies config files in place
  • Testing frameworks that need to verify or modify configuration files while keeping diffs human-readable

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

Parses and edits configparser-compatible INI files while preserving whitespace, comments, and formatting, operating as a concrete syntax tree (CST) rather than a lossy key-value store.

Yes, if you need to edit INI-format config files programmatically and preserving formatting matters. The package is stable, low-friction to install, and solves a real problem that standard configparser cannot. The aging maintenance status (477 days since last release) is not a blocker for a mature tool, but verify it handles your specific INI dialect before relying on it in production.

Install

imperfect on PyPI

pip

pip install imperfect

uv

uv add imperfect

poetry

poetry add imperfect

Installing imperfect

Before you install

Low friction: pure Python wheel with a single runtime dependency (moreorless). Maintenance status is aging—last release was 477 days ago, though the repository remains active and stable since its initial 2019 release.

License in practice

MIT license is permissive; you can use, modify, and distribute this package freely with minimal restrictions, making it suitable for both open-source and commercial projects.

Quickstart

import imperfect
with open("setup.cfg") as f:
    data = f.read()
conf = imperfect.parse_string(data)
conf.set_value("metadata", "long_description_content_type", "text/markdown")
with open("setup.cfg", "w") as f:
    f.write(conf.text)

Requires Python 3.8 or later

Verify before relying

  • Whether the CST implementation handles all edge cases in real-world setup.cfg or other INI files beyond the hypothesis-tested scenarios
  • Performance characteristics when editing large or deeply nested configuration files

Package facts

License MIT (permissive)
Python support supports the current Python release (>=3.8)
Install friction low — pure-Python wheel
Runtime dependencies 1 — moreorless
Maintenance aging — 477 days since the last release
Last repo commit
First released
Downloads 745,667/month — #5,171 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: imperfect-0.4.0-py3-none-any.whl

Tags

ini file editor preserving commentsconfigparser CST parseredit config files preserve formattingsetup.cfg programmatic editingwhitespace-preserving ini parser
config-managementcst-parser

More Build Tools packages