ssh2-python
Bindings for libssh2 C library
What it is and what it does
ssh2-python is a thin Python wrapper around libssh2, the C library that implements the SSH2 protocol. It exposes the low-level libssh2 API directly to Python, allowing developers to perform SSH operations with minimal overhead. The package is distributed as pre-compiled binary wheels for major platforms and Python versions, with no runtime dependencies.
This is intentionally a low-level binding, not a high-level client library. It requires manual management of sessions, channels, and authentication, and substantial boilerplate code for common tasks. The documentation explicitly recommends that most developers use higher-level clients instead, which provide a simpler interface built on top of ssh2-python. Use ssh2-python only if you need direct control over libssh2 semantics or are building a specialized SSH tool.
Use it for:
- Building a custom SSH client or server with fine-grained control over protocol behavior and performance.
- Implementing SSH functionality in performance-critical applications where C-API overhead matters.
- Porting existing libssh2 C code examples to Python with minimal changes.
- Creating SSH automation tools that require low-level session and channel manipulation.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
ssh2-python provides Python bindings to libssh2, a low-level SSH2 protocol library, enabling direct access to SSH2 operations via C-API semantics.
Yes, if you need direct libssh2 bindings and understand the low-level API. No, if you want a simple SSH client—higher-level alternatives are recommended. The package is stable, actively maintained, has no known vulnerabilities, and offers good platform coverage. The LGPL-2.1-only license requires derivative works to be released under the same license, which may constrain proprietary use.
Install
ssh2-python on PyPI
pip
pip install ssh2-pythonuv
uv add ssh2-pythonpoetry
poetry add ssh2-pythonInstalling ssh2-python
Before you install
Binary wheels are provided for Linux, macOS, and Windows across Python 3.8, 3.9, 3.10, 3.11, 3.12, 3.13, and 3.14, with no runtime dependencies. Install friction is medium due to the compiled nature of the bindings, but pre-built wheels eliminate build-time complexity for most platforms. Repository is actively maintained with a recent commit on 2026-06-12.
License in practice
Licensed under LGPL-2.1-only (copyleft). Any derivative work or modification must be released under the same license; static linking or bundling may trigger additional obligations depending on your distribution model.
Quickstart
pip install ssh2-python
import ssh2
session = ssh2.Session()
session.handshake('hostname')
session.userauth_password('user', 'password')
channel = session.open_session()
channel.execute('ls')
size, data = channel.read()
print(data.decode())
Requires a working SSH server to connect to; this is a low-level C-API wrapper and demands manual session and channel lifecycle management.
Verify before relying
- Whether the package supports key-based authentication or only password authentication.
- What the minimum Python version is (requires_python is unspecified in metadata).
- Whether PyPy support is actively tested or only declared in classifiers.
Package facts
| License | LGPL-2.1-only (copyleft) |
| Python support | not specified |
| Install friction | medium — platform-specific wheel |
| Runtime dependencies | none |
| Maintenance | actively maintained — 306 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 316,997/month — #7,669 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: ssh2_python-1.2.0.post1-cp310-cp310-manylinux2014_aarch64.manylinux_2_17_aarch64.whl; ssh2_python-1.2.0.post1-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.whl; ssh2_python-1.2.0.post1-cp310-cp310-win_amd64.whl; ssh2_python-1.2.0.post1-cp311-cp311-macosx_12_0_arm64.whl; ssh2_python-1.2.0.post1-cp311-cp311-macosx_13_0_arm64.whl; ssh2_python-1.2.0.post1-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.whl; ssh2_python-1.2.0.post1-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl; ssh2_python-1.2.0.post1-cp311-cp311-win_amd64.whl; ssh2_python-1.2.0.post1-cp312-cp312-macosx_14_0_arm64.whl; ssh2_python-1.2.0.post1-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.whl; ssh2_python-1.2.0.post1-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl; ssh2_python-1.2.0.post1-cp312-cp312-win_amd64.whl; ssh2_python-1.2.0.post1-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.whl; ssh2_python-1.2.0.post1-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl; ssh2_python-1.2.0.post1-cp313-cp313-win_amd64.whl; ssh2_python-1.2.0.post1-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.whl; ssh2_python-1.2.0.post1-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.whl; ssh2_python-1.2.0.post1-cp314-cp314t-manylinux2014_aarch64.manylinux_2_17_aarch64.whl; ssh2_python-1.2.0.post1-cp314-cp314t-manylinux2014_x86_64.manylinux_2_17_x86_64.whl; ssh2_python-1.2.0.post1-cp38-cp38-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Tags
More Libraries packages
urllib3 is an HTTP client library that provides…
permissive · top 100 on PyPI
requestsRequests is a Python HTTP library that…
permissive · top 100 on PyPI
pluggyPluggy provides a plugin system that lets you…
permissive · top 100 on PyPI
python-dateutilProvides parsing, arithmetic, and recurrence…
permissive · top 100 on PyPI
sixSix provides utility functions to write Python…
permissive · top 100 on PyPI
pytestpytest is a testing framework that lets you…
permissive · top 100 on PyPI
ssh-pythonPython bindings to the libssh C library for SSH…
copyleft · top 15,000 on PyPI
paramikoParamiko is a pure-Python SSH protocol library…
copyleft · top 1,000 on PyPI
fs.sshfsfs.sshfs provides a PyFilesystem2 interface to…
copyleft · top 15,000 on PyPI
installerA low-level library for unpacking and…
permissive · top 1,000 on PyPI
parallel-sshAsynchronous SSH client for running commands on…
copyleft · top 15,000 on PyPI
sshtunnelEstablishes SSH tunnels to forward local ports…
permissive · top 1,000 on PyPI
scpProvides file transfer over SSH using the SCP…
copyleft · top 5,000 on PyPI
jumpsshJumpSSH runs commands on remote servers through…
permissive · top 15,000 on PyPI
PyNaClPyNaCl provides Python bindings to libsodium…
permissive · top 1,000 on PyPI
asyncsshAsyncSSH provides an asynchronous SSH client…
copyleft · top 5,000 on PyPI