Skip to content

trading_agent.client.package_commands

The trading-agent packages commands: install, list and remove.

Typical usage example:

exit_code = PackageCommands(packages).run('install', 'https://github.com/someone/news-pack.git', replace=False)

PackageCommands

PackageCommands(packages, output=stdout)

Installs, lists and removes packages for the user.

Creates the commands.

Parameters:

Name Type Description Default
packages InstalledPackages

The installed packages.

required
output TextIO

Where to print.

stdout
Source code in src/trading_agent/client/package_commands.py
def __init__(
    self,
    packages: installed_packages_module.InstalledPackages,
    output: TextIO = sys.stdout,
):
    """Creates the commands.

    Args:
        packages (installed_packages_module.InstalledPackages): The installed packages.
        output (TextIO): Where to print.
    """
    self._packages = packages
    self._installer = package_installer.PackageInstaller(packages)
    self._output = output

run

run(action, argument, replace)

Runs one action.

Parameters:

Name Type Description Default
action str

"install", "list" or "remove".

required
argument str | None

The source for "install", the name for "remove".

required
replace bool

For "install", whether to replace an installed package of the same name.

required

Returns:

Type Description
int

0 on success, 1 when the install or removal was refused.

Source code in src/trading_agent/client/package_commands.py
def run(self, action: str, argument: str | None, replace: bool) -> int:
    """Runs one action.

    Args:
        action (str): "install", "list" or "remove".
        argument (str | None): The source for "install", the name for "remove".
        replace (bool): For "install", whether to replace an installed package of the same name.

    Returns:
        int: 0 on success, 1 when the install or removal was refused.
    """
    try:
        if action == 'install':
            self._install(argument, replace)
        elif action == 'remove':
            folder = self._installer.remove(argument)
            self._print(
                f'Removed {argument} ({folder}). Restart the gateway to stop its MCP servers.'
            )
        else:
            self._list()
    except package_installer.PackageError as error:
        self._print(str(error))
        return 1
    return 0