module documentation

A drop-in replacement for argparse that allows options to also be set via config files and/or environment variables.

See Also
configargparse.ArgumentParser, configargparse.add_argument
Class ArgumentDefaultsRawHelpFormatter HelpFormatter that adds default values AND doesn't do line-wrapping
Class ArgumentParser Drop-in replacement for argparse.ArgumentParser that adds support for environment variables and .ini or .yaml-style config files.
Class CompositeConfigParser Create a config parser composed by other ConfigFileParser instances.
Class ConfigFileParser This abstract class can be extended to add support for new config file formats
Class ConfigparserConfigFileParser parses INI files using pythons configparser.
Class DefaultConfigFileParser Based on a simplified subset of INI and YAML formats. Here is the supported syntax
Class IniConfigParser Create a INI parser bounded to the list of provided sections. Optionaly convert multiline strings to list.
Class TomlConfigParser Create a TOML parser bounded to the list of provided sections.
Class YAMLConfigFileParser Parses YAML config files. Depends on the PyYAML module. https://pypi.python.org/pypi/PyYAML
Exception ConfigFileParserException Raised when config file parsing failed.
Function add_argument This method supports the same args as ArgumentParser.add_argument(..) as well as the additional args below.
Function already_on_command_line Utility method for checking if any of the potential_command_line_args is already present in existing_args.
Function get_argument_parser Returns the global ArgumentParser instance with the given name. The 1st time this function is called, a new ArgumentParser instance will be created for the given name, and any args other than "name" will be passed on to the ArgumentParser constructor.
Function get_toml_section Given some TOML data (as loaded with toml.load()), returns the requested section of the data. Returns None if the section is not found.
Function init_argument_parser Creates a global ArgumentParser instance with the given name, passing any args other than "name" to the ArgumentParser constructor. This instance can then be retrieved using get_argument_parser(..)
Function is_quoted Detect whether a string is a quoted representation.
Function parse_toml_section_name Parse a TOML section name to a sequence of strings.
Function unquote_str Unquote a maybe quoted string representation. If the string is not detected as being a quoted representation, it returns the same string as passed. It supports all kinds of python quotes: """, ''', " and ...
Variable ACTION_TYPES_THAT_DONT_NEED_A_VALUE Undocumented
Variable is_boolean_optional_action Undocumented
Constant _COMMAND_LINE_SOURCE_KEY Undocumented
Constant _CONFIG_FILE_SOURCE_KEY Undocumented
Constant _DEFAULTS_SOURCE_KEY Undocumented
Constant _ENV_VAR_SOURCE_KEY Undocumented
Constant _QUOTED_STR_REGEX Undocumented
Constant _TRIPLE_QUOTED_STR_REGEX Undocumented
Variable _parsers Undocumented
def add_argument(self, *args, **kwargs): (source)

This method supports the same args as ArgumentParser.add_argument(..) as well as the additional args below.

Parameters
selfUndocumented
*argsUndocumented
env_varIf set, the value of this environment variable will override any config file or default values for this arg (but can itself be overridden on the commandline). Also, if auto_env_var_prefix is set in the constructor, this env var name will be used instead of the automatic name.
is_config_file_argIf True, this arg is treated as a config file path This provides an alternative way to specify config files in place of the ArgumentParser(fromfile_prefix_chars=..) mechanism. Default: False
is_write_out_config_file_argIf True, this arg will be treated as a config file path, and, when it is specified, will cause configargparse to write all current commandline args to this file as config options and then exit. Default: False
Returns
argparse.Actionthe new argparse action
def already_on_command_line(existing_args_list, potential_command_line_args, prefix_chars): (source)

Utility method for checking if any of the potential_command_line_args is already present in existing_args.

Returns
boolalready on command line?
def get_argument_parser(name=None, **kwargs): (source)

Returns the global ArgumentParser instance with the given name. The 1st time this function is called, a new ArgumentParser instance will be created for the given name, and any args other than "name" will be passed on to the ArgumentParser constructor.

def get_toml_section(data, section): (source)

Given some TOML data (as loaded with toml.load()), returns the requested section of the data. Returns None if the section is not found.

def init_argument_parser(name=None, **kwargs): (source)

Creates a global ArgumentParser instance with the given name, passing any args other than "name" to the ArgumentParser constructor. This instance can then be retrieved using get_argument_parser(..)

@functools.lru_cache(maxsize=256, typed=True)
def is_quoted(text, triple=True): (source)

Detect whether a string is a quoted representation.

Parameters
textUndocumented
tripleAlso match tripple quoted strings.
def parse_toml_section_name(section_name): (source)

Parse a TOML section name to a sequence of strings.

The following names are all valid:

"a.b.c"            # this is best practice -> returns ("a", "b", "c")
" d.e.f "          # same as [d.e.f] -> returns ("d", "e", "f")
" g .  h  . i "    # same as [g.h.i] -> returns ("g", "h", "i")
' j . "ʞ" . "l" '  # same as [j."ʞ"."l"], double or simple quotes here are supported. -> returns ("j", "ʞ", "l")
def unquote_str(text, triple=True): (source)

Unquote a maybe quoted string representation. If the string is not detected as being a quoted representation, it returns the same string as passed. It supports all kinds of python quotes: """, ''', " and '.

Parameters
textUndocumented
tripleAlso unquote tripple quoted strings.
Raises
ValueErrorIf the string is detected as beeing quoted but literal_eval() fails to evaluate it as string. This would be a bug in the regex.
ACTION_TYPES_THAT_DONT_NEED_A_VALUE = (source)

Undocumented

is_boolean_optional_action = (source)

Undocumented

_COMMAND_LINE_SOURCE_KEY: str = (source)

Undocumented

Value
'command_line'
_CONFIG_FILE_SOURCE_KEY: str = (source)

Undocumented

Value
'config_file'
_DEFAULTS_SOURCE_KEY: str = (source)

Undocumented

Value
'defaults'
_ENV_VAR_SOURCE_KEY: str = (source)

Undocumented

Value
'environment_variables'
_QUOTED_STR_REGEX = (source)

Undocumented

Value
re.compile(r'(^"(?:\\.|[^"\\])*"$)|(^\'(?:\\.|[^\'\\])*\'$)')
_TRIPLE_QUOTED_STR_REGEX = (source)

Undocumented

Value
re.compile(r'(^"""(\s+)?(([^"]|"([^"]|"[^"]))*(""?)?)?(\s+)?(?:\\.|[^"\\])?"""$)
|(^\'\'\'(\s+)?(([^\']|\'([^\']|\'[^\']))*(\'\'?)?)?(\s+)?(?:\\.|[^\'\\])?\'\'\'
$)',
           re.DOTALL)
_parsers: dict = (source)

Undocumented