Skip to main content

parallel-ssh

Non-blocking, asynchronous parallel SSH client library.

Run SSH commands over many - hundreds/hundreds of thousands - number of servers asynchronously and with minimal system load on the client host.

Native code based client with extremely high performance - based on libssh2 C library.

License Latest Version https://travis-ci.org/ParallelSSH/parallel-ssh.svg?branch=master https://codecov.io/gh/ParallelSSH/parallel-ssh/branch/master/graph/badge.svg https://img.shields.io/pypi/wheel/parallel-ssh.svg Latest documentation

Installation

pip install parallel-ssh

Usage Example

See documentation on read the docs for more complete examples.

Run uname on two remote hosts in parallel with sudo.

from pssh.pssh_client import ParallelSSHClient

hosts = ['myhost1', 'myhost2']
client = ParallelSSHClient(hosts)

output = client.run_command('uname')
for host, host_output in output.items():
    for line in host_output.stdout:
        print(line)
Output:
Linux
Linux

Native client

Starting from version 1.2.0, a new client is supported in parallel-ssh which offers much greater performance and reduced overhead than the current default client.

The new client is based on libssh2 via the ssh2-python extension library and supports non-blocking mode natively. Binary wheel packages with libssh2 included are provided for Linux, OSX and Windows platforms and all supported Python versions.

See this post for a performance comparison of the available clients.

To make use of this new client, ParallelSSHClient can be imported from pssh.pssh2_client instead. Their respective APIs are almost identical.

The new client will become the default and will replace the current pssh.pssh_client in a new major version of the library - 2.0.0 - once remaining features have been implemented. The native client should be considered as beta status until the 2.0.0 release when it is made the default.

The current default client will remain available as an option under a new name.

For example:

from pprint import pprint
from pssh.pssh2_client import ParallelSSHClient

hosts = ['myhost1', 'myhost2']
client = ParallelSSHClient(hosts)

output = client.run_command('uname')
for host, host_output in output.items():
    for line in host_output.stdout:
        print(line)

See documentation for a feature comparison of the two clients.

Native Code Client Features

  • Highest performance and least overhead of any Python SSH libraries

  • Thread safe - makes use of native threads for blocking calls like authentication

  • Natively non-blocking utilising libssh2 via ssh2-python - no monkey patching of the Python standard library

  • Significantly reduced overhead in CPU and memory usage

Exit codes

Once either standard output is iterated on to completion, or client.join(output) is called, exit codes become available in host output. Iteration ends only when remote command has completed, though it may be interrupted and resumed at any point.

for host in output:
    print(output[host].exit_code)
Output:
0
0

The client’s join function can be used to block and wait for all parallel commands to finish:

client.join(output)

Similarly, output and exit codes are available after client.join is called:

output = client.run_command('exit 0')

# Wait for commands to complete and gather exit codes.
# Output is updated in-place.
client.join(output)
pprint(output.values()[0].exit_code)

# Output remains available in output generators
for host, host_output in output.items():
    for line in host_output.stdout:
        pprint(line)
Output:
0
<..stdout..>

There is also a built in host logger that can be enabled to log output from remote hosts. The helper function pssh.utils.enable_host_logger will enable host logging to stdout.

To log output without having to iterate over output generators, the consume_output flag can be enabled - for example:

from pssh.utils import enable_host_logger
enable_host_logger()
client.join(client.run_command('uname'), consume_output=True)
Output:
[localhost]       Linux

SFTP/SCP

SFTP is supported natively, no scp binary required.

For example to copy a local file to remote hosts in parallel:

from pssh.pssh_client import ParallelSSHClient
from pssh import utils
from gevent import joinall

utils.enable_logger(utils.logger)
hosts = ['myhost1', 'myhost2']
client = ParallelSSHClient(hosts)
cmds = client.copy_file('../test', 'test_dir/test')
joinall(cmds, raise_error=True)
Output:
Copied local file ../test to remote destination myhost1:test_dir/test
Copied local file ../test to remote destination myhost2:test_dir/test

There is similar capability to copy remote files to local ones suffixed with the host’s name with the copy_remote_file function.

Directory recursion is supported in both cases via the recurse parameter - defaults to off.

See SFTP documentation for more examples.

Design And Goals

ParallelSSH’s design goals and motivation are to provide a library for running non-blocking asynchronous SSH commands in parallel with little to no load induced on the system by doing so with the intended usage being completely programmatic and non-interactive.

