imperfect
A CST-based config editor for configparser
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 imperfectuv
uv add imperfectpoetry
poetry add imperfectInstalling 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
More Build Tools packages
Provides reusable utilities for Python…
permissive · top 100 on PyPI
tqdmWraps any iterable to display a real-time…
copyleft · top 100 on PyPI
pippip is the standard installer for Python…
permissive · top 100 on PyPI
hatchlingHatchling is a standards-compliant Python build…
permissive · top 100 on PyPI
grpcio-toolsGenerates Python gRPC service stubs and message…
permissive · top 1,000 on PyPI
pre-commitpre-commit is a framework for installing and…
permissive · top 1,000 on PyPI
codemod-yamlModifies YAML documents in place with surgical…
permissive · top 15,000 on PyPI
config-formatterAutomatically formats .ini and .cfg…
permissive · top 15,000 on PyPI
iniparseiniparse is an INI file parser that preserves…
permissive · top 15,000 on PyPI
ConfigUpdaterConfigUpdater reads and modifies INI…
permissive · top 5,000 on PyPI
crudinicrudini is a command-line utility for reading,…
copyleft · top 15,000 on PyPI
iniconfiginiconfig parses INI configuration files while…
permissive · top 100 on PyPI
commented-configparserExtends Python's standard ConfigParser to…
permissive · top 15,000 on PyPI
untokenizeConverts Python tokens back into source code…
permissive · top 15,000 on PyPI
confectionConfection is a configuration system for Python…
permissive · top 5,000 on PyPI
libcstlibcst parses Python source code into a…
permissive · top 1,000 on PyPI