| CI/CD | |
| Package | |
| Details |
The sole purpose of ConfigUpdater is to easily update an INI config file with no changes to the original file except the intended ones. This means comments, the ordering of sections and key/value-pairs as wells as their cases are kept as in the original file. Thus ConfigUpdater provides complementary functionality to Python's ConfigParser, which is primarily meant for reading config files and writing new ones.
Features
The key differences to ConfigParser are:
- minimal invasive changes in the update configuration file,
- proper handling of comments,
- only a single config file can be updated at a time,
- the original case of sections and keys are kept,
- control over the position of a new section/key
Following features are deliberately not implemented:
- interpolation of values,
- propagation of parameters from the default section,
- conversions of values,
- passing key/value-pairs with
defaultargument, - non-strict mode allowing duplicate sections and keys.
Usage
First install the package with either:
pip install configupdater
or add it to a project managed with uv:
uv add configupdater
or:
conda install -c conda-forge configupdater
Now we can simply do:
from configupdater import ConfigUpdater
updater = ConfigUpdater()
updater.read("setup.cfg")
which would read the file setup.cfg that is found in many projects.
To change the value of an existing key we can simply do:
updater["metadata"]["author"].value = "Alan Turing"
At any point we can print the current state of the configuration file with:
print(updater)
To update the read-in file, with the encoding it was read with, just call
updater.update_file() or updater.write(open('filename','w')) to write
the changed configuration file to another destination. Before actually
writing, ConfigUpdater will automatically check that the updated
configuration file is still valid by parsing it with the help of ConfigParser.
Many of ConfigParser's methods still exists and it's best to look them up in the module reference. Let's look at some examples.
Adding and removing options
Let's say we have the following configuration in a string:
cfg = """
[metadata]
author = Ada Lovelace
summary = The Analytical Engine
"""
We can add an license option, i.e. a key/value pair, in the same way we would do with ConfigParser:
updater = ConfigUpdater()
updater.read_string(cfg)
updater["metadata"]["license"] = "MIT"
A simple print(updater) will give show you that the new option was
appended to the end:
[metadata]
author = Ada Lovelace
summary = The Analytical Engine
license = MIT
Since the license is really important to us let's say we want to add it
before the summary and even add a short comment before it:
updater = ConfigUpdater()
updater.read_string(cfg)
(
updater["metadata"]["summary"]
.add_before.comment("Ada would have loved MIT")
.option("license", "MIT")
)
which would result in:
[metadata]
author = Ada Lovelace
# Ada would have loved MIT
license = MIT
summary = The Analytical Engine
Using add_after would give the same result and looks like:
updater = ConfigUpdater()
updater.read_string(cfg)
(
updater["metadata"]["author"]
.add_after.comment("Ada would have loved MIT")
.option("license", "MIT")
)
Let's say we want to rename summary to the more common
description:
updater = ConfigUpdater()
updater.read_string(cfg)
updater["metadata"]["summary"].key = "description"
If we wanted no summary at all, we could just do
del updater["metadata"]["summary"].
Adding and removing sections
Adding and remove sections just works like adding and removing options
but on a higher level. Sticking to our Ada Lovelace example, let's
say we want to add a section options just before metadata with a
comment and two new lines to separate it from metadata:
updater = ConfigUpdater()
updater.read_string(cfg)
(
updater["metadata"]
.add_before.comment("Some specific project options")
.section("options")
.space(2)
)
As expected, this results in:
# Some specific project options
[options]
[metadata]
author = Ada Lovelace
summary = The Analytical Engine
We could now fill the new section with options like we learnt before. If
we wanted to rename an existing section we could do this with the help
of the name attribute:
updater["metadata"].name = "MetaData"
Sometimes it might be useful to inject a new section not in a programmatic way but more declarative. Let's assume we have thus defined our new section in a multi-line string:
sphinx_sect_str = """
[build_sphinx]
source_dir = docs
build_dir = docs/_build
"""
With the help of two ConfigUpdater objects we can easily inject this section into our example:
sphinx = ConfigUpdater()
sphinx.read_string(sphinx_sect_str)
sphinx_sect = sphinx["build_sphinx"]
updater = ConfigUpdater()
updater.read_string(cfg)
(updater["metadata"].add_after.space().section(sphinx_sect.detach()))
The detach method will remove the build_sphinx section from the
first object and add it to the second object. This results in:
[metadata]
author = Ada Lovelace
summary = The Analytical Engine
[build_sphinx]
source_dir = docs
build_dir = docs/_build
Alternatively, if you want to preserve build_sphinx in both
ConfigUpdater objects (i.e., prevent it from being removed from the
first while still adding a copy to the second), you call also rely on
stdlib's copy.deepcopy function instead of detach:
from copy import deepcopy
sphinx = ConfigUpdater()
sphinx.read_string(sphinx_sect_str)
sphinx_sect = sphinx["build_sphinx"]
updater = ConfigUpdater()
updater.read_string(cfg)
(updater["metadata"].add_after.space().section(deepcopy(sphinx_sect)))
This technique can be used for all objects inside ConfigUpdater: sections, options, comments and blank spaces.
Shallow copies are discouraged in the context of ConfigUpdater because each configuration block keeps a reference to its container to allow easy document editing. When doing editions (such as adding or changing options and comments) based on a shallow copy, the results can be unreliable and unexpected.
For more examples on how the API of ConfigUpdater works it's best to take a look into the unit tests and read the references.
Notes
ConfigUpdater started out as a helper for PyScaffold, which still uses
it to update the setup.cfg of existing projects. Since then it has
become a useful tool in its own right for everyone who needs to change
configuration files programmatically without losing the comments and
formatting that humans put into them.
Metadata
Release files for ConfigUpdater 4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| configupdater-4.0.tar.gz | 142.6 kB | With provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| configupdater-4.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 179.2 kB
Release files / configupdater-4.0.tar.gz
| Download URL | configupdater-4.0.tar.gz |
|---|---|
| Size | 142.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8e32a62f8ec766e43f30569bd9fbf389b0fba315dd2c836274756b94e08a3e62
|
|
BLAKE2b-256 checksum How to use checksums |
3b379cb3267422b817209a3a5106fd5ab5f94845068366e46db745bdac6fa111
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Oct 18, 2026.
Transparency logRelease files / configupdater-4.0-py3-none-any.whl
| Download URL | configupdater-4.0-py3-none-any.whl |
|---|---|
| Size | 36.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c329b6a496aa415c7ab3364e20a5f00dfa31a75c8fd5f57111b74f9842e5e423
|
|
BLAKE2b-256 checksum How to use checksums |
0ba36c483185da84825ab35b058354e1be94184bde831ba7308542e1640bdfd5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Oct 18, 2026.
Transparency logSecurity for ConfigUpdater 4.0
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.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for configupdater-4.0.tar.gz
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 Oct 18, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.