To meet these goals, API driven solutions are preferred first and foremost. This frees up developers to drive the library via any method desired, be that environment variables, CI driven tasks, command line tools, existing OpenSSH or new configuration files, from within an application et al.

Scaling

Some guide lines on scaling ParallelSSH client and pool size numbers.

In general, long lived commands with little or no output gathering will scale better. Pool sizes in the multiple thousands have been used successfully with little CPU overhead in the single process running them in these use cases.

Conversely, many short lived commands with output gathering will not scale as well. In this use case, smaller pool sizes in the hundreds are likely to perform better with regards to CPU overhead in the event loop. Multiple python processes, each with its own event loop, may be used to scale this use case further as CPU overhead allows.

Gathering is highlighted here as output generation does not affect scaling. Only when output is gathered either over multiple still running commands, or while more commands are being triggered, is overhead increased.

Technical Details

To understand why this is, consider that in co-operative multi tasking, which is being used in this project via the gevent library, a co-routine (greenlet) needs to yield the event loop to allow others to execute - co-operation. When one co-routine is constantly grabbing the event loop in order to gather output, or when co-routines are constantly trying to start new short-lived commands, it causes overhead with other co-routines that also want to use the event loop.

This manifests itself as increased CPU usage in the process running the event loop and reduced performance with regards to scaling improvements from increasing pool size.

On the other end of the spectrum, long lived remote commands that generate no output only need the event loop at the start, when they are establishing connections, and at the end, when they are finished and need to gather exit codes, which results in practically zero CPU overhead at any time other than start or end of command execution.

Output generation is done remotely and has no effect on the event loop until output is gathered - output buffers are iterated on. Only at that point does the event loop need to be held.

User’s group

here is a public ParallelSSH Google group setup for this purpose - both posting and viewing are open to the public.

https://ga-beacon.appspot.com/UA-9132694-7/parallel-ssh/README.rst?pixel

Metadata

Release files for parallel-ssh 1.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for parallel-ssh 1.2.0
File Size Uploaded Provenance Actions
parallel-ssh-1.2.0.tar.gz 119.2 kB Without provenance Details for parallel-ssh-1.2.0.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for parallel-ssh 1.2.0
File Actions
parallel_ssh-1.2.0-cp36-cp36m-win_amd64.whl CPython 3.6 CPython 3.6 pymalloc Windows x86-64 Details for parallel_ssh-1.2.0-cp36-cp36m-win_amd64.whl
parallel_ssh-1.2.0-cp36-cp36m-win32.whl CPython 3.6 CPython 3.6 pymalloc Windows x86-32 Details for parallel_ssh-1.2.0-cp36-cp36m-win32.whl
parallel_ssh-1.2.0-cp36-cp36m-manylinux1_x86_64.whl CPython 3.6 CPython 3.6 pymalloc Linux glibc 2.5+ x86-64 Details for parallel_ssh-1.2.0-cp36-cp36m-manylinux1_x86_64.whl
parallel_ssh-1.2.0-cp35-cp35m-win_amd64.whl CPython 3.5 CPython 3.5 pymalloc Windows x86-64 Details for parallel_ssh-1.2.0-cp35-cp35m-win_amd64.whl
parallel_ssh-1.2.0-cp35-cp35m-win32.whl CPython 3.5 CPython 3.5 pymalloc Windows x86-32 Details for parallel_ssh-1.2.0-cp35-cp35m-win32.whl
parallel_ssh-1.2.0-cp35-cp35m-manylinux1_x86_64.whl CPython 3.5 CPython 3.5 pymalloc Linux glibc 2.5+ x86-64 Details for parallel_ssh-1.2.0-cp35-cp35m-manylinux1_x86_64.whl
parallel_ssh-1.2.0-cp34-cp34m-win_amd64.whl CPython 3.4 CPython 3.4 pymalloc Windows x86-64 Details for parallel_ssh-1.2.0-cp34-cp34m-win_amd64.whl
parallel_ssh-1.2.0-cp34-cp34m-win32.whl CPython 3.4 CPython 3.4 pymalloc Windows x86-32 Details for parallel_ssh-1.2.0-cp34-cp34m-win32.whl
parallel_ssh-1.2.0-cp34-cp34m-manylinux1_x86_64.whl CPython 3.4 CPython 3.4 pymalloc Linux glibc 2.5+ x86-64 Details for parallel_ssh-1.2.0-cp34-cp34m-manylinux1_x86_64.whl
parallel_ssh-1.2.0-cp33-cp33m-manylinux1_x86_64.whl CPython 3.3 CPython 3.3 pymalloc Linux glibc 2.5+ x86-64 Details for parallel_ssh-1.2.0-cp33-cp33m-manylinux1_x86_64.whl
parallel_ssh-1.2.0-cp27-cp27mu-manylinux1_x86_64.whl CPython 2.7 CPython 2.7 pymalloc wide-unicode Linux glibc 2.5+ x86-64 Details for parallel_ssh-1.2.0-cp27-cp27mu-manylinux1_x86_64.whl
parallel_ssh-1.2.0-cp27-cp27m-win_amd64.whl CPython 2.7 CPython 2.7 pymalloc Windows x86-64 Details for parallel_ssh-1.2.0-cp27-cp27m-win_amd64.whl
parallel_ssh-1.2.0-cp27-cp27m-win32.whl CPython 2.7 CPython 2.7 pymalloc Windows x86-32 Details for parallel_ssh-1.2.0-cp27-cp27m-win32.whl
parallel_ssh-1.2.0-cp27-cp27m-manylinux1_x86_64.whl CPython 2.7 CPython 2.7 pymalloc Linux glibc 2.5+ x86-64 Details for parallel_ssh-1.2.0-cp27-cp27m-manylinux1_x86_64.whl
parallel_ssh-1.2.0-cp27-cp27m-macosx_10_11_x86_64.whl CPython 2.7 CPython 2.7 pymalloc macOS 10.11+ x86-64 Details for parallel_ssh-1.2.0-cp27-cp27m-macosx_10_11_x86_64.whl
parallel_ssh-1.2.0-cp26-cp26mu-manylinux1_x86_64.whl CPython 2.6 CPython 2.6 pymalloc wide-unicode Linux glibc 2.5+ x86-64 Details for parallel_ssh-1.2.0-cp26-cp26mu-manylinux1_x86_64.whl
parallel_ssh-1.2.0-cp26-cp26m-manylinux1_x86_64.whl CPython 2.6 CPython 2.6 pymalloc Linux glibc 2.5+ x86-64 Details for parallel_ssh-1.2.0-cp26-cp26m-manylinux1_x86_64.whl

