commented-configparser
A custom ConfigParser class that preserves comments and most formatting when writing loaded config out.
What it is and what it does
commented-configparser is a drop-in replacement for Python's standard library ConfigParser that preserves comments and most formatting when you read and write configuration files. When you load an INI file, modify it, and save it back, your original comments stay in place—a feature the standard library discards. The package normalizes spacing around assignment operators and does not preserve indentation outside of multi-line values, but it retains both hash and semicolon comments, blank lines between sections, and trailing comments.
You use it exactly like the standard ConfigParser: instantiate it, call read() to load a file, modify the configuration as needed, and call write() to save it back. It has no external dependencies and runs on Python 3.9 and later, making it a lightweight addition to projects that need to edit configuration files while respecting user comments.
Use it for:
- Edit application config files programmatically while preserving user comments and structure.
- Build configuration management tools that round-trip INI files without losing documentation.
- Maintain configuration templates where comments explain each setting to end users.
- Update config values in scripts while keeping inline and section-level comments intact.
- Generate or modify INI files from code and have them remain human-readable and annotated.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Extends Python's standard ConfigParser to preserve comments and formatting when reading and writing INI-style configuration files.
Yes, if you need to programmatically edit INI configuration files while preserving comments. The package is lightweight, has no dependencies, and solves a real gap in the standard library. Maintenance is aging but the repository is not abandoned; consider it stable for its narrow use case. No known security issues.
Install
commented-configparser on PyPI
pip
pip install commented-configparseruv
uv add commented-configparserpoetry
poetry add commented-configparserInstalling commented-configparser
Before you install
Low friction: pure Python wheel with no runtime dependencies. Maintenance is aging—last release was 418 days ago, though the repository remains active and the package supports current Python versions (3.9+).
License in practice
MIT license is permissive; you can use, modify, and distribute this package freely with minimal restrictions.
Quickstart
from commentedconfigparser import CommentedConfigParser
config = CommentedConfigParser()
config.read("myconfig.ini")
# modify config as needed
with open("myconfig.ini", "w") as f:
config.write(f)
Requires Python 3.9 or later.
Verify before relying
- Whether indentation outside multi-line values is truly lost or recoverable in edge cases.
- Performance characteristics when handling very large configuration files.
- Compatibility with ConfigParser subclasses or custom interpolation schemes.
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (>=3.9) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | none |
| Maintenance | aging — 418 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 501,381/month — #6,315 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: commented_configparser-3.0.0-py3-none-any.whl
Tags
More Utilities packages
Converts domain names between Unicode and…
permissive · top 100 on PyPI
charset-normalizerDetects and normalizes text encoding from…
permissive · top 100 on PyPI
setuptoolsSetuptools is a Python build backend and…
permissive · top 100 on PyPI
pluggyPluggy provides a plugin system that lets you…
permissive · top 100 on PyPI
PygmentsPygments is a syntax highlighter that colorizes…
permissive · top 100 on PyPI
sixSix provides utility functions to write Python…
permissive · top 100 on PyPI
config-formatterAutomatically formats .ini and .cfg…
permissive · top 15,000 on PyPI
configobjConfigObj reads, writes, and validates…
permissive · top 5,000 on PyPI
ConfigUpdaterConfigUpdater reads and modifies INI…
permissive · top 5,000 on PyPI
iniparseiniparse is an INI file parser that preserves…
permissive · top 15,000 on PyPI
iniconfiginiconfig parses INI configuration files while…
permissive · top 100 on PyPI
ConfigArgParseExtends Python's argparse to parse command-line…
permissive · top 1,000 on PyPI
imperfectParses and edits configparser-compatible INI…
permissive · top 15,000 on PyPI
ast-commentsExtends Python's built-in `ast` module to…
permissive · top 15,000 on PyPI
comment-parserExtracts comments from source code files across…
permissive · top 15,000 on PyPI
jsoncommentParses JSON with comments, multiline strings,…
permissive · top 15,000 on PyPI