clap package

(C)ommand (L)ine (A)rgument (P)arsing.

A thin wrapper around the standard Python argparse library.

class Config(_env_file='<object object>', _env_file_encoding=None, _secrets_dir=None, **values)[source]

Bases: pydantic.env_settings.BaseSettings

Default CLI arguments / app configuration.

Parameters
  • _env_file (Union[Path, str, None]) –

  • _env_file_encoding (Optional[str]) –

  • _secrets_dir (Union[Path, str, None]) –

  • values (Any) –

logs
verbose
class MainType(*args, **kwargs)[source]

Bases: Protocol

Type of the main() function returned by main_factory().

class NewCommand(*args, **kwargs)[source]

Bases: Protocol

Type of the function returned by new_command_factory().

Parser(*args, name=None, **kwargs)[source]

Wrapper for argparse.ArgumentParser.

Parameters
  • args (Any) –

  • name (Optional[str]) –

  • kwargs (Any) –

Return type

ArgumentParser

main_factory(run, config)[source]

Factory used to create a new main() function.

Parameters
  • run (Callable[[ConfigType], int]) – A function that acts as the real entry point for a program.

  • config (Type[ConfigType]) – A pydantic.BaseSettings type that represents our applications config.

Return type

MainType

Returns

A generic main() function to be used as a script’s entry point.

new_command_factory(parser, *, dest='command', required=True, description=None, **kwargs)[source]

Returns a new_command() function that can be used to add subcommands.

Parameters
  • parser (ArgumentParser) – The argparse parser that we want to add subcommands to.

  • dest (str) – The attribute name that the subcommand name will be stored under inside the Namespace object.

  • required (bool) – Will this subcommand be required or optional?

  • description (Optional[str]) – This argument describes what the subcommand is used for.

  • kwargs (Any) – These keyword arguments are relayed to the parser.add_subparsers() function call.

Return type

NewCommand