configparser getboolean() Rejects enabled/disabled (tested)
ConfigParser.getboolean() looks like it should understand any reasonable true/false word in a config file. We measured exactly which words it accepts — and confirmed enabled/disabled, a very common config convention, isn't one of them.
1. The accepted words are a fixed, short list
import configparser
c = configparser.ConfigParser()
c.read_string("""
[s]
a = yes
b = no
c = Yes
d = TRUE
e = 1
f = on
""")
for k in ["a","b","c","d","e","f"]:
print(k, c.getboolean("s", k))
a True
b False
c True
d True
e True
f True
Measured: yes/no, true/false, on/off, and 1/0 all work, case-insensitively. These are exactly the pairs documented for getboolean() — nothing beyond this fixed list is supported.
2. enabled/disabled — a very common convention — is not on the list
c.read_string("""
[s]
g = enabled
""")
c.getboolean("s", "g")
Traceback (most recent call last):
...
ValueError: Not a boolean: enabled
Measured: enabled is rejected outright, even though it reads as an obvious boolean to a person and is a standard convention in many real config files (Apache, nginx-style configs, and plenty of hand-written INI files use enabled/disabled rather than yes/no). There's no partial matching or fuzzy acceptance — it's an exact (case-insensitive) match against the fixed word list or nothing.
3. Fix: normalize non-standard boolean words yourself before calling getboolean(), or extend the accepted map
c.read_string("""
[s]
g = enabled
""")
# Option 1: read as a string and compare directly
c["s"]["g"].strip().lower() in ("enabled", "yes", "true", "1", "on")
True
# Option 2: extend ConfigParser's own BOOLEAN_STATES map
c2 = configparser.ConfigParser()
c2.BOOLEAN_STATES.update({"enabled": True, "disabled": False})
c2.read_string("""
[s]
g = enabled
""")
c2.getboolean("s", "g")
True
Measured: ConfigParser.BOOLEAN_STATES is a plain dict attribute, not a private implementation detail — updating it before parsing lets getboolean() recognize additional words like enabled/disabled without having to bypass getboolean() and write manual string comparisons everywhere it's used.
Frequently asked questions
What values does configparser's getboolean() accept?
We confirmed the fixed, case-insensitive list per the Python docs: '1'/'0', 'yes'/'no', 'true'/'false', and 'on'/'off'. Nothing outside this exact list is recognized.
Why does configparser.getboolean() raise an error on 'enabled'?
We measured it raising ValueError: Not a boolean: enabled because 'enabled' isn't in getboolean()'s fixed accepted-word list, even though it's a common and readable boolean-style value in many real config files.
Is configparser's getboolean() case-sensitive?
No — we measured 'Yes', 'YES', and 'yes' all being accepted identically, confirming the match is case-insensitive across the whole accepted word list.
How do I make configparser.getboolean() accept custom words like enabled/disabled?
We verified that ConfigParser.BOOLEAN_STATES is a public, mutable dict — updating it (e.g. c.BOOLEAN_STATES.update({'enabled': True, 'disabled': False})) before parsing makes getboolean() recognize the new words.
What's a safe fallback if I can't control which boolean words appear in a config file?
Based on what we measured, reading the raw string value and normalizing it yourself (e.g. .strip().lower() in a set of accepted words) avoids the exception entirely and lets you decide exactly which words count as true.
Written with AI assistance. Measured on 2026-10-03 with Python 3.13.5's built-in configparser module: called ConfigParser.getboolean() on values yes/no/Yes/TRUE/1/on (all accepted) and enabled (rejected), to find the exact accepted word list. PlainHeaders is our extension; Python's configparser module is built in.