configparser — Configuration file parser.
| Use Case | Command | Description |
|---|---|---|
| 📝 Create a parser | config = configparser.ConfigParser() | Instantiate a new config parser with default settings |
| 📂 Read a file | config.read('config.ini') | Parse a configuration file (silently ignores missing files) |
| 📄 Read from string | config.read_string(string) | Parse configuration from a string |
| 🔍 Get a value | config.get('section', 'key') | Retrieve a string value for an option |
| 🔢 Get with type conversion | config.getint('section', 'key') | Retrieve an integer value |
| ✏️ Set a value | config.set('section', 'key', 'value') | Set an option in a section |
| 💾 Write to file | config.write(file) | Write configuration in .ini format |
| 🗂️ List sections | config.sections() | Return all section names (excluding DEFAULT) |
| ❓ Check option existence | config.has_option('section', 'key') | Check if a specific option exists |
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.
builtins.object
Dummy interpolation that passes the value through with no changes.
Method resolution order: Interpolation, builtins.object
before_get(self, parser, section, option, value, defaults) — Called before get()before_read(self, parser, section, option, value) — Called before readbefore_set(self, parser, section, option, value) — Called before setbefore_write(self, parser, section, option, value) — Called before writeData descriptors: __dict__, __weakref__
Interpolation as implemented in the classic ConfigParser.
Method resolution order: BasicInterpolation, Interpolation, builtins.object
before_get(self, parser, section, option, value, defaults) — Perform interpolationbefore_set(self, parser, section, option, value) — Validate interpolation syntaxInherited from Interpolation: before_read, before_write, __dict__, __weakref__
Advanced variant of interpolation supporting zc.buildout syntax. Enables interpolation between sections.
Method resolution order: ExtendedInterpolation, Interpolation, builtins.object
before_get(self, parser, section, option, value, defaults) — Perform extended interpolationbefore_set(self, parser, section, option, value) — Validate extended interpolation syntaxInherited from Interpolation: before_read, before_write, __dict__, __weakref__
Deprecated interpolation used in old versions of ConfigParser. Use BasicInterpolation or ExtendedInterpolation instead.
Method resolution order: LegacyInterpolation, Interpolation, builtins.object
before_get(self, parser, section, option, value, vars) — Legacy interpolationbefore_set(self, parser, section, option, value) — Legacy validationInherited from Interpolation: before_read, before_write, __dict__, __weakref__
Base class for configparser exceptions.
Method resolution order: Error, builtins.Exception, builtins.BaseException, builtins.object
__repr__(self) — Return repr(self)__str__ = __repr__ — String representationData descriptor: __weakref__
Inherited from builtins.Exception: __new__
Inherited from builtins.BaseException: __delattr__, __getattribute__, __reduce__, __setattr__, __setstate__, with_traceback, __cause__, __context__, __dict__, __suppress_context__, __traceback__, args
Raised by strict parsers when an option is repeated in an input source.
Method resolution order: DuplicateOptionError, Error, builtins.Exception, builtins.BaseException, builtins.object
__init__(self, section, option, source=None, lineno=None) — Initialize selfInherited from Error: __repr__, __str__, __weakref__
Inherited from builtins.Exception: __new__
Inherited from builtins.BaseException: __delattr__, __getattribute__, __reduce__, __setattr__, __setstate__, with_traceback, __cause__, __context__, __dict__, __suppress_context__, __traceback__, args
Raised when a section is repeated in an input source.
Method resolution order: DuplicateSectionError, Error, builtins.Exception, builtins.BaseException, builtins.object
__init__(self, section, source=None, lineno=None) — Initialize selfInherited from Error: __repr__, __str__, __weakref__
Inherited from builtins.Exception: __new__
Inherited from builtins.BaseException: __delattr__, __getattribute__, __reduce__, __setattr__, __setstate__, with_traceback, __cause__, __context__, __dict__, __suppress_context__, __traceback__, args
Base class for interpolation-related exceptions.
Method resolution order: InterpolationError, Error, builtins.Exception, builtins.BaseException, builtins.object
__init__(self, option, section, msg) — Initialize selfInherited from Error: __repr__, __str__, __weakref__
Inherited from builtins.Exception: __new__
Inherited from builtins.BaseException: __delattr__, __getattribute__, __reduce__, __setattr__, __setstate__, with_traceback, __cause__, __context__, __dict__, __suppress_context__, __traceback__, args
Raised when substitutions are nested too deeply.
Method resolution order: InterpolationDepthError, InterpolationError, Error, builtins.Exception, builtins.BaseException, builtins.object
__init__(self, option, section, rawval) — Initialize selfInherited from InterpolationError: __init__ (overridden)
Inherited from Error: __repr__, __str__, __weakref__
Inherited from builtins.Exception: __new__
Inherited from builtins.BaseException: __delattr__, __getattribute__, __reduce__, __setattr__, __setstate__, with_traceback, __cause__, __context__, __dict__, __suppress_context__, __traceback__, args
A string substitution required a setting which was not available.
Method resolution order: InterpolationMissingOptionError, InterpolationError, Error, builtins.Exception, builtins.BaseException, builtins.object
__init__(self, option, section, rawval, reference) — Initialize selfInherited from InterpolationError: __init__ (overridden)
Inherited from Error: __repr__, __str__, __weakref__
Inherited from builtins.Exception: __new__
Inherited from builtins.BaseException: __delattr__, __getattribute__, __reduce__, __setattr__, __setstate__, with_traceback, __cause__, __context__, __dict__, __suppress_context__, __traceback__, args
Raised when the source text contains invalid syntax.
Method resolution order: InterpolationSyntaxError, InterpolationError, Error, builtins.Exception, builtins.BaseException, builtins.object
Methods inherited from InterpolationError: __init__
Inherited from Error: __repr__, __str__, __weakref__
Inherited from builtins.Exception: __new__
Inherited from builtins.BaseException: __delattr__, __getattribute__, __reduce__, __setattr__, __setstate__, with_traceback, __cause__, __context__, __dict__, __suppress_context__, __traceback__, args
A requested option was not found.
Method resolution order: NoOptionError, Error, builtins.Exception, builtins.BaseException, builtins.object
__init__(self, option, section) — Initialize selfInherited from Error: __repr__, __str__, __weakref__
Inherited from builtins.Exception: __new__
Inherited from builtins.BaseException: __delattr__, __getattribute__, __reduce__, __setattr__, __setstate__, with_traceback, __cause__, __context__, __dict__, __suppress_context__, __traceback__, args
Raised when no section matches a requested option.
Method resolution order: NoSectionError, Error, builtins.Exception, builtins.BaseException, builtins.object
__init__(self, section) — Initialize selfInherited from Error: __repr__, __str__, __weakref__
Inherited from builtins.Exception: __new__
Inherited from builtins.BaseException: __delattr__, __getattribute__, __reduce__, __setattr__, __setstate__, with_traceback, __cause__, __context__, __dict__, __suppress_context__, __traceback__, args
Raised when a configuration file does not follow legal syntax.
Method resolution order: ParsingError, Error, builtins.Exception, builtins.BaseException, builtins.object
__init__(self, source=None, filename=None) — Initialize selfappend(self, lineno, line) — Add an error lineData descriptor: filename (deprecated, use source)
Inherited from Error: __repr__, __str__, __weakref__
Inherited from builtins.Exception: __new__
Inherited from builtins.BaseException: __delattr__, __getattribute__, __reduce__, __setattr__, __setstate__, with_traceback, __cause__, __context__, __dict__, __suppress_context__, __traceback__, args
Raised when a key-value pair is found before any section header.
Method resolution order: MissingSectionHeaderError, ParsingError, Error, builtins.Exception, builtins.BaseException, builtins.object
__init__(self, filename, lineno, line) — Initialize selfInherited from ParsingError: append, filename
Inherited from Error: __repr__, __str__, __weakref__
Inherited from builtins.Exception: __new__
Inherited from builtins.BaseException: __delattr__, __getattribute__, __reduce__, __setattr__, __setstate__, with_traceback, __cause__, __context__, __dict__, __suppress_context__, __traceback__, args
ConfigParser 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>)
Method resolution order: RawConfigParser, collections.abc.MutableMapping, collections.abc.Mapping, collections.abc.Collection, collections.abc.Sized, collections.abc.Iterable, collections.abc.Container, builtins.object
__contains__(self, key) — Check membership__delitem__(self, key) — Delete a section__getitem__(self, key) — Get a section proxy__init__(self, ...) — Initialize self__iter__(self) — Iterate over sections__len__(self) — Number of sections__setitem__(self, key, value) — Set a sectionadd_section(self, section) — Create a new section. Raises DuplicateSectionError if exists, ValueError if name is DEFAULT.defaults(self) — Return the DEFAULT section dictget(self, section, option, *, raw=False, vars=None, fallback=<object object>) — Get an option value. Lookup order: vars, section, DEFAULTSECT. If key not found and fallback provided, return fallback. If interpolation enabled and raw=False, expand % values.getboolean(self, section, option, *, raw=False, vars=None, fallback=<object object>, **kwargs) — Like get() but convert to booleangetfloat(self, section, option, *, raw=False, vars=None, fallback=<object object>, **kwargs) — Like get() but convert to floatgetint(self, section, option, *, raw=False, vars=None, fallback=<object object>, **kwargs) — Like get() but convert to integerhas_option(self, section, option) — Check if option exists in section (or DEFAULT if section is None/empty)has_section(self, section) — Check if section exists (DEFAULT not acknowledged)items(self, section=<object object>, raw=False, vars=None) — Return list of (name, value) tuples for options in a section. If section not given, return list of (section_name, section_proxy) for all sections including DEFAULT.options(self, section) — Return list of option names in a sectionoptionxform(self, optionstr) — Transform option name (default: lower case)popitem(self) — Remove and return a (section_name, section_proxy) tuple. Raises KeyError if empty. DEFAULT is never returned.read(self, filenames, encoding=None) — Read and parse one or more filenames. Non-existing files ignored. Return list of successfully read files.read_dict(self, dictionary, source='<dict>') — Read configuration from a dictionary. Keys = section names, values = dict of options. All values converted to strings.read_file(self, f, source=None) — Read configuration from a file-like object. Source defaults to f.name.read_string(self, string, source='<string>') — Read configuration from a string.readfp(self, fp, filename=None) — Deprecated, use read_file instead.remove_option(self, section, option) — Remove an option.remove_section(self, section) — Remove a section.sections(self) — Return list of section names, excluding [DEFAULT].set(self, section, option, value=None) — Set an option.write(self, fp, space_around_delimiters=True) — Write .ini-format representation. Comments are not preserved.Readonly properties: converters
Data descriptors: __dict__, __weakref__
Class attributes: BOOLEAN_STATES = {'0': False, '1': True, 'false': False, 'no': False, ...}, NONSPACECRE, OPTCRE, OPTCRE_NV, SECTCRE, __abstractmethods__
Inherited from collections.abc.MutableMapping: clear, pop, setdefault, update
Inherited from collections.abc.Mapping: __eq__, keys, values, __hash__ = None, __reversed__ = None
Inherited from collections.abc.Collection: __subclasshook__
Inherited from collections.abc.Iterable: __class_getitem__
ConfigParser implementing interpolation.
Constructor: ConfigParser(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=<object object>, converters=<object object>)
Method resolution order: ConfigParser, RawConfigParser, collections.abc.MutableMapping, collections.abc.Mapping, collections.abc.Collection, collections.abc.Sized, collections.abc.Iterable, collections.abc.Container, builtins.object
Methods defined here:
add_section(self, section) — Extends RawConfigParser.add_section by validating section name is a string.set(self, section, option, value=None) — Extends RawConfigParser.set by validating type and interpolation syntax.Data attributes: __abstractmethods__ = frozenset()
All other methods inherited from RawConfigParser.
ConfigParser alias for backwards compatibility purposes.
Constructor: SafeConfigParser(*args, **kwargs)
Method resolution order: SafeConfigParser, ConfigParser, RawConfigParser, collections.abc.MutableMapping, collections.abc.Mapping, collections.abc.Collection, collections.abc.Sized, collections.abc.Iterable, collections.abc.Container, builtins.object
Methods defined here:
__init__(self, *args, **kwargs) — Initialize self.Data attributes: __abstractmethods__ = frozenset()
All other methods inherited from ConfigParser and RawConfigParser.
A proxy for a single section from a parser.
Constructor: SectionProxy(parser, name) — Creates a view on a section of the specified name in parser.
Method resolution order: SectionProxy, collections.abc.MutableMapping, collections.abc.Mapping, collections.abc.Collection, collections.abc.Sized, collections.abc.Iterable, collections.abc.Container, builtins.object
__contains__(self, key) — Check if option exists__delitem__(self, key) — Delete an option__getitem__(self, key) — Get an option value__init__(self, parser, name) — Initialize self__iter__(self) — Iterate over option names__len__(self) — Number of options__repr__(self) — Return repr(self)__setitem__(self, key, value) — Set an optionget(self, option, fallback=None, *, raw=False, vars=None, _impl=None, **kwargs) — Get an option value. Returns None if not found unless fallback provided.Readonly properties: name, parser
Data descriptors: __dict__, __weakref__
Data attributes: __abstractmethods__ = frozenset()
Inherited from collections.abc.MutableMapping: clear, pop, popitem, setdefault, update
Inherited from collections.abc.Mapping: __eq__, items, keys, values, __hash__ = None, __reversed__ = None
Inherited from collections.abc.Collection: __subclasshook__
Inherited from collections.abc.Iterable: __class_getitem__
Enables reuse of get*() methods between the parser and section proxies.
Constructor: ConverterMapping(parser)
Method resolution order: ConverterMapping, collections.abc.MutableMapping, collections.abc.Mapping, collections.abc.Collection, collections.abc.Sized, collections.abc.Iterable, collections.abc.Container, builtins.object
__delitem__(self, key) — Delete a converter__getitem__(self, key) — Get a converter__init__(self, parser) — Initialize self__iter__(self) — Iterate over converter names__len__(self) — Number of converters__setitem__(self, key, value) — Set a converterData descriptors: __dict__, __weakref__
Data attributes: GETTERCRE = re.compile('^get(?P<name>.+)$'), __abstractmethods__ = frozenset()
Inherited from collections.abc.MutableMapping: clear, pop, popitem, setdefault, update
Inherited from collections.abc.Mapping: __contains__, __eq__, get, items, keys, values, __hash__ = None, __reversed__ = None
Inherited from collections.abc.Collection: __subclasshook__
Inherited from collections.abc.Iterable: __class_getitem__
DEFAULTSECT = 'DEFAULT'MAX_INTERPOLATION_DEPTH = 10__all__ = ['NoSectionError', 'DuplicateOptionError', 'DuplicateSectionError', ...] (full list not shown for brevity)/usr/lib/python3.10/configparser.py
Generated by phpman v4.10.0-7-g98e9fd5 · Markdown · JSON · MCP Author: Che Dong Under GNU General Public License
2026-09-01 16:48 @216.73.216.239
CrawledBy Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)