Python SSH libraries

Updated Nov 2026

Python SSH libraries open encrypted connections to remote machines to run commands, transfer files, and forward ports. A native client implements the SSH protocol in Python or binds a C library rather than driving the system ssh command. These libraries let deployment scripts, network automation tools, and AI agents operate servers and devices remotely.

Popularity

Pexpect has the most monthly downloads in this comparison, at 137.7M, a count that includes many non-SSH tasks.

LibraryMonthly downloadsStarsLast releaseLicense
Pexpect
137.7M
2.9KNov 2023ISC license
Paramiko
111.1M
9.9KOct 2026LGPL-2.1
AsyncSSH
16.3M
1.8KOct 2026EPL-2.0 OR GPL-2.0-or-later
sshtunnel
14.7M
1.3KOct 2026MIT
Fabric
7.9M
15.5KApr 2026BSD-2-Clause
Netmiko
967.5K
4.3KSep 2026MIT
ssh2-python
297.4K
237Oct 2025LGPL-2.1-only
ssh-python
237.5K
48Oct 2025LGPL-2.1-only
Downloads: PyPI, last thirty days. Stars and releases: GitHub. Amber: no release in over a year.

Libraries and code examples

Controls interactive console applications.

Downloads / mo
137.7M
Stars
2.9K
Last release
4.9.0
License
ISC license

Quickstart

From pxssh.py
$ pip install pexpect
from pexpect import pxssh
s = pxssh.pxssh()
s.login(hostname, username, password)
s.sendline('uptime')   # run a command
s.prompt()             # match the prompt
print(s.before)        # print everything before the prompt.
s.logout()

Pexpect examples

From open-source projects on GitHub

Provides an SSH client for authentication, commands, and SFTP sessions.

Downloads / mo
111.1M
Stars
9.9K
Last release
5.1.0
License
LGPL-2.1

Strengths

  • Runs remote SSH commands. Execute a command and access its standard input, output and error streams.
  • Exposes an SFTP client. Open an SFTP session over the established SSH connection.

Limitations

  • Unknown hosts need trusted keys. Load trusted host keys before connecting to a new SSH server.
  • Channel operations need explicit timeouts. Set timeout to bound blocking channel reads and writes.

Quickstart

From __init__.py
$ pip install paramiko
from paramiko.client import (
    AutoAddPolicy,
    MissingHostKeyPolicy,
    RejectPolicy,
    SSHClient,
    WarningPolicy,
)

client = SSHClient()
client.load_system_host_keys()
client.connect('ssh.example.com')
stdin, stdout, stderr = client.exec_command('ls -l')

Paramiko examples

From open-source projects on GitHub

Implements asynchronous SSH clients and servers on asyncio.

Downloads / mo
16.3M
Stars
1.8K
Last release
2.24.1
License
EPL-2.0 OR GPL-2.0-or-later

Strengths

  • Fits asyncio applications. Await SSH operations within an existing asyncio application.
  • Connects through existing SSH sessions. Use a connection tunnel to reach hosts behind an SSH gateway.

Limitations

  • Hardware keys need another package. Install fido2 for compatible hardware security-key authentication.

Quickstart

From latest.md
$ pip install asyncssh
import asyncio, asyncssh, sys

async def run_client():
    async with asyncssh.connect('localhost') as conn:
        result = await conn.run('echo "Hello!"', check=True)
        print(result.stdout, end='')

try:
    asyncio.run(run_client())
except (OSError, asyncssh.Error) as exc:
    sys.exit('SSH connection failed: ' + str(exc))

AsyncSSH examples

From open-source projects on GitHub

Opens SSH tunnels in pure Python.

Downloads / mo
14.7M
Stars
1.3K
Last release
0.5.1
License
MIT

Quickstart

From README.rst
$ pip install sshtunnel
from sshtunnel import SSHTunnelForwarder

server = SSHTunnelForwarder(
    'alfa.8iq.dev',
    ssh_username="pahaz",
    ssh_password="secret",
    remote_bind_address=('127.0.0.1', 8080)
)

