Skip to main content

Round Trip INI Parser

For reading and respectfully modifying INI files when dealing with software that still uses this format.

This library aims to be as flexible as possible when it comes to interpreting ini files.

Why roundtripini?

There are already a number of existing ini libraries, including python's builtin configparser, but not only do most of these libraries not support round-trip-parsing, most of them also do not support duplicate sections and keys.

roundtripini simultaneously supports round trip parsing, handling duplicate keys by treating them as lists, and allowing sections to be defined multiple times (with each section being queried when reading values).

Why INI?

Lots of software still uses this poorly-specified format. roundtripini is designed to help interface with such software.

If you want a library to read configuration files for the software itself, I would recommend instead using a file format which has a specification and consistent implementations in multiple languages and for multiple platforms, like TOML or YAML.

Usage

from roundtripini import INI

with open("file") as file:
    ini = INI(file)

# Unlike configparser, ini takes a tuple, rather than returning a section when accessed with []
# This is necessary as multiple sections may exist in the file.
ini["section", "key"] = "value"
# Multiple values can be included as a list. Each one will be added with a separate key
ini["section", "key"] = ["value 1", "value 2"]
ini["section", "other key"] = "other value"
# When assigning values, single-element lists are equivalent to strings
ini["section", "other key"] = ["other value"]

assert ini.dump() == """[section]
key = value 1
key = value 2
other key = other value
"""

assert isinstance(ini["section", "key"], list)
assert isinstance(ini["section", "other key"], str)

with open("file", "w") as file:
    file.write(ini.dump())

Restrictions

  • key/value pairs must be separated by =
  • keys may not begin or end with whitespace
  • values will have beginning or ending whitespace stripped when returned.
  • Comments will only be ignored if they are on one line, but not if they are on the same line as a key/value pair, where they will be treated as part of the value

Implementation Notes

  • Validation of key/value pairs occurs when data is used, not when the file is read.
  • When replacing keys with duplicates, all old keys will be removed from all sections (in the case of duplicate sections), and the new elements will be inserted in a single block at the location of the first old key.
  • Lists returned by the [] operator should not be modified, as the underlying data will not change.

Metadata

Release files for roundtripini 0.4.1

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

Source distribution (sdist)

Source distribution for roundtripini 0.4.1
File Size Uploaded Provenance Actions
roundtripini-0.4.1.tar.gz 17.7 kB Without provenance Details for roundtripini-0.4.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for roundtripini 0.4.1
File Interpreter ABI Platform Actions
roundtripini-0.4.1-py3-none-any.whl Python 3 none any Details for roundtripini-0.4.1-py3-none-any.whl

Total release size: 35.8 kB

Release files / roundtripini-0.4.1.tar.gz

Download URL roundtripini-0.4.1.tar.gz
Size 17.7 kB
Tags Source
SHA-256 checksum
How to use checksums
ea9a67fc1d59518765e819a17ce1a77c0dbe00aae94d3680c13829a670218562
BLAKE2b-256 checksum
How to use checksums
595e10849b802b8702973ad89e27a518e32db06d61a7e7a88f17a3d192833d77
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.9.21

Release files / roundtripini-0.4.1-py3-none-any.whl

Download URL roundtripini-0.4.1-py3-none-any.whl
Size 18.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
14f145f273b676ef365a0c93715a3cdd7abc46d6883a7f4fcc48a8896a1ecd88
BLAKE2b-256 checksum
How to use checksums
28290fefed6869a8302f5b112635ffc814ccb23af28aa8ae5fc6a7c4a2247cee
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.9.21

Security for roundtripini 0.4.1

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A 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.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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