{"library":"sshfs","title":"SSH Filesystem for fsspec","type":"library","description":"sshfs is an implementation of fsspec, providing a unified Pythonic interface for interacting with SFTP servers over SSH. It leverages the asyncssh library for its underlying secure shell operations, offering a fast and asynchronous way to manage remote filesystems. The library is actively maintained, with its current version being 2025.11.0, and typically sees several releases per year to incorporate updates and improvements. [3, 10]","language":"python","status":"active","last_verified":"Thu May 21","install":{"commands":["pip install sshfs"],"cli":null},"imports":["from sshfs import SSHFileSystem","from fsspec import open"],"auth":{"required":false,"env_vars":[]},"links":{"homepage":null,"github":null,"docs":null,"changelog":null,"pypi":"https://pypi.org/project/sshfs/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null},"quickstart":{"code":"import os\nfrom sshfs import SSHFileSystem\nfrom fsspec import open\n\n# Configuration (use environment variables for sensitive data)\nSSH_HOST = os.environ.get('SSH_HOST', '127.0.0.1')\nSSH_USER = os.environ.get('SSH_USER', 'user')\nSSH_PASSWORD = os.environ.get('SSH_PASSWORD', 'password')\nSSH_KEY_PATH = os.environ.get('SSH_KEY_PATH', '~/.ssh/id_rsa')\n\n# --- Method 1: Using SSHFileSystem class directly ---\nprint(\"\\n--- Using SSHFileSystem directly ---\")\ntry:\n    # Connect with password\n    fs_pass = SSHFileSystem(SSH_HOST, username=SSH_USER, password=SSH_PASSWORD)\n    print(f\"Connected to {SSH_HOST} with password. Current dir: {fs_pass.pwd()}\")\n    # Example operation: list files\n    print(\"Files in remote home (password auth):\", fs_pass.ls('.'))\n    fs_pass.close()\n\n    # Connect with private key\n    fs_key = SSHFileSystem(SSH_HOST, username=SSH_USER, client_keys=[SSH_KEY_PATH])\n    print(f\"Connected to {SSH_HOST} with key. Current dir: {fs_key.pwd()}\")\n    print(\"Files in remote home (key auth):\", fs_key.ls('.'))\n\n    # Example: Write and read a file\n    remote_path = f'/tmp/test_sshfs_{os.getpid()}.txt'\n    with fs_key.open(remote_path, 'w') as f:\n        f.write('Hello from sshfs via key!')\n    with fs_key.open(remote_path, 'r') as f:\n        content = f.read()\n    print(f\"Read from {remote_path}: '{content}'\")\n    fs_key.rm(remote_path)\n    print(f\"Cleaned up {remote_path}\")\n    fs_key.close()\n\nexcept Exception as e:\n    print(f\"SSHFileSystem connection/operation failed: {e}\")\n\n# --- Method 2: Using fsspec.open with URL ---\nprint(\"\\n--- Using fsspec.open with URL ---\")\ntry:\n    # Using SSH URL with password\n    # Note: fsspec.open requires storage_options for auth. Password direct in URL is less secure.\n    # Better to pass via storage_options or rely on SSH agent/config.\n    with open(f'ssh://{SSH_USER}:{SSH_PASSWORD}@{SSH_HOST}/tmp/fsspec_test_{os.getpid()}.txt', 'w') as f:\n        f.write('Hello from fsspec.open!')\n    print(\"Wrote file via fsspec.open (password).\")\n\n    with open(f'ssh://{SSH_USER}@{SSH_HOST}/tmp/fsspec_test_{os.getpid()}.txt', 'r',\n              client_keys=[SSH_KEY_PATH]) as f:\n        content = f.read()\n    print(f\"Read via fsspec.open (key auth): '{content}'\")\n\n    # Clean up (requires SSHFileSystem directly or a complex fsspec glob pattern)\n    fs_cleanup = SSHFileSystem(SSH_HOST, username=SSH_USER, client_keys=[SSH_KEY_PATH])\n    fs_cleanup.rm(f'/tmp/fsspec_test_{os.getpid()}.txt')\n    print(\"Cleaned up fsspec.open test file.\")\n    fs_cleanup.close()\n\nexcept Exception as e:\n    print(f\"fsspec.open connection/operation failed: {e}\")\n\nprint(\"\\nQuickstart finished.\")","lang":"python","description":"This quickstart demonstrates how to connect to an SFTP server using `sshfs` with both password and SSH private key authentication. It shows direct usage of the `SSHFileSystem` class for programmatic file operations and integrates with `fsspec.open` for URL-based file access. It includes examples for listing, writing, and reading files, with cleanup operations. Remember to replace placeholder credentials with secure environment variables or a robust SSH configuration. [3, 10]","tag":null,"tag_description":null,"last_tested":"2026-04-25","results":[{"runtime":"python:3.10-alpine","exit_code":0},{"runtime":"python:3.10-slim","exit_code":0},{"runtime":"python:3.11-alpine","exit_code":0},{"runtime":"python:3.11-slim","exit_code":0},{"runtime":"python:3.12-alpine","exit_code":0},{"runtime":"python:3.12-slim","exit_code":0},{"runtime":"python:3.13-alpine","exit_code":0},{"runtime":"python:3.13-slim","exit_code":0},{"runtime":"python:3.9-alpine","exit_code":0},{"runtime":"python:3.9-slim","exit_code":0}]},"compatibility":{"tag":null,"tag_description":null,"last_tested":"2026-05-21","installed_version":"2025.11.0","pypi_latest":"2025.11.0","is_stale":false,"summary":{"python_range":"3.10–3.9","success_rate":100,"avg_install_s":2.9,"avg_import_s":0.87,"wheel_type":"wheel"},"results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"sshfs","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.65,"mem_mb":15.2,"disk_size":"39.4M"},{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"sshfs","exit_code":0,"wheel_type":null,"failure_reason":null,"import_side_effects":null,"install_time_s":null,"import_time_s":0.69,"mem_mb":15.1,"disk_size":"39.2M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"sshfs","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":3,"import_time_s":0.47,"mem_mb":15.2,"disk_size":"40M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"sshfs","exit_code":0,"wheel_type":null,"failure_reason":null,"import_side_effects":null,"install_time_s":null,"import_time_s":0.48,"mem_mb":15.1,"disk_size":"40M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"sshfs","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.98,"mem_mb":17.1,"disk_size":"43.0M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"sshfs","exit_code":0,"wheel_type":null,"failure_reason":null,"import_side_effects":null,"install_time_s":null,"import_time_s":1.16,"mem_mb":17.1,"disk_size":"42.8M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"sshfs","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":2.9,"import_time_s":0.9,"mem_mb":17.1,"disk_size":"43M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"sshfs","exit_code":0,"wheel_type":null,"failure_reason":null,"import_side_effects":null,"install_time_s":null,"import_time_s":0.91,"mem_mb":17.1,"disk_size":"43M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"sshfs","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":1,"mem_mb":16.9,"disk_size":"34.5M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"sshfs","exit_code":0,"wheel_type":null,"failure_reason":null,"import_side_effects":null,"install_time_s":null,"import_time_s":1.27,"mem_mb":16.9,"disk_size":"34.3M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"sshfs","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":2.5,"import_time_s":1.01,"mem_mb":16.9,"disk_size":"35M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"sshfs","exit_code":0,"wheel_type":null,"failure_reason":null,"import_side_effects":null,"install_time_s":null,"import_time_s":1.09,"mem_mb":16.9,"disk_size":"35M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"sshfs","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.98,"mem_mb":17.3,"disk_size":"34.2M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"sshfs","exit_code":0,"wheel_type":null,"failure_reason":null,"import_side_effects":null,"install_time_s":null,"import_time_s":1.13,"mem_mb":17.2,"disk_size":"33.9M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"sshfs","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":2.6,"import_time_s":0.97,"mem_mb":17.3,"disk_size":"35M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"sshfs","exit_code":0,"wheel_type":null,"failure_reason":null,"import_side_effects":null,"install_time_s":null,"import_time_s":1.22,"mem_mb":17.3,"disk_size":"34M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"sshfs","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.59,"mem_mb":15,"disk_size":"39.6M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"sshfs","exit_code":0,"wheel_type":null,"failure_reason":null,"import_side_effects":null,"install_time_s":null,"import_time_s":0.64,"mem_mb":14.9,"disk_size":"39.4M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"sshfs","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":3.5,"import_time_s":0.57,"mem_mb":15,"disk_size":"40M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"sshfs","exit_code":0,"wheel_type":null,"failure_reason":null,"import_side_effects":null,"install_time_s":null,"import_time_s":0.59,"mem_mb":15,"disk_size":"40M"}]}}