server.start()

print(server.local_bind_port)  # show assigned local port
# work with `SECRET SERVICE` through `server.local_bind_port`.

server.stop()

sshtunnel examples

From open-source projects on GitHub

Runs shell commands remotely over SSH.

Downloads / mo
7.9M
Stars
15.5K
Last release
3.2.3
License
BSD-2-Clause

Strengths

  • Captures remote command results. Inspect captured output, exit status, and success through the returned result.
  • Includes SSH gateway configuration. Use ProxyJump-style connections or ProxyCommand-style gateways.

Limitations

  • Connections need explicit cleanup. Close connections or use a context manager to avoid shutdown hangs.

Quickstart

From getting-started.html
$ pip install fabric
from fabric import Connection
c = Connection('web1')
result = c.run('uname -s')

Simplifies command-line connections to network devices from multiple vendors.

Downloads / mo
967.5K
Stars
4.3K
Last release
4.8.0
License
MIT

Strengths

  • Targets network-device command lines. Select a device driver suited to the target network platform.
  • Sends network configuration commands. Apply a list of configuration commands through send_config_set.

Limitations

  • Device profiles must match hardware. Set device_type to a supported platform before connecting.

Quickstart

From EXAMPLES.md
$ pip install netmiko
from netmiko import ConnectHandler
from getpass import getpass

cisco1 = {
    "device_type": "cisco_ios",
    "host": "cisco1.lasthop.io",
    "username": "pyclass",
    "password": getpass(),
}

net_connect = ConnectHandler(**cisco1)
print(net_connect.find_prompt())
net_connect.disconnect()

Netmiko examples

From open-source projects on GitHub

Binds the libssh2 C library.

Downloads / mo
297.4K
Stars
237
Last release
1.2.0.post1
License
LGPL-2.1-only

Quickstart

From example_echo.py
$ pip install ssh2-python
import os
import socket
from ssh2.session import Session
host = 'localhost'
user = os.getlogin()
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((host, 22))
session = Session()
session.handshake(sock)
session.agent_auth(user)
channel = session.open_session()
channel.execute('echo me')

ssh2-python examples

From open-source projects on GitHub

Binds the libssh C library to Python.

Downloads / mo
237.5K
Stars
48
Last release
1.2.0.post1
License
LGPL-2.1-only

Quickstart

From exec.py
$ pip install ssh-python
import socket

from ssh.session import Session
from ssh import options

USERNAME = 'your-user'
HOST = 'localhost'
PORT = 22

sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((HOST, PORT))

s = Session()
s.options_set(options.HOST, HOST)
s.options_set(options.USER, USERNAME)
s.options_set_port(PORT)
s.set_socket(sock)
s.connect()

# Authenticate with agent
s.userauth_agent(USERNAME)

chan = s.channel_new()
chan.open_session()
chan.request_exec('echo me')
size, data = chan.read()
while size > 0:
    print(data.strip())
    size, data = chan.read()
chan.close()

ssh-python examples

From open-source projects on GitHub

FAQ

Paramiko suits most scripts, with native Python SSH and SFTP clients. AsyncSSH suits asyncio code. Fabric suits remote commands and file transfers across hosts. Netmiko suits CLI sessions on network devices.

Paramiko implements the SSH protocol in Python, with SSH and SFTP client and server building blocks. Fabric and sshtunnel build on it.

Netmiko is a multi-vendor library for CLI connections to network devices, with prompt handling and platform-specific commands.

Pexpect controls interactive console applications. Its pxssh module drives the system SSH client through a terminal session.

AsyncSSH implements its client and server on the asyncio framework. Paramiko uses blocking channel reads and writes.

Its default missing-host-key policy rejects an unknown key. Load the trusted host keys before connecting.

For coding agents

Found your SSH library? Help your agent use it.

Connect Exa so your coding agent can find the library’s documentation, check its API, and look up implementations while you build.

Run in your terminal

claude plugin install exa@claude-plugins-official