{"id":10297,"library":"tini","title":"tini Configuration Parser","description":"tini is a lightweight and straightforward Python library designed for reading and parsing simple .ini and configuration files. It provides a dictionary-like interface for accessing sections and keys, with automatic type conversion for common data types. The current version is 4.0.0, and it follows an infrequent release cadence, with major versions tied to significant API changes or Python version support.","status":"active","version":"4.0.0","language":"en","source_language":"en","source_url":"https://github.com/beaugunderson/python-tini","tags":["configuration","ini","parser","config file"],"install":[{"cmd":"pip install tini","lang":"bash","label":"Install stable version"}],"dependencies":[],"imports":[{"note":"This is the primary class for parsing .ini files.","symbol":"Ini","correct":"from tini import Ini"}],"quickstart":{"code":"import os\nfrom tini import Ini\n\n# Create a dummy ini file for demonstration\nconfig_content = \"\"\"\n[server]\nhost = localhost\nport = 8080\nssl = True\n\n[database]\ntype = postgres\nuser = admin\npassword = mysecret\nservers = db1,db2,db3\n\"\"\"\n\nconfig_file_path = \"config.ini\"\nwith open(config_file_path, \"w\") as f:\n    f.write(config_content)\n\n# Load the configuration\nconfig = Ini(config_file_path)\n\n# Access values\nprint(f\"Server Host: {config['server']['host']}\")\nprint(f\"Server Port: {config['server']['port']} (type: {type(config['server']['port'])})\")\nprint(f\"SSL Enabled: {config['server']['ssl']} (type: {type(config['server']['ssl'])})\")\n\nprint(f\"Database User: {config['database']['user']}\")\nprint(f\"Database Servers: {config['database']['servers']} (type: {type(config['database']['servers'])})\")\n\n# Get a value with a default\nprint(f\"API Key (default None): {config['api'].get('key')}\")\n\n# Clean up the dummy file\nos.remove(config_file_path)\n","lang":"python","description":"This quickstart demonstrates how to load an INI file using `tini.Ini`, access sections and keys, and observe automatic type conversions for common types like integers, booleans, and comma-separated lists. It also shows how to use `.get()` with a default value."},"warnings":[{"fix":"Replace `config.read()` with `config.load()` and `config.save()` with `config.dump()`.","message":"The `Ini.read()` and `Ini.save()` methods were renamed to `Ini.load()` and `Ini.dump()` respectively.","severity":"breaking","affected_versions":"4.0.0 and later"},{"fix":"Ensure your project is running on Python 3.7 or newer. Upgrade your Python environment if necessary.","message":"Python 2.7 and Python 3.6 support was dropped.","severity":"breaking","affected_versions":"4.0.0 and later"},{"fix":"If a raw string is required for a value that might be auto-converted, cast it: `str(config['section']['key'])`.","message":"tini performs automatic type conversion (int, float, bool, list) for values it recognizes. If you need the raw string value, you must explicitly convert it.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Use the `.get()` method with a default value: `config['section'].get('key', 'default_value')` or `config.get('missing_section', {})`.","message":"Accessing non-existent sections or keys directly (e.g., `config['missing_section']`) will raise a `KeyError`. Use `.get()` for safer access.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"Run `pip install tini` to install the package.","cause":"The 'tini' library is not installed in your Python environment.","error":"ModuleNotFoundError: No module named 'tini'"},{"fix":"The method was renamed. Use `config.load()` instead of `config.read()`.","cause":"You are using the deprecated `read()` method on an `Ini` object in `tini` version 4.0.0 or later.","error":"AttributeError: 'Ini' object has no attribute 'read'"},{"fix":"Use the safe `.get()` method which allows providing a default value: `config.get('some_missing_section', {})` or `config['existing_section'].get('missing_key', 'default_value')`.","cause":"You are attempting to access a configuration section or key that does not exist directly using `config['section']['key']` syntax.","error":"KeyError: 'some_missing_section'"},{"fix":"If you intend to parse a string value that `tini` auto-converts (e.g., '123' to 123), explicitly cast it back to a string: `str(config['section']['key'])` before iterating or processing as a string.","cause":"You might be iterating over a configuration value that `tini` auto-converted to an integer or boolean, expecting it to be a string or list.","error":"TypeError: argument of type 'int' is not iterable"}]}