Imperfect is a Python library (version 0.4.0) designed for editing `configparser`-compatible INI files while preserving comments and whitespace. It operates by parsing configuration files into a Concrete Syntax Tree (CST) of nodes, allowing programmatic modifications that maintain the original file's structural integrity. The library is under active development with irregular releases.
pip install imperfectVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to parse an existing INI-style configuration string using `imperfect.parse_string`, modify a value using `set_value`, and then retrieve the modified content, showcasing the preservation of comments and whitespace.
Consult `configparser` documentation for detailed behavior, especially regarding edge cases, and test `imperfect`'s behavior thoroughly for critical parsing scenarios.
For complex structural edits involving comments or specific whitespace, inspect and manipulate `ConfigEntry` objects directly rather than relying solely on high-level `set_value` methods. Review the output (`conf.text`) carefully after modifications.
Review any code that processes user-provided or external configuration files to ensure compatibility with the new unnamed section parsing behavior. Implement explicit validation if unnamed sections are still undesirable for your application.
Always refer to section and option names with their exact casing as present in the INI file. If migrating from `configparser.ConfigParser` where `optionxform = str` was not explicitly set, be mindful of casing.
Ensure all modifications are performed using the `imperfect.ConfigFile` object's methods (e.g., `set_value`, direct manipulation of `ConfigEntry` objects within sections). Always use `conf.text` or `conf.build(file_object)` to retrieve or write the modified content to ensure CST-based preservation.
No dependency data recorded yet.