ssh2-python3


Namessh2-python3 JSON
Version 1.11.1 PyPI version JSON
download
home_pagehttps://github.com/pycopia/ssh2-python3
SummarySuper fast SSH library - bindings for libssh2 and Python 3
upload_time2023-04-13 21:03:02
maintainerKeith Dart
docs_urlNone
authorPanos Kittenis
requires_python>=3.8
licenseLGPLv2
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ssh2-python3
============

Super fast SSH2 protocol library.
This `ssh2-python3` package provides Python bindings for [libssh2][libssh2].

[![License](https://img.shields.io/badge/License-LGPL%20v2-blue.svg)](https://pypi.python.org/pypi/ssh2-python3)

This is a forked and modified version of the original, *ssh2-python*.

Notable changes:

- Supports Python 3 only.
- Uses exclusively the embedded libssh2 (also modified to support Unix tunnel targets).
- Compiles libbsh2 to use Python's memory allocator.
- Some new methods that support:
  - Unix domain socket tunnel target on server host.
  - The "signal" protocol message.
  - Generic message constructor.
  - Bug fixes. Notably, a segfault during garbage collection in certain situations.

Any new bugs are the result of myself and not the orignal author (Panos Kittenis).
Many thanks for his fine work to get this started.

Installation
------------

Binary wheel packages are provided for Linux, all recent Python versions. Wheel packages have **no
dependencies**.

You may need to update `pip` to install recent binary wheel packages - `pip install -U pip`.

```console
pip install ssh2-python3
```

API Feature Set
---------------

At this time all of the `libssh2` API has been implemented up to version `1.9.1-embedded`.

In addition, as `ssh2-python3` is a thin wrapper of `libssh2` with Python 3 semantics,
its [code examples](https://libssh2.org/examples/) can be ported straight over to Python with only minimal
changes.

Library Features
----------------

The library uses [Cython][Cython] based native code extensions as wrappers for `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, and uses Python's memory allocator.
- Use Python semantics where applicable, such as context manager and iterator support for
  opening and reading from SFTP file handles
- Raise errors as Python exceptions
- 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`. Output is always in byte strings.

Contributions are most welcome!

Authentication Methods
----------------------

Connect and get available authentication methods.

```python
from ssh2.session import Session

sock = <create and connect socket>

session = Session()
session.handshake(sock)
print(session.userauth_list())
```

Output will vary depending on SSH server configuration. For example:

```python
['publickey', 'password', 'keyboard-interactive']
```

Agent Authentication
--------------------

```python
session.agent_auth(user)
```

Command Execution
------------------------

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

Reading Output
---------------

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

```console
Hello
```

Exit Code
--------------

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

```python
   Exit status: 0
```

Public Key Authentication
-------------------------

```python
session.userauth_publickey_fromfile(username, 'private_key_file')
```

Passphrase can be provided with the `passphrase` keyword param.

Password Authentication
----------------------------

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

SFTP Read
-----------

```python
from ssh2.sftp import LIBSSH2_FXF_READ, LIBSSH2_SFTP_S_IRUSR

sftp = session.sftp_init()
with sftp.open(<remote file to read>,
      LIBSSH2_FXF_READ, LIBSSH2_SFTP_S_IRUSR) as remote_fh, \
       open(<local 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](https://www.libssh2.org/examples/).

As mentioned, `ssh2-python3` is intentionally 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.

```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; 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:

```console
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, for both TCP and Unix sockets.
- Non-blocking mode
- SCP send and receive
- Listener for port forwarding
- Subsystem support
- Host key checking and manipulation
- Signal remote process.

And more, as per [libssh2][libssh2] functionality.

[Cython]: https://www.cython.org
[libssh2]: https://www.libssh2.org

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/pycopia/ssh2-python3",
    "name": "ssh2-python3",
    "maintainer": "Keith Dart",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "keith.dart@gmail.com",
    "keywords": "",
    "author": "Panos Kittenis",
    "author_email": "22e889d8@opayq.com",
    "download_url": "https://files.pythonhosted.org/packages/63/68/abe21160e2b8deea39a0e9e7d16a50775b4b9382c0c3561d96bc0a94940b/ssh2-python3-1.11.1.tar.gz",
    "platform": "linux_x86_64",
    "description": "ssh2-python3\n============\n\nSuper fast SSH2 protocol library.\nThis `ssh2-python3` package provides Python bindings for [libssh2][libssh2].\n\n[![License](https://img.shields.io/badge/License-LGPL%20v2-blue.svg)](https://pypi.python.org/pypi/ssh2-python3)\n\nThis is a forked and modified version of the original, *ssh2-python*.\n\nNotable changes:\n\n- Supports Python 3 only.\n- Uses exclusively the embedded libssh2 (also modified to support Unix tunnel targets).\n- Compiles libbsh2 to use Python's memory allocator.\n- Some new methods that support:\n  - Unix domain socket tunnel target on server host.\n  - The \"signal\" protocol message.\n  - Generic message constructor.\n  - Bug fixes. Notably, a segfault during garbage collection in certain situations.\n\nAny new bugs are the result of myself and not the orignal author (Panos Kittenis).\nMany thanks for his fine work to get this started.\n\nInstallation\n------------\n\nBinary wheel packages are provided for Linux, all recent Python versions. Wheel packages have **no\ndependencies**.\n\nYou may need to update `pip` to install recent binary wheel packages - `pip install -U pip`.\n\n```console\npip install ssh2-python3\n```\n\nAPI Feature Set\n---------------\n\nAt this time all of the `libssh2` API has been implemented up to version `1.9.1-embedded`.\n\nIn addition, as `ssh2-python3` is a thin wrapper of `libssh2` with Python 3 semantics,\nits [code examples](https://libssh2.org/examples/) can be ported straight over to Python with only minimal\nchanges.\n\nLibrary Features\n----------------\n\nThe library uses [Cython][Cython] based native code extensions as wrappers for `libssh2`.\n\nExtension features:\n\n- Thread safe - GIL is released as much as possible\n- Very low overhead\n- Super fast as a consequence of the excellent C library it uses and prodigious use of native code\n- Object oriented - memory freed automatically and safely as objects are garbage collected by\n  Python, and uses Python's memory allocator.\n- Use Python semantics where applicable, such as context manager and iterator support for\n  opening and reading from SFTP file handles\n- Raise errors as Python exceptions\n- Provide access to `libssh2` error code definitions\n\nQuick Start\n-----------\n\nBoth byte and unicode strings are accepted as arguments and encoded appropriately. To change default\nencoding, `utf-8`, change the value of `ssh2.utils.ENCODING`. Output is always in byte strings.\n\nContributions are most welcome!\n\nAuthentication Methods\n----------------------\n\nConnect and get available authentication methods.\n\n```python\nfrom ssh2.session import Session\n\nsock = <create and connect socket>\n\nsession = Session()\nsession.handshake(sock)\nprint(session.userauth_list())\n```\n\nOutput will vary depending on SSH server configuration. For example:\n\n```python\n['publickey', 'password', 'keyboard-interactive']\n```\n\nAgent Authentication\n--------------------\n\n```python\nsession.agent_auth(user)\n```\n\nCommand Execution\n------------------------\n\n```python\nchannel = session.open_session()\nchannel.execute('echo Hello')\n```\n\nReading Output\n---------------\n\n```python\n   size, data = channel.read()\n   while(size > 0):\n       print(data)\n       size, data = channel.read()\n```\n\n```console\nHello\n```\n\nExit Code\n--------------\n\n```python\nprint(\"Exit status: %s\" % (channel.get_exit_status()))\n```\n\n```python\n   Exit status: 0\n```\n\nPublic Key Authentication\n-------------------------\n\n```python\nsession.userauth_publickey_fromfile(username, 'private_key_file')\n```\n\nPassphrase can be provided with the `passphrase` keyword param.\n\nPassword Authentication\n----------------------------\n\n```python\n   session.userauth_password(username, '<my password>')\n```\n\nSFTP Read\n-----------\n\n```python\nfrom ssh2.sftp import LIBSSH2_FXF_READ, LIBSSH2_SFTP_S_IRUSR\n\nsftp = session.sftp_init()\nwith sftp.open(<remote file to read>,\n      LIBSSH2_FXF_READ, LIBSSH2_SFTP_S_IRUSR) as remote_fh, \\\n       open(<local file to write>, 'wb') as local_fh:\n   for size, data in remote_fh:\n       local_fh.write(data)\n```\n\nComplete Example\n----------------\n\nA simple usage example looks very similar to\n`libssh2` [usage examples](https://www.libssh2.org/examples/).\n\nAs mentioned, `ssh2-python3` is intentionally a thin wrapper over `libssh2` and directly maps most\nof its API.\n\nClients using this library can be much simpler to use than interfacing with the `libssh2` API\ndirectly.\n\n```python\nimport os\nimport socket\n\nfrom ssh2.session import Session\n\nhost = 'localhost'\nuser = os.getlogin()\n\nsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)\nsock.connect((host, 22))\n\nsession = Session()\nsession.handshake(sock)\nsession.agent_auth(user)\n\nchannel = session.open_session()\nchannel.execute('echo me; exit 2')\nsize, data = channel.read()\nwhile size > 0:\n   print(data)\n   size, data = channel.read()\nchannel.close()\nprint(\"Exit status: %s\" % channel.get_exit_status())\n```\n\nOutput:\n\n```console\nme\n\nExit status: 2\n```\n\nSSH Functionality currently implemented\n---------------------------------------\n\n- SSH channel operations (exec,shell,subsystem) and methods\n- SSH agent functionality\n- Public key authentication and management\n- SFTP operations\n- SFTP file handles and attributes\n- SSH port forwarding and tunnelling, for both TCP and Unix sockets.\n- Non-blocking mode\n- SCP send and receive\n- Listener for port forwarding\n- Subsystem support\n- Host key checking and manipulation\n- Signal remote process.\n\nAnd more, as per [libssh2][libssh2] functionality.\n\n[Cython]: https://www.cython.org\n[libssh2]: https://www.libssh2.org\n",
    "bugtrack_url": null,
    "license": "LGPLv2",
    "summary": "Super fast SSH library - bindings for libssh2 and Python 3",
    "version": "1.11.1",
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "2730fcd1e700f5b5b55e5db8e09af43f1a938a550417e8acd15875cbe3ff8489",
                "md5": "74cd861dc770bc86cadfdc4da9300af6",
                "sha256": "fd1cdcf74b0b7f3a1277173784bca7a7eccd4fa7cd4882bb2156430c6f791eb2"
            },
            "downloads": -1,
            "filename": "ssh2_python3-1.11.1-cp310-cp310-manylinux_2_27_x86_64.whl",
            "has_sig": false,
            "md5_digest": "74cd861dc770bc86cadfdc4da9300af6",
            "packagetype": "bdist_wheel",
            "python_version": "cp310",
            "requires_python": ">=3.8",
            "size": 2888080,
            "upload_time": "2023-04-13T21:02:40",
            "upload_time_iso_8601": "2023-04-13T21:02:40.732546Z",
            "url": "https://files.pythonhosted.org/packages/27/30/fcd1e700f5b5b55e5db8e09af43f1a938a550417e8acd15875cbe3ff8489/ssh2_python3-1.11.1-cp310-cp310-manylinux_2_27_x86_64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b84afb4c9cf6ad1fd77d188a2151b70e6389224b2ce58f1f36f0f032dce721ea",
                "md5": "68a6e374a0fb1a59d26ae57528a86f2c",
                "sha256": "2844c8ca8502009aefc1921e545f7898432f4a8a29c308ee7f890e98a7e34fda"
            },
            "downloads": -1,
            "filename": "ssh2_python3-1.11.1-cp311-cp311-manylinux_2_27_x86_64.whl",
            "has_sig": false,
            "md5_digest": "68a6e374a0fb1a59d26ae57528a86f2c",
            "packagetype": "bdist_wheel",
            "python_version": "cp311",
            "requires_python": ">=3.8",
            "size": 2859543,
            "upload_time": "2023-04-13T21:02:32",
            "upload_time_iso_8601": "2023-04-13T21:02:32.123696Z",
            "url": "https://files.pythonhosted.org/packages/b8/4a/fb4c9cf6ad1fd77d188a2151b70e6389224b2ce58f1f36f0f032dce721ea/ssh2_python3-1.11.1-cp311-cp311-manylinux_2_27_x86_64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "5af959eceb675489be5ccfeb06f8b96d9bed47c2a21917c8f863e65f06322285",
                "md5": "9e2dc92d3b54ce2833d9795f61acaf23",
                "sha256": "ed356a27a2df76179ac281f3ec9c77586e5d4d3c47cee7d04649edd566837e83"
            },
            "downloads": -1,
            "filename": "ssh2_python3-1.11.1-cp37-cp37m-manylinux_2_27_x86_64.whl",
            "has_sig": false,
            "md5_digest": "9e2dc92d3b54ce2833d9795f61acaf23",
            "packagetype": "bdist_wheel",
            "python_version": "cp37",
            "requires_python": ">=3.8",
            "size": 2865271,
            "upload_time": "2023-04-13T21:02:36",
            "upload_time_iso_8601": "2023-04-13T21:02:36.257941Z",
            "url": "https://files.pythonhosted.org/packages/5a/f9/59eceb675489be5ccfeb06f8b96d9bed47c2a21917c8f863e65f06322285/ssh2_python3-1.11.1-cp37-cp37m-manylinux_2_27_x86_64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ba15fb17f40c0cbaf191b5dfdaeaa3d4e696b127a5bd863e3241b82cd383d4df",
                "md5": "1bbc44367d46a1c35b8f7e215b88a075",
                "sha256": "f8e2e2701cfd10bb3455ae42bf4e205ab448529ef77c323d6fb8261b6902dfce"
            },
            "downloads": -1,
            "filename": "ssh2_python3-1.11.1-cp38-cp38-manylinux_2_27_x86_64.whl",
            "has_sig": false,
            "md5_digest": "1bbc44367d46a1c35b8f7e215b88a075",
            "packagetype": "bdist_wheel",
            "python_version": "cp38",
            "requires_python": ">=3.8",
            "size": 3007288,
            "upload_time": "2023-04-13T21:02:44",
            "upload_time_iso_8601": "2023-04-13T21:02:44.951929Z",
            "url": "https://files.pythonhosted.org/packages/ba/15/fb17f40c0cbaf191b5dfdaeaa3d4e696b127a5bd863e3241b82cd383d4df/ssh2_python3-1.11.1-cp38-cp38-manylinux_2_27_x86_64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b86814144f21f9abfb1a6c08618acd120e1dca8a487ed4f3b3c63f677b1f8028",
                "md5": "d529c9a89a2a05389c1ce5b5d62f316a",
                "sha256": "6e62c8eaf8af033cf1cab339d88ca3dca806efbc1e9ec3f4e856265ca3add067"
            },
            "downloads": -1,
            "filename": "ssh2_python3-1.11.1-cp39-cp39-manylinux_2_27_x86_64.whl",
            "has_sig": false,
            "md5_digest": "d529c9a89a2a05389c1ce5b5d62f316a",
            "packagetype": "bdist_wheel",
            "python_version": "cp39",
            "requires_python": ">=3.8",
            "size": 2913211,
            "upload_time": "2023-04-13T21:02:27",
            "upload_time_iso_8601": "2023-04-13T21:02:27.232236Z",
            "url": "https://files.pythonhosted.org/packages/b8/68/14144f21f9abfb1a6c08618acd120e1dca8a487ed4f3b3c63f677b1f8028/ssh2_python3-1.11.1-cp39-cp39-manylinux_2_27_x86_64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "6368abe21160e2b8deea39a0e9e7d16a50775b4b9382c0c3561d96bc0a94940b",
                "md5": "83a7a6ff5bc45096640d06624c2d8067",
                "sha256": "f2a2c5d39f486e83ec85bfa7e2bcc378c9709035dbc6cb664ad9bbddddefd084"
            },
            "downloads": -1,
            "filename": "ssh2-python3-1.11.1.tar.gz",
            "has_sig": false,
            "md5_digest": "83a7a6ff5bc45096640d06624c2d8067",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 613584,
            "upload_time": "2023-04-13T21:03:02",
            "upload_time_iso_8601": "2023-04-13T21:03:02.435466Z",
            "url": "https://files.pythonhosted.org/packages/63/68/abe21160e2b8deea39a0e9e7d16a50775b4b9382c0c3561d96bc0a94940b/ssh2-python3-1.11.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-04-13 21:03:02",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "pycopia",
    "github_project": "ssh2-python3",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "ssh2-python3"
}
        
Elapsed time: 0.07261s