Skip to main content

Super fast SSH library - bindings for libssh2

Project description

Super fast SSH2 protocol library. ssh2-python provides Python bindings for libssh2.

License Latest Version https://travis-ci.org/ParallelSSH/ssh2-python.svg?branch=master https://ci.appveyor.com/api/projects/status/github/parallelssh/ssh2-python?svg=true&branch=master https://img.shields.io/pypi/wheel/ssh2-python.svg https://img.shields.io/pypi/pyversions/ssh2-python.svg Latest documentation

Installation

Binary wheel packages are provided for Linux, OSX and Windows, all Python versions, with libssh2 and its required libraries included.

Wheel packages have no dependencies.

pip may need to be updated to be able to install binary wheel packages - pip install -U pip.

pip install ssh2-python

System packages are also available on the latest release page built on Centos/RedHat 6/7, Ubuntu 14.04/16.04, Debian 7/8 and Fedora 22/23/24.

System packages have no dependencies other than the libssh2 system library.

Conda is another installation option - see documentation for more detailed instructions.

API Feature Set

Currently the vast majority of the libssh2 API has been implemented with only few exceptions.

Complete example scripts for various operations can be found in the examples directory.

In addition, as ssh2-python is a thin wrapper of libssh2 with Python semantics, its code examples can be ported straight over to Python with only minimal changes.

Library Features

The library uses Cython based native code extensions as wrappers to libssh2.

Extension features:

  • Thread safe - GIL is released as much as possible

  • Very low overhead

  • Super fast as a consequence of the excellent C library it uses and prodigious use of native code

  • Object oriented - memory freed automatically and safely as objects are garbage collected by Python

  • Use Python semantics where applicable, such as context manager and iterator support for opening and reading from SFTP file handles

  • Expose errors as Python exceptions where possible

  • Provide access to libssh2 error code definitions

Quick Start

Both byte and unicode strings are accepted as arguments and encoded appropriately. To change default encoding, utf-8, change the value of ssh2.utils.ENCODING. Channel output is always byte strings.

See Complete Example for a complete example including socket connect.

Please use either the issue tracker for reporting issues with code or the mail group for discussion and questions.

Contributions are most welcome!

Authentication Methods

Connect and get available authentication methods.

from __future__ import print_function

from ssh2.session import Session

sock = <create and connect socket>

session = Session()
session.handshake(sock)
print(session.userauth_list())
['publickey', 'password', 'keyboard-interactive']

Agent Authentication

session.agent_auth(user)

Command Execution

channel = session.open_session()
channel.execute('echo Hello')

Reading Output

size, data = channel.read()
while(size > 0):
    print(data)
    size, data = channel.read()
Hello

Exit Code

print("Exit status: %s" % (channel.get_exit_status()))
Exit status: 0

Public Key Authentication

session.userauth_publickey_fromfile(
    username, 'my_pkey.pub', 'my_pkey', '')

Where '' can be a passphrase.

Password Authentication

session.userauth_password(
    username, '<my password>')

SFTP Read

sftp = session.sftp_init()
with sftp.open(<remote file to read>, 0, 0) as remote_fh, \
        open(<file to write>, 'wb') as local_fh:
    for size, data in remote_fh:
        local_fh.write(data)

Complete Example

A simple usage example looks very similar to libssh2 usage examples.

See examples directory for more complete example scripts.

As mentioned, ssh2-python is intentially a thin wrapper over libssh2 and directly maps most of its API.

Clients using this library can be much simpler to use than interfacing with the libssh2 API directly.

from __future__ import print_function

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; exit 2')
size, data = channel.read()
while size > 0:
    print(data)
    size, data = channel.read()
channel.close()
print("Exit status: %s" % channel.get_exit_status())
Output:

me

Exit status: 2

SSH Functionality currently implemented

  • SSH channel operations (exec,shell,subsystem) and methods

  • SSH agent functionality

  • Public key authentication and management

  • SFTP operations

  • SFTP file handles and attributes

  • SSH port forwarding and tunnelling

  • Non-blocking mode

  • SCP send and receive

  • Listener for port forwarding

  • Subsystem support

And more, as per libssh2 functionality.

Comparison with other Python SSH libraries

Performance of above example, compared with Paramiko.

