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
muslpy 3.10–3.920 runs
installs and imports cleanly · install 0.0s · import 0.023s · 18MB
glibcpy 3.10–3.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)
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.
fixUpgrade `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.
fixEnsure 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.