Registry / serialization / iniparse

iniparse

JSON →
library0.5pypypi✓ verified 85d ago

iniparse is an INI parser for Python designed for API compatibility with the standard library's ConfigParser. It offers enhanced functionality, including preserving the structure of INI files (order of sections & options, indentation, comments, and blank lines) when data is updated, and more convenient dotted notation access to values. The current version is 0.5.1, with infrequent releases primarily focused on Python compatibility updates.

pip install iniparse
INSTALL
IMPORT
SIG · INIPARSE
I
iniparse
serializationpythonv0.5
Install
1.6s avg
Import
22ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.5 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.023s · 18MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 1.6s · import 0.021s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

ConfigParser
from iniparse import ConfigParser
from configparser import ConfigParser
While API compatible, `iniparse` offers extended features; directly importing from `configparser` will not provide `iniparse`'s benefits like structure preservation or dotted notation.
RawConfigParser
from iniparse import RawConfigParser
Provided for API compatibility with the standard library's `ConfigParser` module.
SafeConfigParser
from iniparse import SafeConfigParser
Provided for API compatibility with the standard library's `ConfigParser` module.

This quickstart demonstrates how to read an INI file, access and modify values using both dotted notation and dictionary-like syntax, add new options, and write the updated configuration back to a new file, ensuring original structure and comments are preserved. It uses `ConfigParser` from `iniparse`.

import os from iniparse import ConfigParser # Create a dummy INI file ini_content = """ [mysection] key = value another_key = another value [database] host = localhost port = 5432 user = dbuser """ config_file_path = 'config.ini' with open(config_file_path, 'w') as f: f.write(ini_content) # Initialize and read the INI file cfg = ConfigParser() cfg.read(config_file_path) # Access values using dotted notation or dictionary-like syntax print(f"Value for mysection.key: {cfg.mysection.key}") print(f"Value for database.port: {cfg['database']['port']}") # Modify a value cfg.mysection.key = 'new_value' print(f"Modified value for mysection.key: {cfg.mysection.key}") # Add a new option cfg.database.password = os.environ.get('DB_PASSWORD', 'default_password') print(f"Added database.password: {cfg.database.password}") # Write changes to a new INI file, preserving structure new_config_file_path = 'new_config.ini' with open(new_config_file_path, 'w') as f: cfg.write(f) print(f"Configuration written to {new_config_file_path}") # Clean up dummy files os.remove(config_file_path) os.remove(new_config_file_path)
Debug
Known issues
breakingOlder versions of `iniparse` may encounter compatibility issues with Python 3.11 due to internal changes in `ConfigParser` or deprecated features. Version 0.5.1 specifically addresses Python 3.11 compatibility.
fix
Upgrade to `iniparse` version 0.5.1 or newer: `pip install --upgrade iniparse`.
affects: <0.5.1
breakingWhen running on Python 3.12 or newer, `iniparse` versions older than 0.5.1 may break due to the removal of `ConfigParser.readfp` and certain `unittest` aliases. `readfp` has been deprecated since Python 3.2 and is removed in 3.12.
fix
Upgrade to `iniparse` version 0.5.1 or newer to ensure compatibility with Python 3.12+ (though full 3.12+ support might require further updates depending on the extent of internal changes): `pip install --upgrade iniparse`.
affects: <0.5.1
gotchaWhile `iniparse` is API-compatible with `ConfigParser`, its core feature is preserving INI file structure (order, comments, blank lines) upon writing. This might lead to unexpected file modifications if a user expects the default `ConfigParser` behavior of stripping these elements during write operations, which `iniparse` is specifically designed to avoid.
fix
Be aware that `iniparse.ConfigParser.write()` will attempt to preserve the original file's formatting as much as possible, unlike the standard library's `configparser.ConfigParser.write()` which normalizes the output.
affects: All versions
Errors
Common errors & fixes
AttributeError: 'ConfigParser' object has no attribute 'readfp'
This error occurs in Python 3.12+ because the `readfp` method was removed from the standard `configparser.ConfigParser` class, which `iniparse` internally extends or mimics. Older `iniparse` versions have not adapted to this change.
fix
Upgrade `iniparse` to version 0.5.1 or newer to resolve this compatibility issue: `pip install --upgrade iniparse`. The recommended replacement is `read_file`.
TypeError: 'ConfigParser' object is not subscriptable (when using dotted notation)
This error typically indicates you've accidentally imported the standard `configparser.ConfigParser` instead of `iniparse.ConfigParser`. The standard library's parser does not support dotted notation for accessing sections/options.
fix
Ensure your import statement is `from iniparse import ConfigParser`. If you already have `iniparse` installed, verify the import path is correct and not shadowed by `configparser`.
Upgrade
Version history
0.5latest on PyPI · released Jan 29, 2020
Audit
Dependencies

No dependency data recorded yet.

Agent activity
9 hits · last 30 days
node
8
Resources
iniparse — pip install iniparse · libregistry