Subcommands#

The conda CLI can be extended with the conda_subcommands plugin hook. Registered subcommands will be available under the conda <subcommand> command.

Subcommands can provide an alias or aliases for alternate command names. Aliases are registered with the same parser and action as the primary subcommand name, and must not overlap with built-in commands or other plugin subcommands.

class CondaSubcommand(*, name: str, summary: str, action: collections.abc.Callable[[argparse.Namespace], int | None], configure_parser: collections.abc.Callable[[argparse.ArgumentParser], None], aliases: str | collections.abc.Iterable[str] = ())#

Return type to use when defining a conda subcommand plugin hook.

For details on how this is used, see conda_subcommands().

Subcommands support two shapes, distinguished by configure_parser:

  • If configure_parser is set, action receives the parsed argparse.Namespace.

  • If configure_parser is omitted, action receives the remaining argv as tuple[str, ...].

Parameters:
  • name -- Subcommand name (e.g., conda my-subcommand-name).

  • summary -- Subcommand summary, will be shown in conda --help.

  • action -- Callable that will be run when the subcommand is invoked.

  • aliases -- Alternative name or names for the subcommand.

  • configure_parser -- Callable that will be run when the subcommand parser is initialized.

action: collections.abc.Callable[[argparse.Namespace], int | None] | collections.abc.Callable[[tuple[str, Ellipsis]], int | None]#
aliases: tuple[str, Ellipsis] = ()#
configure_parser: collections.abc.Callable[[argparse.ArgumentParser], None] | None = None#
summary: str#
conda_subcommands() collections.abc.Iterable[conda.plugins.types.CondaSubcommand]#

Register external subcommands in conda.

Example:

from conda import plugins


def example_command(args):
    print("This is an example command!")


@plugins.hookimpl
def conda_subcommands():
    yield plugins.types.CondaSubcommand(
        name="example",
        aliases=("example-alias",),
        summary="example command",
        action=example_command,
    )
Returns:

An iterable of subcommand entries.