Total release size: 15.0 MB

Release files / parallel-ssh-1.2.0.tar.gz

Download URL parallel-ssh-1.2.0.tar.gz
Size 119.2 kB
Tags Source
SHA-256 checksum
How to use checksums
2c7b57d2332a65f46bf575d3d8cde5271fc37b4feaf31dbb295710fb92af122e
BLAKE2b-256 checksum
How to use checksums
cd22c4e9f5d977ef3ae7a39efe6baea708cb748dd46f3bbeaee1586ca133f563
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / parallel_ssh-1.2.0-cp36-cp36m-win_amd64.whl

Download URL parallel_ssh-1.2.0-cp36-cp36m-win_amd64.whl
Size 104.1 kB
Tags CPython 3.6 CPython 3.6 pymalloc Windows x86-64
SHA-256 checksum
How to use checksums
d6f4070cab98c5a06e7378c7be45242b2fa212707963f163fe6028503d44be4f
BLAKE2b-256 checksum
How to use checksums
054da1cf97d40d8b4e9cc9f4a710c9c21dd86ca65a0828914700b5255740017f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / parallel_ssh-1.2.0-cp36-cp36m-win32.whl

Download URL parallel_ssh-1.2.0-cp36-cp36m-win32.whl
Size 94.8 kB
Tags CPython 3.6 CPython 3.6 pymalloc Windows x86-32
SHA-256 checksum
How to use checksums
f4a7cb9e5a2f9ec9165a06366d276b78b980be232359c0c64f969c404ef0f446
BLAKE2b-256 checksum
How to use checksums
c4d90ce846e2710e5f181645700e4ca3b51abbc55057e47c8e1b250ef53195c1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / parallel_ssh-1.2.0-cp36-cp36m-manylinux1_x86_64.whl

Download URL parallel_ssh-1.2.0-cp36-cp36m-manylinux1_x86_64.whl
Size 1.6 MB
Tags CPython 3.6 CPython 3.6 pymalloc Linux glibc 2.5+ x86-64
SHA-256 checksum
How to use checksums
3250410b323f2db7e6d974daa868c61a95ef624f1a3421bcd4a38164d6927d28
BLAKE2b-256 checksum
How to use checksums
b4767702ad9e0b1562f41510113e728e1765e8a0cd5a0cbf488c2dae3f322395
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / parallel_ssh-1.2.0-cp35-cp35m-win_amd64.whl

