configparser — Configuration file parser.
| Use Case | Command | Description |
|---|---|---|
| 📄 Create a parser | ConfigParser(defaults=None) |
Create a new configuration parser. |
| 📂 Read a file | parser.read('file.ini') |
Read and parse one or more .ini files. |
| 🔍 Get a value | parser.get('section', 'option') |
Return a string value for an option. |
| 🔢 Get an integer | parser.getint('section', 'option') |
Return an integer value. |
| 🔢 Get a float | parser.getfloat('section', 'option') |
Return a float value. |
| ✅ Get a boolean | parser.getboolean('section', 'option') |
Return a boolean (0/1, false/true, no/yes, off/on). |
| 📋 List sections | parser.sections() |
Return a list of section names, excluding DEFAULT. |
| 📝 Write configuration | parser.write(file_object) |
Write the configuration state in .ini format. |
| ➕ Add a section | parser.add_section('section') |
Create a new section. |
| ✏️ Set an option | parser.set('section', 'option', 'value') |
Set an option value. |
A configuration file consists of sections, lead by a "[section]" header, and followed by "name: value" entries, with continuations and such in the style of RFC 822.
Intrinsic defaults can be specified by passing them into the ConfigParser constructor as a dictionary.
https://docs.python.org/3.10/library/configparser.html
The following documentation is automatically generated from the Python source files. It may be incomplete, incorrect or include features that are considered implementation detail and may vary between Python implementations. When in doubt, consult the module reference at the location listed above.
Hierarchy:
builtins.object
Interpolation
BasicInterpolationExtendedInterpolationLegacyInterpolationcollections.abc.MutableMapping
ConverterMappingRawConfigParser
ConfigParser
SafeConfigParserSectionProxyError (builtins.Exception)
DuplicateOptionErrorDuplicateSectionErrorInterpolationError
InterpolationDepthErrorInterpolationMissingOptionErrorInterpolationSyntaxErrorNoOptionErrorNoSectionErrorParsingError
MissingSectionHeaderErrorConfigParser that does not do interpolation.
Constructor:
RawConfigParser(defaults=None, dict_type=<class 'dict'>, allow_no_value=False, *,
delimiters=('=', ':'), comment_prefixes=('#', ';'), inline_comment_prefixes=None,
strict=True, empty_lines_in_values=True, default_section='DEFAULT',
interpolation=<unset>, converters=<unset>)
Methods:
__contains__(self, key) — Check if key exists.__delitem__(self, key) — Delete a section.__getitem__(self, key) — Get a section proxy.__iter__(self) — Iterate over section names.__len__(self) — Number of sections.__setitem__(self, key, value) — Add/replace section.add_section(self, section) — Create a new section.defaults(self) — Return default values.get(self, section, option, *, raw=False, vars=None, fallback=<unset>) — Get an option value.getboolean(self, section, option, *, raw=False, vars=None, fallback=<unset>, **kwargs) — Get boolean.getfloat(self, section, option, *, raw=False, vars=None, fallback=<unset>, **kwargs) — Get float.getint(self, section, option, *, raw=False, vars=None, fallback=<unset>, **kwargs) — Get integer.has_option(self, section, option) — Check if option exists.has_section(self, section) — Check if section exists.items(self, section=<unset>, raw=False, vars=None) — List (name, value) tuples.options(self, section) — List option names.optionxform(self, optionstr) — Transform option name.popitem(self) — Remove and return (section_name, proxy).read(self, filenames, encoding=None) — Read and parse files.read_dict(self, dictionary, source='<dict>') — Read from dictionary.read_file(self, f, source=None) — Read from file object.read_string(self, string, source='<string>') — Read from string.readfp(self, fp, filename=None) — Deprecated, use read_file.remove_option(self, section, option) — Remove an option.remove_section(self, section) — Remove a section.sections(self) — List section names (excluding DEFAULT).set(self, section, option, value=None) — Set an option.write(self, fp, space_around_delimiters=True) — Write .ini format.Properties: converters (readonly).
Data attributes: BOOLEAN_STATES, NONSPACECRE, OPTCRE, OPTCRE_NV, SECTCRE.
ConfigParser implementing interpolation.
Additional methods:
add_section(self, section) — Extends parent by validating section name is a string.set(self, section, option, value=None) — Extends parent by validating type and interpolation syntax.Data attributes: __abstractmethods__ = frozenset().
Alias for ConfigParser for backwards compatibility. Identical interface.
A proxy for a single section.
Methods:
__contains__(self, key) — Check if option exists.__delitem__(self, key) — Delete an option.__getitem__(self, key) — Get an option value.__iter__(self) — Iterate over option names.__len__(self) — Number of options.__setitem__(self, key, value) — Set an option.get(self, option, fallback=None, *, raw=False, vars=None, _impl=None, **kwargs) — Get option value.Properties: name, parser.
Base class for interpolation. Dummy implementation passes value through unchanged.
Methods:
before_get(self, parser, section, option, value, defaults)before_read(self, parser, section, option, value)before_set(self, parser, section, option, value)before_write(self, parser, section, option, value)Classic ConfigParser interpolation. Uses %(name)s format strings.
Methods:
before_get(self, parser, section, option, value, defaults)before_set(self, parser, section, option, value)Advanced interpolation supporting ${section:option} syntax (zc.buildout style).
Methods:
before_get(self, parser, section, option, value, defaults)before_set(self, parser, section, option, value)Deprecated interpolation from older versions.
Methods:
before_get(self, parser, section, option, value, vars)before_set(self, parser, section, option, value)Enables reuse of get*() methods between parser and section proxies.
Methods:
__delitem__(self, key)__getitem__(self, key)__init__(self, parser)__iter__(self)__len__(self)__setitem__(self, key, value)Data attributes: GETTERCRE.
All exception classes inherit from Error (which derives from builtins.Exception).
DuplicateOptionError(section, option, source=None, lineno=None) — Raised when an option is repeated in a single source.DuplicateSectionError(section, source=None, lineno=None) — Raised when a section is repeated.InterpolationError(option, section, msg) — Base class for interpolation errors.InterpolationDepthError(option, section, rawval) — Substitutions nested too deeply.InterpolationMissingOptionError(option, section, rawval, reference) — Required substitution not available.InterpolationSyntaxError(option, section, msg) — Invalid syntax in substitution source.NoOptionError(option, section) — Requested option not found.NoSectionError(section) — Section not found.ParsingError(source=None, filename=None) — General parsing error; has append(lineno, line) method.MissingSectionHeaderError(filename, lineno, line) — Key-value pair found before any section header.DEFAULTSECT = 'DEFAULT'MAX_INTERPOLATION_DEPTH = 10__all__ = list of public names./usr/lib/python3.10/configparser.py
Generated by phpman v4.9.27 · Markdown · JSON · MCP Author: Che Dong Under GNU General Public License
2026-07-18 13:11 @216.73.216.114
CrawledBy Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)
Enhanced by LLM: deepseek-v4-flash / taotoken.net / www.chedong.com - original format