Python Glossary Русский

Python 3.0+configparserterm

configparser

module

Reading and writing INI-style configuration files: sections, keys and values.

Syntax

import configparser

Use it for simple settings in the INI format users are familiar with; in Python 2 it was called ConfigParser. Nested data is better served by JSON or TOML (tomllib reads TOML since 3.11). All values are stored as strings: numbers and flags are read with getint and getboolean, and keys are lower-cased by default.

Examples

import configparser
cfg = configparser.ConfigParser()
cfg.read_string('[server]\nPort = 8080\ndebug = yes')
print(cfg.getint('server', 'port'), cfg.getboolean('server', 'debug'))  # → 8080 True
print(cfg['server']['port'] + '1')  # → 80801 — значения хранятся строками

See also

Common errors

Open in the full glossarydocs.python.orgReport an inaccuracy