class documentation

Create a TOML parser bounded to the list of provided sections. Useful to read settings from a project file such as pyproject.toml.

Usage:

parser = ArgumentParser(
    default_config_files=['./pyproject.toml'],
    config_file_parser_class=TomlConfigParser(['tool.my_super_tool']),
)

IniConfigParser works the same way, for files such as setup.cfg.

Example:

# this is a comment
[tool.my_super_tool] # TOML section table.
# how to specify a key-value pair
format-string = "restructuredtext" # strings must be quoted
# how to set an arg which has action="store_true"
warnings-as-errors = true
# how to set an arg which has action="count" or type=int
verbosity = 1
# how to specify a list arg (eg. arg which has action="append")
repeatable-option = ["https://docs.python.org/3/objects.inv",
                     "https://twistedmatrix.com/documents/current/api/objects.inv"]
# how to specify a multiline text:
multi-line-text = '''
    Lorem ipsum dolor sit amet, consectetur adipiscing elit.
    Vivamus tortor odio, dignissim non ornare non, laoreet quis nunc.
    Maecenas quis dapibus leo, a pellentesque leo.
    '''

IniConfigParser reads a similar INI file, but not this one as is: it doesn't support a '# comment' after a value, and it keeps the quotes around a value that has other text after them.

See the TOML specification for details.

Method __call__ Undocumented
Method __init__ No summary
Method get_syntax_description Returns a string describing the config file syntax.
Method parse Parses the keys and values from a TOML config file.
Method serialize Serialize items to TOML format with section support.
Instance Variable sections Undocumented
def __call__(self): (source)

Undocumented

def __init__(self, sections): (source)
Parameters
sectionsThe section names bounded to the new parser.
def get_syntax_description(self): (source)

Returns a string describing the config file syntax.

def parse(self, stream): (source)

Parses the keys and values from a TOML config file.

def serialize(self, items): (source)

Serialize items to TOML format with section support.

Note: Requires the 'toml' package for serialization (pip install toml). Python 3.11's tomllib only supports reading, not writing.

sections = (source)

Undocumented