time python examples/example_echo.py
time python examples/paramiko_comparison.py
Output:

ssh2-python:

real       0m0.141s
user       0m0.037s
sys        0m0.008s

paramiko:

real       0m0.592s
user       0m0.351s
sys        0m0.021s

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ssh2-python-0.9.1.tar.gz (532.6 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

ssh2_python-0.9.1-cp36-cp36m-win_amd64.whl (588.5 kB view details)

Uploaded CPython 3.6mWindows x86-64

ssh2_python-0.9.1-cp36-cp36m-win32.whl (505.5 kB view details)

Uploaded CPython 3.6mWindows x86

ssh2_python-0.9.1-cp36-cp36m-manylinux1_x86_64.whl (3.1 MB view details)

Uploaded CPython 3.6m

ssh2_python-0.9.1-cp35-cp35m-win_amd64.whl (586.2 kB view details)

Uploaded CPython 3.5mWindows x86-64

ssh2_python-0.9.1-cp35-cp35m-win32.whl (503.4 kB view details)

Uploaded CPython 3.5mWindows x86

ssh2_python-0.9.1-cp35-cp35m-manylinux1_x86_64.whl (3.1 MB view details)

Uploaded CPython 3.5m

ssh2_python-0.9.1-cp34-cp34m-win_amd64.whl (564.3 kB view details)

Uploaded CPython 3.4mWindows x86-64

ssh2_python-0.9.1-cp34-cp34m-win32.whl (503.5 kB view details)

Uploaded CPython 3.4mWindows x86

ssh2_python-0.9.1-cp34-cp34m-manylinux1_x86_64.whl (3.1 MB view details)

Uploaded CPython 3.4m

ssh2_python-0.9.1-cp33-cp33m-manylinux1_x86_64.whl (3.1 MB view details)

Uploaded CPython 3.3m

ssh2_python-0.9.1-cp27-cp27mu-manylinux1_x86_64.whl (3.0 MB view details)

Uploaded CPython 2.7mu

ssh2_python-0.9.1-cp27-cp27m-win_amd64.whl (568.7 kB view details)

Uploaded CPython 2.7mWindows x86-64

ssh2_python-0.9.1-cp27-cp27m-win32.whl (497.3 kB view details)

Uploaded CPython 2.7mWindows x86

ssh2_python-0.9.1-cp27-cp27m-manylinux1_x86_64.whl (3.0 MB view details)

Uploaded CPython 2.7m

ssh2_python-0.9.1-cp27-cp27m-macosx_10_12_x86_64.whl (2.0 MB view details)

Uploaded CPython 2.7mmacOS 10.12+ x86-64

ssh2_python-0.9.1-cp27-cp27m-macosx_10_11_x86_64.whl (2.0 MB view details)

Uploaded CPython 2.7mmacOS 10.11+ x86-64

ssh2_python-0.9.1-cp27-cp27m-macosx_10_10_intel.whl (2.2 MB view details)

Uploaded CPython 2.7mmacOS 10.10+ Intel (x86-64, i386)

File details

Details for the file ssh2-python-0.9.1.tar.gz.

File metadata

  • Download URL: ssh2-python-0.9.1.tar.gz
  • Upload date:
  • Size: 532.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for ssh2-python-0.9.1.tar.gz
Algorithm Hash digest
SHA256 39b5388c6b7a510aaf28079e017769bd7b9f2d6c834f649733b5fdf30fd39389
MD5 07236368ca1dda25369db859f2b4c719
BLAKE2b-256 870dc00a6399450b3ce9c0b23326613b04bac8741dc4b808f79f2aa4442af370

See more details on using hashes here.

File details

Details for the file ssh2_python-0.9.1-cp36-cp36m-win_amd64.whl.

File metadata

File hashes

Hashes for ssh2_python-0.9.1-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 698aa7c340cf3d1cd5808ce9081a789809b3368c44e491c40d9ca2fba0c29da7
MD5 e3927620e6f3b9f865f25d956afe2774
BLAKE2b-256 70ae302dc2d44631195be366ab4456657a8c3a2d0eed3aad6c3195cff2c5e867

See more details on using hashes here.

File details

Details for the file ssh2_python-0.9.1-cp36-cp36m-win32.whl.

File metadata

File hashes

Hashes for ssh2_python-0.9.1-cp36-cp36m-win32.whl
Algorithm Hash digest
SHA256 862cae10677fae3125ed545c45eab788babe5bee54344762a1350a53b226382e
MD5 6a74888f4a578661489b5bdf1db56215
BLAKE2b-256 4fc09e45614f86c62553b1aaafef5f5987edc7cb2217952fe58e79fb621d6e74

See more details on using hashes here.

File details

Details for the file ssh2_python-0.9.1-cp36-cp36m-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for ssh2_python-0.9.1-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 8997bc2ca6bdd7a771a2b8201fd1ec9c3cd2d33eea6bfe20414b402c28bb7fc3
MD5 9c479f66f42e72413a8b13a27d860342
BLAKE2b-256 815682929ed990248fe17513ae1b698ac38d1beb43cac55f44f835e4cb33e6ce

See more details on using hashes here.

File details

Details for the file ssh2_python-0.9.1-cp35-cp35m-win_amd64.whl.

File metadata

File hashes

Hashes for ssh2_python-0.9.1-cp35-cp35m-win_amd64.whl
Algorithm Hash digest
SHA256 96368bf55d19346f18385759a933cb147ee436c94818394ba1aa57d9acf9fdf5
MD5 c2a4406982d494f8712331c162826a48
BLAKE2b-256 4a61778eb8a20ff3fdad2bb13263e5f1ba414875e546ade36276a813942f7679

See more details on using hashes here.

File details

Details for the file ssh2_python-0.9.1-cp35-cp35m-win32.whl.

File metadata

File hashes

Hashes for ssh2_python-0.9.1-cp35-cp35m-win32.whl
Algorithm Hash digest
SHA256 427db90a394e9b85b2526a5ff726dc9cca254136a7ac98bbf34be09905e23b27
MD5 075a769fbc5718c5c84cc283fca4617b
BLAKE2b-256 15e0ca1b8c9c5ca9a6f2fb3663c791d905e2eb495df08a8fba4ebb227ff1e670

See more details on using hashes here.

File details

Details for the file ssh2_python-0.9.1-cp35-cp35m-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for ssh2_python-0.9.1-cp35-cp35m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 7811143a9e2395b84ded66e12c5abac5f2c3076ab236dfabeccc3628b1e11db9
MD5 6f12d253e3c69d7b5421e61383746091
BLAKE2b-256 7f11c0261afbc1281779e3131113a0f65c3d9792f2052dea17bc369349844bf2

See more details on using hashes here.

File details

Details for the file ssh2_python-0.9.1-cp34-cp34m-win_amd64.whl.

File metadata

File hashes

Hashes for ssh2_python-0.9.1-cp34-cp34m-win_amd64.whl
Algorithm Hash digest
SHA256 bfbb6ab756f5ed35daf9b0f6704ff60de497fed8291c05d0dff1b6e7f9b9eb2c
MD5 530297e97b4b38886d9a17be23bba212
BLAKE2b-256 d2f708b0852432da9a4462dfb86d01030b73bc87bd65dc68404b98c4b54253a6

See more details on using hashes here.

File details

Details for the file ssh2_python-0.9.1-cp34-cp34m-win32.whl.

File metadata

File hashes

Hashes for ssh2_python-0.9.1-cp34-cp34m-win32.whl
Algorithm Hash digest
SHA256 459857761e2f50df969684b33083d60f3e39cbb028c4439d2a758cf253bbcec0
MD5 9925096bae04cc7bdb78e4ed1910476a
BLAKE2b-256 74cc984b9ce900ac640259fba074669c188e8c57b147e25066b357f807f4e761

See more details on using hashes here.

File details

Details for the file ssh2_python-0.9.1-cp34-cp34m-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for ssh2_python-0.9.1-cp34-cp34m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 b0d833a15b61bb2825c51a3a77282974ad1a3c73941181dab5c55dbb18147f41
MD5 293fdcb9fabaebbe4e1ad20fc2465553
BLAKE2b-256 d9d3eadc22ca4d51745ca7f9cf45f9f3e8cd8cc6d76fc6ab99579d01ec141497

See more details on using hashes here.

File details

Details for the file ssh2_python-0.9.1-cp33-cp33m-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for ssh2_python-0.9.1-cp33-cp33m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 1db6580e376ed1590467e5386aabe2cd5b6455e042de96630300ab8301dcd6db
MD5 ef08c804800ea9267aa1a0cb19f485bc
BLAKE2b-256 a03a1982e455bac39ea2e0764452edbafba0257d1c810c16108866805c99a0fe

See more details on using hashes here.

File details

Details for the file ssh2_python-0.9.1-cp27-cp27mu-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for ssh2_python-0.9.1-cp27-cp27mu-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 cedff7ef8736e278887b5b4eb0dd242b80f790c8cfffc173e0a0330121aaa05c
MD5 a667279cae71681f4edd5d97ddc4eede
BLAKE2b-256 ae1fd661aebcbe1fb8ebf22e62d963bd2a52f97d0e49897d862b1d802a018e16

See more details on using hashes here.

File details

Details for the file ssh2_python-0.9.1-cp27-cp27m-win_amd64.whl.

File metadata

File hashes

Hashes for ssh2_python-0.9.1-cp27-cp27m-win_amd64.whl
Algorithm Hash digest
SHA256 7737ace1432958710ff4c4f0451d46b54a4418d6b20beff7e59673e0d340f678
MD5 ffdee9c40ab5460c07408c5012d73925
BLAKE2b-256 f0c3705c1e51f867825485b32cb4206c95e34344fa0faa1ed3acaec65480fdfc

See more details on using hashes here.

File details

Details for the file ssh2_python-0.9.1-cp27-cp27m-win32.whl.

File metadata

File hashes

Hashes for ssh2_python-0.9.1-cp27-cp27m-win32.whl
Algorithm Hash digest
SHA256 5ee97e7455111dd4c3a5764e5194b6914cce0164ae9b059630c419f305f72931
MD5 30e3d1f8332752538036d2927d09a5e4
BLAKE2b-256 12448fb80d3a3bc78c2d35146be6f4a8cbaf76606fa8c90df6f81a51eb4255ce

See more details on using hashes here.

File details

Details for the file ssh2_python-0.9.1-cp27-cp27m-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for ssh2_python-0.9.1-cp27-cp27m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 b5c1d3f3118293828dc0e8b5a00bb50370f6444b1db2eb9d46cfc58a820587bc
MD5 5bbc601e5905959457e471efb4a37c18
BLAKE2b-256 9fa907f7cdbe9930206036745392d77397f091c4330a569e1b1dbb021675407a

See more details on using hashes here.

File details

Details for the file ssh2_python-0.9.1-cp27-cp27m-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for ssh2_python-0.9.1-cp27-cp27m-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 93c484e1ca6a0aa559466ede22c7cff7232f34317068daeeed11c193d20e9633
MD5 fb72dcb33e30bdfd9c43cc74927152df
BLAKE2b-256 dbda5a85c9005ff9a73ef95ba4879bd48cbe3dfbfc4481525b748e8a299dbaa8

See more details on using hashes here.

File details

Details for the file ssh2_python-0.9.1-cp27-cp27m-macosx_10_11_x86_64.whl.

File metadata

File hashes

Hashes for ssh2_python-0.9.1-cp27-cp27m-macosx_10_11_x86_64.whl
Algorithm Hash digest
SHA256 ee9af2d2d8d3e65d91ef0fcbfdf64e86e89f7005b825a461acaae6669e38461a
MD5 63e1e2b06b2108d3e6248465d8e20543
BLAKE2b-256 c7d43e16ee4d0512f62015fe6b5e107d5d9bb8f63e08adffb13638579efcdc26

See more details on using hashes here.

File details

Details for the file ssh2_python-0.9.1-cp27-cp27m-macosx_10_10_intel.whl.

File metadata

File hashes

Hashes for ssh2_python-0.9.1-cp27-cp27m-macosx_10_10_intel.whl
Algorithm Hash digest
SHA256 46c0bcffd712a6ac1dfdfad627c32ce94f91a37fa8582ac297307f7be16c83f7
MD5 a8e5bfa809fbca69ff4dd4218bb3f15a
BLAKE2b-256 0798af12a92d435829e04049baeb0aedf7cee9cbb7f8b28a8db2535dccdbc228

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page