Skip to main content

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. This will install fsspec and register sshfs for ssh:// urls, so you can open files using:

from fsspec import open

with open('ssh://[user@]host[:port]/path/to/file', "w") as file:
    file.write("Hello World!")

with open('ssh://[user@]host[:port]/path/to/file', "r") as file:
    print(file.read())

For more operations, you can use the SSHFileSystem class directly:

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']
)

Note: you can also pass client_keys as an argument to fsspec.open.

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 message!')
...

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 message!'

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


Download files

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

Source Distribution

sshfs-2025.11.0.tar.gz (24.8 kB view details)

Uploaded Source

Built Distribution

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

sshfs-2025.11.0-py3-none-any.whl (16.4 kB view details)

Uploaded Python 3

File details

Details for the file sshfs-2025.11.0.tar.gz.

File metadata

  • Download URL: sshfs-2025.11.0.tar.gz
  • Upload date:
  • Size: 24.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for sshfs-2025.11.0.tar.gz
Algorithm Hash digest
SHA256 f5bad75e16229112a8a13d6d4a2faeffd72e4141907d8d999a978bef599e4847
MD5 3df11a59c2b6f493c0035a5c43636915
BLAKE2b-256 7ca44d445a859a58d3d2ee1e52b0376164a87de63d42304287b7ccd5f6b54d5b

See more details on using hashes here.

File details

Details for the file sshfs-2025.11.0-py3-none-any.whl.

File metadata

  • Download URL: sshfs-2025.11.0-py3-none-any.whl
  • Upload date:
  • Size: 16.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for sshfs-2025.11.0-py3-none-any.whl
Algorithm Hash digest
SHA256 90a3a2e815d28a0e8475f10fe8ef0127a507b60f77df17c3473c1a28e78c7f4b
MD5 27f7c6002bc63e5573d4bb201ec36c21
BLAKE2b-256 cca729935d7b8572ba378514864bd3d99dfb01518a5c20366b794b6cdb283356

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