tini Configuration Parser

4.0.0 · active · verified Fri Apr 17

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.

Common errors

Warnings

Install

Imports

Quickstart

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.

import os
from tini import Ini

# Create a dummy ini file for demonstration
config_content = """
[server]
host = localhost
port = 8080
ssl = True

[database]
type = postgres
user = admin
password = mysecret
servers = db1,db2,db3
"""

config_file_path = "config.ini"
with open(config_file_path, "w") as f:
    f.write(config_content)

# Load the configuration
config = Ini(config_file_path)

# Access values
print(f"Server Host: {config['server']['host']}")
print(f"Server Port: {config['server']['port']} (type: {type(config['server']['port'])})")
print(f"SSL Enabled: {config['server']['ssl']} (type: {type(config['server']['ssl'])})")

print(f"Database User: {config['database']['user']}")
print(f"Database Servers: {config['database']['servers']} (type: {type(config['database']['servers'])})")

# Get a value with a default
print(f"API Key (default None): {config['api'].get('key')}")

# Clean up the dummy file
os.remove(config_file_path)

view raw JSON →