initools
initools is a Python library for parsing INI-style configuration files, providing convenient attribute-like access to configuration values. It was last released in 2013 (version 0.3.1) and is no longer actively maintained, making it effectively abandoned. For new projects, the standard library's `configparser` module is recommended.
Common errors
-
AttributeError: 'IniConfig' object has no attribute 'nonexistent_section'
cause Attempting to access an INI section that does not exist in the parsed configuration using attribute access.fixEnsure the section exists in your INI file or configuration object. Wrap access in a `try-except AttributeError` block, or check for existence first (e.g., `if 'section' in config: ...`). -
AttributeError: 'IniSection' object has no attribute 'nonexistent_key'
cause Attempting to access a key within an INI section that does not exist using attribute access.fixVerify that the key is present in the specified section of your INI file. Use `getattr(config.section, 'key', default_value)` for safe access with a fallback. -
ModuleNotFoundError: No module named 'initools'
cause The `initools` library is not installed in your Python environment.fixInstall the library using pip: `pip install initools`.
Warnings
- breaking The `initools` library is abandoned and has not been updated since 2013. It receives no security patches, bug fixes, or compatibility updates. While it might still work for simple cases with current Python 3 versions, its long-term compatibility is not guaranteed, and it may fail with future Python releases.
- gotcha Accessing a non-existent section or key via attribute or dictionary access will raise an `AttributeError` or `KeyError` respectively, as `initools` does not provide a direct way to specify default values or fallback behavior.
- gotcha initools is purely a parser and does not provide functionality to write or modify INI configuration files back to disk or string.
Install
-
pip install initools
Imports
- IniConfig
from initools.ini import IniConfig
Quickstart
import io
from initools.ini import IniConfig
ini_string = """
[server]
host = 127.0.0.1
port = 8080
[database]
type = postgres
user = admin
"""
# Parse the INI string
config = IniConfig(io.StringIO(ini_string))
# Access values using attribute-like syntax
print(f"Server Host: {config.server.host}")
print(f"Database Type: {config.database.type}")
print(f"Database User: {config.database.user}")
# Access values using dictionary-like syntax
print(f"Server Port: {config['server']['port']}")