Download URL parallel_ssh-1.2.0-cp35-cp35m-win_amd64.whl
Size 103.8 kB
Tags CPython 3.5 CPython 3.5 pymalloc Windows x86-64
SHA-256 checksum
How to use checksums
338a4bda3fc644aca9fb4a0192f08105f5d65c9485485dc26d276329871c7241
BLAKE2b-256 checksum
How to use checksums
9b7a285ee8368d6a01e6bdee8a542def7e7d64d013c29bf47875e73cb325ae2a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / parallel_ssh-1.2.0-cp35-cp35m-win32.whl

Download URL parallel_ssh-1.2.0-cp35-cp35m-win32.whl
Size 94.6 kB
Tags CPython 3.5 CPython 3.5 pymalloc Windows x86-32
SHA-256 checksum
How to use checksums
67b9913a8a300725ee0a989e73699e33d7d9b7c94b90697bcf35f9e3b891521c
BLAKE2b-256 checksum
How to use checksums
dab2ced14785f94dc2418166f8415fe0f00bb2204434783616dc126b697054e1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / parallel_ssh-1.2.0-cp35-cp35m-manylinux1_x86_64.whl

Download URL parallel_ssh-1.2.0-cp35-cp35m-manylinux1_x86_64.whl
Size 1.6 MB
Tags CPython 3.5 CPython 3.5 pymalloc Linux glibc 2.5+ x86-64
SHA-256 checksum
How to use checksums
cf9fedb21dc0e4f440c0ccc557669bc3c0aee897a52cb0283bf1b01e13402bb1
BLAKE2b-256 checksum
How to use checksums
3017ba727f7cba9177a552e26b8378c7e3b654a959d79d42bab5df3ad89504a2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / parallel_ssh-1.2.0-cp34-cp34m-win_amd64.whl

Download URL parallel_ssh-1.2.0-cp34-cp34m-win_amd64.whl
Size 101.8 kB
Tags CPython 3.4 CPython 3.4 pymalloc Windows x86-64
SHA-256 checksum
How to use checksums
18ceff865fb17473b9be7b26135783a6bed7a1ccec450667496a58675540ebef
BLAKE2b-256 checksum
How to use checksums
8a217d01137a18a73ec18a84a4c4050c707dd5c79d93972d645efa1fe503f7c2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / parallel_ssh-1.2.0-cp34-cp34m-win32.whl

Download URL parallel_ssh-1.2.0-cp34-cp34m-win32.whl
Size 95.2 kB
Tags CPython 3.4 CPython 3.4 pymalloc Windows x86-32
SHA-256 checksum
How to use checksums
6d51519476d6f3a46952053e45f9802a31bf104cd92d3c5045a3471ef079d742
BLAKE2b-256 checksum
How to use checksums
f2ceacdca1763ced0986d941fd570d5bfd227e80876ed9b5fde3fa73c8dd6865
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / parallel_ssh-1.2.0-cp34-cp34m-manylinux1_x86_64.whl

Download URL parallel_ssh-1.2.0-cp34-cp34m-manylinux1_x86_64.whl
Size 1.6 MB
Tags CPython 3.4 CPython 3.4 pymalloc Linux glibc 2.5+ x86-64
SHA-256 checksum
How to use checksums
ef4a5b5e2d3e612a05f7726c7b271f316740296a9a3002f130fd2c86122cf818
BLAKE2b-256 checksum
How to use checksums
2be9c68570c56b7527b55095d2e2b63e76a60cab834246780181af8dea06d92e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / parallel_ssh-1.2.0-cp33-cp33m-manylinux1_x86_64.whl

Download URL parallel_ssh-1.2.0-cp33-cp33m-manylinux1_x86_64.whl
Size 1.6 MB
Tags CPython 3.3 CPython 3.3 pymalloc Linux glibc 2.5+ x86-64
SHA-256 checksum
How to use checksums
a2b92e44bc8fe294d0cb2c7323784e6fbb1c9e1d0016a948183010a1b2d62317
BLAKE2b-256 checksum
How to use checksums
96862d6b3e0f49bd0cadd51b5613062ba8d4906504b4e301351adbeb471f8580
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / parallel_ssh-1.2.0-cp27-cp27mu-manylinux1_x86_64.whl

