Reading TOML and INI in Python
tomllib is in the standard library, read-only; configparser handles INI.
import configparser
import tomllib
TOML = """
name = "typestar"
languages = 10
[server]
port = 8080
debug = true
"""
config = tomllib.loads(TOML)
print(config["name"], config["languages"], config["server"]["port"])
print(type(config["server"]["debug"]).__name__)
ini = configparser.ConfigParser()
ini.read_string("[server]\nport = 8080\ndebug = yes\n")
print(ini["server"]["port"], ini.getboolean("server", "debug"))
How it works
tomllib.loadstakes text,loadtakes a binary file.- TOML gives you real types: numbers, booleans, dates, tables.
- configparser reads everything as a string until you ask otherwise.
Keywords and builtins used here
printtype
The run, in numbers
- Lines
- 18
- Characters to type
- 419
- Tokens
- 118
- Three-star pace
- 105 tpm
At the three-star pace of 105 tokens a minute, this run takes about 67 seconds.
Step 1 of 3 in Configuration & time, step 32 of 41 in Domain tools.