CertGrid CertGrid
Hands-on Lab·Python Automation for IT

Python YAML, INI and TOML Configuration

Four configuration formats, and the choice between them is mostly about types. INI gives you strings and nothing else. JSON and TOML give you real types and refuse anything ambiguous. YAML gives you real types and guesses aggressively - which is why `[NO, SE, DK]` comes back as `[False, 'SE', 'DK']`. This guide reads the same five settings from all four and shows exactly what each hands over.

Files and Data Formats Guide 13 of 39 Intermediate

Written against the versions above. `tomllib` arrived in **Python 3.11** and is read-only. `configparser` and `json` are unchanged. PyYAML is the only third-party dependency here, because there is no YAML parser in the standard library at all.

Everything on this page runs on the control node. Any machine with Python 3 will do.
Server NameIP AddressOSRolesCPURAMHDD
RUNNER01192.168.0.27Ubuntu 26.04 LTSControl node - every script in this path runs here2 Core4 GB50 GB

Before you start

  1. The same five settings, four ways

  2. What each one gives back

  3. INI is strings, and the conversion helpers

  4. TOML and YAML give you real types

  5. tomllib reads and does not write

  6. Writing INI and JSON back out

  7. What YAML decides your values mean

  8. The Norway problem, and two more like it

  9. The YAML that does not fail and should

  10. Malformed, in each format

  11. Which one to use

Official sources