Skip to content
JacobCallahanPublic

About

SSH for Humans

Topics

Resources

Stars

20 stars

Watchers

1 watching

Forks

Latest commit

Β 

History

115 Commits

Folders and files

Repository files navigation

Hussh: SSH for humans.

image image PyPI - Wheel Actions status

Hussh (pronounced "hush") is a client-side ssh library that offers low level performance through a high level interface.

Hussh uses pyo3 to create Python bindings around the ssh2 and russh libraries for Rust; these allow for synchronous and asynchronous ssh connections.

Installation

pip install hussh

Table of Contents

QuickStart

Hussh's synchronous Connection class will likely be your primary interface.

from hussh import Connection

conn = Connection(host="my.test.server", username="user", password="pass")
result = conn.execute("ls")
print(result.stdout)

Connections recover brief network interruptions automatically before new actions (auto_reconnect=True, max_retries=3, retry_interval=1.5 seconds). Choose auto_reconnect=False for immediate failure or your own retry policy. Commands are never replayed once submission starts; an interrupted command raises HusshIncompleteCommandError because execution may already have occurred. See connection recovery for explicit reconnect(), failure latency, timeout behavior, and transfer limits.

That's it! One import and class instantion is all you need to:

  • Execute commands
  • Perform SCP actions
  • Perform SFTP actions
  • Get an interactive shell

Why Hussh?

  • πŸ”₯ Blazingly fast!
  • πŸͺΆ Incredibly lightweight!
  • 🧠 Super easy to use!
  • ⚑ Asynchronous!
  • πŸ₯ž Concurrency!

Benchmarks

Hussh demonstrates the performance you'd expect from a low level ssh library. Hussh is also much lighter weight in both total memory and memory allocations.

Local Server Local Server Benchmarks

Remote Server Remote Server Benchmarks

Try it for yourself!

Hussh's benchmark script are also open sourced in the benchmarks directory in this repository. Clone the repo, follow the setup instructions, then let us know how it did!

Synchronous Usage

Authentication

from hussh import Connection

# Password authentication
conn = Connection(host="my.test.server", username="user", password="pass")

# Key-based authentication
conn = Connection(host="my.test.server", private_key="~/.ssh/id_rsa")

# Connect through a jump host (ProxyJump)
jump = Connection(host="bastion.example.com", username="user", private_key="~/.ssh/id_rsa")
conn = Connection("target.internal", username="user", proxy_jump=jump)

# Connect through a proxy command (ProxyCommand)
conn = Connection(
    "target.internal",
    username="user",
    proxy_command="ssh -W %h:%p bastion.example.com",
)

Executing Commands

result = conn.execute("whoami")
print(result.stdout, result.stderr, result.status)

File Transfers (SFTP)

# Write a local file to remote
conn.sftp_write(local_path="/path/to/my/file", remote_path="/dest/path/file")

# Read a remote file
contents = conn.sftp_read(remote_path="/dest/path/file")

# Upload an entire local directory recursively
transferred, failed = conn.sftp_put_dir("/local/build/", "/remote/app/")

# Download an entire remote directory recursively
transferred, failed = conn.sftp_get_dir("/remote/logs/", "/local/logs/")

πŸ“š For complete documentation including SCP, file tailing, interactive shells, and more, see Synchronous Usage.

Asynchronous Usage

Hussh offers an AsyncConnection class for asynchronous operations.

import asyncio
from hussh.aio import AsyncConnection

async def main():
    async with AsyncConnection(host="my.test.server", username="user", password="pass") as conn:
        result = await conn.execute("ls")
    print(result.stdout)

    jump = AsyncConnection("bastion.example.com", username="user", key_path="~/.ssh/id_rsa")
    async with AsyncConnection("target.internal", username="user", proxy_jump=jump) as target:
        await target.execute("hostname")

    async with AsyncConnection(
        "target.internal",
        username="user",
        proxy_command="ssh -W %h:%p bastion.example.com",
    ) as proxied:
        await proxied.execute("hostname")

asyncio.run(main())

πŸ“š For complete documentation including timeouts, async SFTP, interactive shells, and file tailing, see Asynchronous Usage.

Concurrent Operations (MultiConnection)

When you need to execute commands or transfer files across multiple hosts simultaneously, use MultiConnection.

from hussh.multi_conn import MultiConnection

# Create connections with shared authentication
mc = MultiConnection.from_shared_auth(
    hosts=["server1", "server2", "server3"],
    username="user",
    password="pass",
)

# Execute on all hosts
with mc:
    results = mc.execute("whoami")
    for host, result in results.items():
        print(f"{host}: {result.stdout.strip()}")

πŸ“š For complete documentation including MultiResult handling, SFTP operations, file tailing, error handling, and concurrency control, see MultiConnection Usage.

Development

On Fedora, with make, uv, and Rust/Cargo available, run:

make setup-dev
source .venv/bin/activate

This uses sudo dnf to install GCC, Perl's core modules, OpenSSL development headers, and pkg-config. It creates .venv if needed and installs Hussh editably with the existing dev dependencies. Perl's core modules are needed to build vendored OpenSSL, including the FindBin module.

After changing Rust code, rebuild with maturin develop --uv in the activated environment. Run tests through tox, for example tox -e py314.

Documentation

For detailed guides and complete API documentation, see the docs directory:

Guide Description
Synchronous Usage Full Connection documentation: auth, SFTP, SCP, tailing, shells
Asynchronous Usage Full AsyncConnection documentation: timeouts, async operations
MultiConnection Usage Concurrent operations across multiple hosts

Disclaimer

This is an early project that should not be used in sensitive production code! With that said, try it out and let me know your thoughts!

Future Features

  • Low level bindings
  • TBD...

About

SSH for Humans

Topics

Resources

Stars

20 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages