{"id":19045276,"url":"https://github.com/julienc91/pystassh","last_synced_at":"2025-04-23T23:43:53.940Z","repository":{"id":10160452,"uuid":"64695233","full_name":"julienc91/pystassh","owner":"julienc91","description":"An easy to use libssh wrapper to execute commands on a remote server via SSH with Python.","archived":false,"fork":false,"pushed_at":"2022-05-17T18:41:17.000Z","size":101,"stargazers_count":1,"open_issues_count":0,"forks_count":4,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-18T08:39:35.212Z","etag":null,"topics":["libssh","python","ssh","ssh-client"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/julienc91.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-08-01T19:24:04.000Z","updated_at":"2024-08-12T19:24:07.000Z","dependencies_parsed_at":"2022-08-07T05:15:31.835Z","dependency_job_id":null,"html_url":"https://github.com/julienc91/pystassh","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/julienc91%2Fpystassh","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/julienc91%2Fpystassh/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/julienc91%2Fpystassh/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/julienc91%2Fpystassh/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/julienc91","download_url":"https://codeload.github.com/julienc91/pystassh/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250535057,"owners_count":21446503,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["libssh","python","ssh","ssh-client"],"created_at":"2024-11-08T22:49:37.381Z","updated_at":"2025-04-23T23:43:53.051Z","avatar_url":"https://github.com/julienc91.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"![Build](https://github.com/julienc91/pystassh/actions/workflows/main.yml/badge.svg)\n[![codecov](https://codecov.io/gh/julienc91/pystassh/branch/main/graph/badge.svg?token=yI3VdGc0rZ)](https://codecov.io/gh/julienc91/pystassh)\n[![Documentation](https://readthedocs.org/projects/pystassh/badge/)](http://pystassh.readthedocs.org/en/latest/)\n\npystassh\n========\n\nAn easy to use libssh wrapper to execute commands on a remote server via SSH with Python.\n\n* Author: Julien CHAUMONT (https://julienc.io)\n* Version: 1.2.2\n* Date: 2022-05-17\n* Licence: MIT\n* Url: https://julienc91.github.io/pystassh/\n\nInstallation\n------------\n\nJust use `pip` to install the package:\n\n    pip install pystassh\n    \n`pystassh` is working with python 3+ and pypy.\n\nRequirements\n------------\n\n`pystassh` is using libssh to work, you will have to install the library before using\n`pystassh`. Only version 0.7.3 was used during the development, but versions 0.5 and above should work fine as well with `pystassh`.\nVisit [libssh's official website](https://www.libssh.org/get-it/) for more information.\n`libffi-dev` is also required by the `cffi` module.\n\nOn Debian and Ubuntu:\n\n    apt-get install libssh-4 libffi-dev\n    \nOn Fedora:\n\n    dnf install libssh libffi-devel\n\nExamples\n--------\n\nEstablishing a connection:\n\n```python\n\u003e\u003e\u003e from pystassh import Session\n\u003e\u003e\u003e # With default private key\n\u003e\u003e\u003e session = Session('remote_host.org', username='user')\n\u003e\u003e\u003e # With username and password\n\u003e\u003e\u003e session = Session('remote_host.org', username='foo', password='bar')\n\u003e\u003e\u003e # With specific private key and a passphrase\n\u003e\u003e\u003e session = Session('remote_host.org', privkey_file='/home/user/.ssh/my_key', passphrase='baz')\n```\n\nRunning simple commands:\n\n```python\n\u003e\u003e\u003e from pystassh import Session\n\u003e\u003e\u003e with Session('remote_host.org', username='user') as ssh_session:\n...     res = ssh_session.execute('whoami')\n\u003e\u003e\u003e res.stdout\n'foo'\n```\n    \nHandling errors:\n\n```python\n\u003e\u003e\u003e from pystassh import Session\n\u003e\u003e\u003e with Session('remote_host.org', username='user') as ssh_session:\n...     res = ssh_session.execute('whoam')\n\u003e\u003e\u003e res.stderr\n'bash: whoam : command not found'\n```\n\nRunning multiple commands:\n\n```python\n\u003e\u003e\u003e from pystassh import Session\n\u003e\u003e\u003e with Session('remote_host.org', username='user') as ssh_session:\n...     ssh_session.execute('echo \"bar\" \u003e /tmp/foo')\n...     res = ssh_session.execute('cat /tmp/foo')\n\u003e\u003e\u003e res.stdout\n'bar'\n```\n    \nUsing a session without a `with` block:\n\n```python\n\u003e\u003e\u003e from pystassh import Session\n\u003e\u003e\u003e ssh_session = Session('remote_host.org', username='user')\n\u003e\u003e\u003e ssh_session.connect()\n\u003e\u003e\u003e res = ssh_session.execute('whoami')\n\u003e\u003e\u003e res.stdout\n'foo'\n\u003e\u003e\u003e ssh_session.disconnect()\n```\n\nUsing a shell:\n\n```python\n\u003e\u003e\u003e from pystassh import Session\n\u003e\u003e\u003e with Session('remote_host.org', username='user') as ssh_session:\n...     channel = ssh_session.channel\n...     with channel:\n...         channel.request_shell(request_pty=False)\n...         # non blocking read to flush the motd, if there is one\n...         channel.read_nonblocking(1024)\n...         channel.write(\"export foo=42;\\n\")\n...         channel.write(\"echo $foo;\\n\")\n...         channel.read(2048)\nb'42\\n'\n```\n\nDocumentation\n-------------\n\nThe complete documentation is available at: http://pystassh.readthedocs.org/en/latest/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjulienc91%2Fpystassh","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjulienc91%2Fpystassh","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjulienc91%2Fpystassh/lists"}