Skip to main content

Python 3.9 | 3.10 | 3.11 | 3.12 | 3.13 | 3.14 Code style: black pre-commit

pre-commit.ci status Python tests

commented-configparser


A custom ConfigParser class that preserves comments and most formatting when writing loaded config out.

This library gives you a custom class of the standard library's configparser.ConfigParger which will preserve the comments of a loaded config file when writing that file back out.


Install via pip

From pypi:

python -m pip install commented-configparser

From github:

python -m pip install commented-configparser@git+https://github.com/Preocts/commented-configparser@x.x.x

Note: Replace x.x.x with the desired tag or branch.


Example use

from commentedconfigparser import CommentedConfigParser

# Load the config like normal
config = CommentedConfigParser()
config.read("myconfig.ini")

# Use the config like normal
...

# Update the config like normal
...

# Save the config back to the file
with open("myconfig.ini", "w") as savefile:
    config.write(savefile)

Results

There is the attempt to retain the original format. Known formats that will not be preserved:

  1. Indents will not be preserved outside of multi-line values
  2. Spacing around assignments will be normalized.

Before

# Welcome to our config
[DEFAULT]
# This value has some meaning to someone
foo=bar
# Make sure to add this when you need it
trace=false
logging=true
; This is a comment as well

    # so we need to track all of them

	; and many could be between things
[NEW SECTION]
# Another comment
multiLine=
	value01
	value02
	value03
closing=0
# Trailing comment

After

# Welcome to our config
[DEFAULT]
# This value has some meaning to someone
foo = bar
# Make sure to add this when you need it
trace = false
logging = true
; This is a comment as well

# so we need to track all of them

; and many could be between things
[NEW SECTION]
# Another comment
multiLine =
	value01
	value02
	value03
closing = 0
# Trailing comment

Metadata

Release files for commented-configparser 3.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for commented-configparser 3.0.0
File Size Uploaded
commented_configparser-3.0.0.tar.gz 14.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for commented-configparser 3.0.0
File Interpreter ABI Platform
commented_configparser-3.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 20.2 kB

Release files / commented_configparser-3.0.0.tar.gz

Download URL commented_configparser-3.0.0.tar.gz
Size 14.2 kB
Tags Source
SHA-256 checksum
How to use checksums
dabdfc94f1166200ad3df3ddfc6d17a2902a554b773bc6f81101202dbf0ff457
BLAKE2b-256 checksum
How to use checksums
403594a7f1ea8fe228c703460ed6726919f31dded615729670fb807fc843fa3c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 22, 2025.

Transparency log

Release files / commented_configparser-3.0.0-py3-none-any.whl

Download URL commented_configparser-3.0.0-py3-none-any.whl
Size 6.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3b8a9cac3e6fe0f9301ec8bc54f6d7ddb83da6e3f4d18dbd15459364f5166ab6
BLAKE2b-256 checksum
How to use checksums
d981dfc2b8a565a7a3178e696e94ec444d98bf75ad2a2a717c7c00688e327359
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 22, 2025.

Transparency log

Release history Release notifications | RSS feed

This release

3.0.0 This release

2 release files

2.2.0

2 release files

2.1.0

2 release files

2.0.0

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page