Skip to main content

Build codecov Documentation

pystassh

An easy to use libssh wrapper to execute commands on a remote server via SSH with Python.

Installation

Just use pip to install the package:

pip install pystassh

pystassh is working with python 3+ and pypy.

Requirements

pystassh is using libssh to work, you will have to install the library before using pystassh. Only version 0.7.3 was used during the development, but versions 0.5 and above should work fine as well with pystassh. Visit libssh's official website for more information. libffi-dev is also required by the cffi module.

On Debian and Ubuntu:

apt-get install libssh-4 libffi-dev

On Fedora:

dnf install libssh libffi-devel

Examples

Establishing a connection:

>>> from pystassh import Session
>>> # With default private key
>>> session = Session('remote_host.org', username='user')
>>> # With username and password
>>> session = Session('remote_host.org', username='foo', password='bar')
>>> # With specific private key and a passphrase
>>> session = Session('remote_host.org', privkey_file='/home/user/.ssh/my_key', passphrase='baz')

Running simple commands:

>>> from pystassh import Session
>>> with Session('remote_host.org', username='user') as ssh_session:
...     res = ssh_session.execute('whoami')
>>> res.stdout
'foo'

Handling errors:

>>> from pystassh import Session
>>> with Session('remote_host.org', username='user') as ssh_session:
...     res = ssh_session.execute('whoam')
>>> res.stderr
'bash: whoam : command not found'

Running multiple commands:

>>> from pystassh import Session
>>> with Session('remote_host.org', username='user') as ssh_session:
...     ssh_session.execute('echo "bar" > /tmp/foo')
...     res = ssh_session.execute('cat /tmp/foo')
>>> res.stdout
'bar'

Using a session without a with block:

>>> from pystassh import Session
>>> ssh_session = Session('remote_host.org', username='user')
>>> ssh_session.connect()
>>> res = ssh_session.execute('whoami')
>>> res.stdout
'foo'
>>> ssh_session.disconnect()

Using a shell:

>>> from pystassh import Session
>>> with Session('remote_host.org', username='user') as ssh_session:
...     channel = ssh_session.channel
...     with channel:
...         channel.request_shell(request_pty=False)
...         # non blocking read to flush the motd, if there is one
...         channel.read_nonblocking(1024)
...         channel.write("export foo=42;\n")
...         channel.write("echo $foo;\n")
...         channel.read(2048)
b'42\n'

Documentation

The complete documentation is available at: http://pystassh.readthedocs.org/en/latest/

Metadata

Release files for pystassh 1.2.2

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

Built distribution (wheel)

Table of built distributions (wheels) for pystassh 1.2.2
File Interpreter ABI Platform Actions
pystassh-1.2.2-py3-none-any.whl Python 3 none any Details for pystassh-1.2.2-py3-none-any.whl

Release files / pystassh-1.2.2-py3-none-any.whl

Download URL pystassh-1.2.2-py3-none-any.whl
Size 14.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2a1afd630f4275ac4ebbe163452b079d4ec82d83d26a0fb5383be40b88ff4a47
BLAKE2b-256 checksum
How to use checksums
f13a939761aa3df7ba1d4d22476002bee853edd6b28f2bec3951c734ad959715
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.0 CPython/3.10.4

Security for pystassh 1.2.2

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.

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