{"library":"parallel-ssh","title":"parallel-ssh (pssh)","description":"parallel-ssh, imported as `pssh`, is an asynchronous Python library for executing commands and transferring files over SSH to multiple hosts in parallel. It leverages `asyncio` for high-performance operations, making it suitable for managing large clusters or performing fast, concurrent remote tasks. The current version is 2.16.0.post1, and it maintains a relatively active release cadence with minor updates every few months.","language":"python","status":"active","last_verified":"Fri Apr 17","install":{"commands":["pip install parallel-ssh"],"cli":{"name":"parallel-ssh","version":"sh: 1: parallel-ssh: not found"}},"imports":["from pssh.clients import ParallelSSHClient","from pssh.clients import SSHClient"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import asyncio\nfrom pssh.clients import ParallelSSHClient\nimport os\n\nasync def run_remote_commands():\n    # Replace with your actual hostnames or IP addresses\n    hosts = ['hostname1', 'hostname2'] \n    \n    # You can specify username, password, or private key path\n    # client = ParallelSSHClient(hosts, user='myuser', password=os.environ.get('SSH_PASSWORD', ''))\n    # client = ParallelSSHClient(hosts, user='myuser', pkey='/path/to/id_rsa')\n    client = ParallelSSHClient(hosts, user=os.environ.get('SSH_USER', 'your_user'))\n\n    print(f\"Connecting to {hosts} and running 'ls -l /tmp'...\")\n    output = await client.run_command('ls -l /tmp')\n\n    async for host_output in output:\n        print(f\"\\n--- Host: {host_output.host} ---\")\n        print(f\"Return Code: {host_output.return_code}\")\n        print(\"Stdout:\")\n        for line in host_output.stdout:\n            print(f\"  {line}\")\n        print(\"Stderr:\")\n        for line in host_output.stderr:\n            print(f\"  {line}\")\n\nif __name__ == '__main__':\n    # Ensure your SSH_USER env var is set or replace 'your_user' directly\n    # Also, ensure SSH agents or known_hosts are configured for passwordless access\n    # or provide password/pkey arguments to ParallelSSHClient.\n    asyncio.run(run_remote_commands())\n","lang":"python","description":"This quickstart demonstrates connecting to multiple hosts using `ParallelSSHClient` and executing a command. It uses `asyncio` to run the asynchronous operations. Replace `hostname1`, `hostname2`, and `your_user` with your actual host details and username. For authentication, consider using SSH agents, `known_hosts`, or passing credentials/private key paths to the client.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}