SSH Filesystem -- Async SSH/SFTP backend for fsspec
Project description
sshfs
sshfs is an implementation of fsspec for the SFTP protocol using asyncssh.
Features
- A complete implementation of the fsspec protocol through SFTP
- Supports features outside of the SFTP (e.g server side copy through SSH command execution)
- Quite fast (compared to alternatives like paramiko)
- Builtin Channel Management
- Async! (thanks to
asyncssh
)
Tutorial
Install the sshfs
from PyPI or the conda-forge, and import it;
from sshfs import SSHFileSystem
To connect with a password, you can simply specify username
/password
as keyword arguments and connect to the host of your choosing;
# Connect with a password
fs = SSHFileSystem(
'127.0.0.1',
username='sam',
password='fishing'
)
If you want to use a private key to authenticate, you can either pass a string pointing to the path of the key, or give a list of them to be tried:
# or with a private key
fs = SSHFileSystem(
'ssh.example.com',
client_keys=['/path/to/ssh/key']
)
All operations and their descriptions are specified here.
Here are a few example calls you can make, starting with info()
which allows you to retrieve the metadata about given path;
>>> details = fs.info('/tmp')
>>> print(f'{details["name"]!r} is a {details["type"]}!')
'/tmp/' is a directory!
>>>
>>> crontab = fs.info('/etc/crontab')
>>> print(f'{crontab["name"]!r} is a {crontab["type"]}!')
'/etc/crontab' is a file!
You can also create new files through either putting a local file with put_file
or opening a file in write mode;
>>> with fs.open('/tmp/message.dat', 'wb') as stream:
... stream.write(b'super secret messsage!')
...
And either download it through get_file
or simply read it on the fly with opening it;
>>> with fs.open('/tmp/message.dat') as stream:
... print(stream.read())
...
b'super secret messsage!'
There are also a lot of other basic filesystem operations, such as mkdir
, touch
and find
;
>>> fs.mkdir('/tmp/dir')
>>> fs.mkdir('/tmp/dir/eggs')
>>> fs.touch('/tmp/dir/spam')
>>> fs.touch('/tmp/dir/eggs/quux')
>>>
>>> for file in fs.find('/tmp/dir'):
... print(file)
...
/tmp/dir/eggs/quux
/tmp/dir/spam
If you want to list a directory but not it's children, you can use ls()
;
>>> [(detail['name'], detail['type']) for detail in fs.ls('/tmp/dir', detail=True)]
[('/tmp/dir/spam', 'file'), ('/tmp/dir/eggs', 'directory')]
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
Built Distribution
Hashes for sshfs-2021.11.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 86043a57e0cf01c3baff0e4e506109950c97cf34f136d2163e65946f1a2dc69a |
|
MD5 | 5fc0c8e0cbdf529d2eb1ed5554ce30e6 |
|
BLAKE2b-256 | c93c4187eff6e07bb51c585a20318c042af8c465ad1ed17bc85fa1f07b950032 |