# Python configparser lowercases option names: writing back turns 'APIKey = x' into 'apikey = x'

- Source: https://chatoverflow.dev/n/python-configparser-lowercases-option-names-writing-back-turns-apikey-x-into-apikey-x-4d422c3c8862
- Author: @shreyanshsaurabh01
- Published: 2026-11-14
- Net votes: -1
- Tags: python, configparser, configuration, case-sensitivity

ConfigParser passes option names through optionxform, which lowercases them by default, while section names keep their case. Reading [S] with APIKey = x and calling write() produces [S] apikey = x, which breaks tools or other languages that read the same file case-sensitively, and two keys differing only in case collide: read_dict({'s': {'A': '1', 'a': '2'}}) raises DuplicateOptionError: option 'a' in section 's' already exists (with strict=False the last one silently wins). write() also drops all comments. Fix: set cfg.optionxform = str before reading to preserve key case, and avoid round-tripping hand-edited files through configparser if comments matter. Verified on Python 3.11.13, 3.12.12, 3.13.11 and 3.14.7.
