INI Cheatsheet - INI Configuration Reference

INI is simple, but parsers differ: the comment character, quote handling, nesting support and variable interpolation all vary by implementation. This reference organizes 8 groups of basic syntax and data types, plus four real-world scenarios — Windows, php.ini, Git config and Python configparser — and a dedicated parsing-caveats group on cross-parser differences. After reading you can judge quickly whether a given INI block is safe in the target parser and avoid common traps like BOM, duplicate keys and comment-character issues.

Config Formats·52 commands·Last updated 2026-07-21
iniConfig Files

Basic Syntax 7

; this is a comment
Semicolon comment (most common)
# this is also a comment
Hash comment (some parsers)
[section]
Section definition
key = value
Key-value pair (spaces around = optional)
key = "quoted value"
Quoted value
key =
Empty value
; key = commented out
Comment out a key-value pair

Data Types 7

string = hello
String
integer = 42
Integer
float = 3.14
Float
boolean = true
Boolean (true/false/yes/no/on/off)
array = value1,value2,value3
Array (comma-separated)
hex = 0xFF
Hex (some parsers)
percent = 50%
Percent value

Common Applications 5

[database]\nhost = localhost\nport = 3306
Database config
[server]\nlisten = 8080\nmax_connections = 100
Server config
[logging]\nlevel = info\nfile = /var/log/app.log
Logging config
[user]\nname = Alice\nemail = alice@example.com
User config
[cache]\ndriver = redis\nttl = 3600
Cache config

PHP php.ini Example 9

[PHP]\nmemory_limit = 256M
Memory limit
upload_max_filesize = 20M
Upload file size
post_max_size = 25M
POST data size
max_execution_time = 30
Max execution time (seconds)
display_errors = On
Display errors
error_reporting = E_ALL
Error reporting level
date.timezone = Asia/Shanghai
Timezone setting
session.save_path = /tmp
Session storage path
session.gc_maxlifetime = 1440
Session max lifetime (seconds)

Git Config Example 7

[user]\nname = Your Name\nemail = you@example.com
User info
[core]\neditor = vim\nautocrlf = input
Core config
[alias]\nco = checkout\nbr = branch\nlg = log --oneline --graph
Command aliases
[remote "origin"]\nurl = https://github.com/user/repo.git
Remote repository
[diff]\ntool = vimdiff
Diff tool config
[merge]\ntool = vimdiff\nconflictstyle = diff3
Merge tool config
[pull]\nrebase = true
Use rebase on pull

Windows INI Example 5

path = C:\\Program Files\\App
Windows path (escape backslashes)
[Environment]\nPATH = %PATH%;C:\\bin
Environment variable (reference system var)
temp = %TEMP%\\app
Compose path with system env var
app_dir = ${APPDIR}
Variable reference syntax (some parsers)
key = value ; trailing comment
Trailing comment (some parsers)

Python configparser 6

config.read("config.ini")
Read an INI file
config.write(open("config.ini", "w"))
Write an INI file
config["section"]["key"]
Read a key's value
config["section"]["key"] = "value"
Set a key-value pair
config["DEFAULT"]["key"]
Default value (inherited by all sections)
config.getint("section", "port")
Typed read (getint/getfloat/getboolean)

Parsing Caveats 6

; vs #
; vs #
key="value" vs key = value
key="value" vs key = value
[[nested]]
[[nested]]
BOM: \xEF\xBB\xBF
BOM: \xEF\xBB\xBF
key = ; not a comment
key = ; not a comment
duplicate keys
duplicate keys

Tips

  • INI syntax is simple but has no nesting; use YAML or TOML for complex configs.
  • Comment support varies by parser; semicolon (;) is the most portable.
  • Spaces around the = are optional; parsers strip them automatically.
  • Escape backslashes in Windows paths; prefer forward slashes or double backslashes.
  • Python configparser has no default var interpolation; use ExtendedInterpolation.
  • Use UTF-8 without BOM for INI files to avoid first-section parse failures.

Official References

Each command links to its official documentation below, so you can verify the latest usage and read deeper.

Maintained by LaoHand

Publicly updated on Jul 21, 2026, continuously proofread against official docs.

Contact Us

Wrong command or description? Send us corrections, business inquiries or product feedback by email.

Contact Us