Download URL parallel_ssh-1.2.0-cp27-cp27mu-manylinux1_x86_64.whl
Size 1.6 MB
Tags CPython 2.7 CPython 2.7 pymalloc wide-unicode Linux glibc 2.5+ x86-64
SHA-256 checksum
How to use checksums
e83ce35c70a117f500c52591b6963d75e0299ce79390d135ef6e82a9d5e78761
BLAKE2b-256 checksum
How to use checksums
c856a68f02aad817a0be984754ac44bef8b0bc0eca47d929834682fff7823711
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / parallel_ssh-1.2.0-cp27-cp27m-win_amd64.whl

Download URL parallel_ssh-1.2.0-cp27-cp27m-win_amd64.whl
Size 102.9 kB
Tags CPython 2.7 CPython 2.7 pymalloc Windows x86-64
SHA-256 checksum
How to use checksums
f173a95d595547e1c4f2b0b63f2af6abfd526792f5e5b5edeaa8085d8eb31f80
BLAKE2b-256 checksum
How to use checksums
4d586b75d34209114334422e525d184d38806dc98a4c65274c9935b8542e5bf7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / parallel_ssh-1.2.0-cp27-cp27m-win32.whl

Download URL parallel_ssh-1.2.0-cp27-cp27m-win32.whl
Size 95.0 kB
Tags CPython 2.7 CPython 2.7 pymalloc Windows x86-32
SHA-256 checksum
How to use checksums
c470b782be92d68b3c87bfa529097aa107860c7c7ab0b55cb0fe381f208c1fad
BLAKE2b-256 checksum
How to use checksums
09d8baa0ca5e086341b74b79ff19510e79d9df5ec1837f2af7b407a23eeade18
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / parallel_ssh-1.2.0-cp27-cp27m-manylinux1_x86_64.whl

Download URL parallel_ssh-1.2.0-cp27-cp27m-manylinux1_x86_64.whl
Size 1.6 MB
Tags CPython 2.7 CPython 2.7 pymalloc Linux glibc 2.5+ x86-64
SHA-256 checksum
How to use checksums
ebf3a0386a7d2dbec5feae54c3aa56b1f6d82d7047833686d50aaccd26dca5d4
BLAKE2b-256 checksum
How to use checksums
17e15cb098722d7ca5a910c0559139feaa0631252516f6f486ec96fedff158c4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / parallel_ssh-1.2.0-cp27-cp27m-macosx_10_11_x86_64.whl

Download URL parallel_ssh-1.2.0-cp27-cp27m-macosx_10_11_x86_64.whl
Size 1.2 MB
Tags CPython 2.7 CPython 2.7 pymalloc macOS 10.11+ x86-64
SHA-256 checksum
How to use checksums
2ac0c894e398f2dfd778f49d2755090ed4e7bc76da85c8a2f6252d92b86c395f
BLAKE2b-256 checksum
How to use checksums
a78c321dc9cac8d9a929bff2000cbba16c3bd74cec4a02f5abd0ac16fca04906
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / parallel_ssh-1.2.0-cp26-cp26mu-manylinux1_x86_64.whl

Download URL parallel_ssh-1.2.0-cp26-cp26mu-manylinux1_x86_64.whl
Size 1.6 MB
Tags CPython 2.6 CPython 2.6 pymalloc wide-unicode Linux glibc 2.5+ x86-64
SHA-256 checksum
How to use checksums
0b95b11e8d0a367c68e0723576e4dca9df6cea7fb7806867a2d308960c6ac6b4
BLAKE2b-256 checksum
How to use checksums
e26496dece068df3ccc48b849be602c2e8f81a688ea7d3a82dbff03ef017b5c6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / parallel_ssh-1.2.0-cp26-cp26m-manylinux1_x86_64.whl

Download URL parallel_ssh-1.2.0-cp26-cp26m-manylinux1_x86_64.whl
Size 1.6 MB
Tags CPython 2.6 CPython 2.6 pymalloc Linux glibc 2.5+ x86-64
SHA-256 checksum
How to use checksums
2937a2fce7f0e478eb1dbb9b2f5d234f8c1471ec83ec60543aa8da27210df7af
BLAKE2b-256 checksum
How to use checksums
5849d6986d03f354ef7a55b296870be7a7a1b950d23d716fcc51dd07d648f848
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for parallel-ssh 1.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.2.0 This release

18 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page