Python library to natively send files to Trash (or Recycle bin) on all platforms.
raw JSON → 2.1.0 verified Tue May 12 auth: no python install: verified quickstart: verified
Send2Trash is a small Python package (version 2.1.0) that moves files and directories to the operating system's trash or recycle bin, rather than permanently deleting them. It provides native support for macOS (Cocoa calls), Windows (IFileOperation/SHFileOperation), and Linux/BSD (freedesktop.org trash specification or PyGObject/GIO fallback). It is actively maintained with a moderate release cadence, with the latest stable release in January 2026.
pip install send2trash Common errors
error ModuleNotFoundError: No module named 'send2trash' ↓
cause The send2trash package is not installed in the current Python environment.
fix
pip install send2trash
error FileNotFoundError: [Errno 2] No such file or directory: 'path/to/non_existent_file_or_dir' ↓
cause The file or directory specified in the path does not exist at the given location.
fix
Ensure the provided path points to an existing file or directory.
error OSError: [Errno 13] Permission denied: 'path/to/protected_file_or_dir' ↓
cause The current user lacks the necessary write permissions for the file/directory or its parent, or the file is locked by another process (especially on Windows).
fix
Check file permissions and ownership, ensure no other process is using the file, or run the script with appropriate elevated privileges if necessary.
error AttributeError: module 'send2trash' has no attribute 'trash' ↓
cause The main function to send items to the trash is named `send2trash`, not `trash`.
fix
Use
send2trash.send2trash(path) to move files or directories to the trash. Warnings
breaking Versions 2.0.0 and later removed Python 2.x compatibility. If upgrading from an older `send2trash` version that supported Python 2.x, ensure your environment is running Python 3.8 or newer. ↓
fix Upgrade your Python environment to 3.8+ or use an older `send2trash` version (e.g., `send2trash<2.0.0`) if Python 2.x compatibility is strictly required (not recommended for new development).
gotcha The `send2trash` function primarily expects string-based file paths. Passing `pathlib.Path` objects directly without converting them to strings (e.g., `str(path_object)`) can lead to `TypeError` or unexpected behavior in some versions or environments. ↓
fix Always ensure paths are converted to strings before passing them to `send2trash()`, for example, `send2trash(str(Path('/tmp/file.txt')))`.
gotcha On Freedesktop platforms (Linux, BSD), trashing files located on different devices than the user's home directory may raise `send2trash.TrashPermissionError` if a `.Trash` directory cannot be found or created. This requires explicit handling in your application. ↓
fix Catch `send2trash.TrashPermissionError` and handle files that cannot be moved to trash, e.g., by logging the error or attempting permanent deletion (with user consent and appropriate warnings).
gotcha When passing a list of files to `send2trash()`, an error encountered for any single file (e.g., `FileNotFoundError`, `TrashPermissionError`) will stop the processing of the *entire* list, preventing subsequent files from being trashed. ↓
fix To trash multiple files robustly, iterate through the list and call `send2trash()` for each file individually within a `try...except` block, handling errors on a per-file basis.
Install
pip install -U send2trash[nativeLib] Install compatibility verified last tested: 2026-05-12
python os / libc variant status wheel install import disk
3.10 alpine (musl) -U wheel - 0.02s 17.9M
3.10 alpine (musl) send2trash wheel - 0.02s 17.9M
3.10 alpine (musl) -U - - 0.02s 17.9M
3.10 alpine (musl) send2trash - - 0.02s 17.9M
3.10 slim (glibc) -U wheel 1.5s 0.01s 18M
3.10 slim (glibc) send2trash wheel 1.5s 0.01s 18M
3.10 slim (glibc) -U - - 0.01s 18M
3.10 slim (glibc) send2trash - - 0.01s 18M
3.11 alpine (musl) -U wheel - 0.03s 19.8M
3.11 alpine (musl) send2trash wheel - 0.03s 19.8M
3.11 alpine (musl) -U - - 0.03s 19.8M
3.11 alpine (musl) send2trash - - 0.03s 19.8M
3.11 slim (glibc) -U wheel 1.6s 0.02s 20M
3.11 slim (glibc) send2trash wheel 1.6s 0.02s 20M
3.11 slim (glibc) -U - - 0.02s 20M
3.11 slim (glibc) send2trash - - 0.02s 20M
3.12 alpine (musl) -U wheel - 0.02s 11.6M
3.12 alpine (musl) send2trash wheel - 0.02s 11.6M
3.12 alpine (musl) -U - - 0.02s 11.6M
3.12 alpine (musl) send2trash - - 0.02s 11.6M
3.12 slim (glibc) -U wheel 1.5s 0.02s 12M
3.12 slim (glibc) send2trash wheel 1.4s 0.02s 12M
3.12 slim (glibc) -U - - 0.02s 12M
3.12 slim (glibc) send2trash - - 0.02s 12M
3.13 alpine (musl) -U wheel - 0.02s 11.4M
3.13 alpine (musl) send2trash wheel - 0.02s 11.4M
3.13 alpine (musl) -U - - 0.02s 11.3M
3.13 alpine (musl) send2trash - - 0.02s 11.3M
3.13 slim (glibc) -U wheel 1.5s 0.02s 12M
3.13 slim (glibc) send2trash wheel 1.5s 0.02s 12M
3.13 slim (glibc) -U - - 0.02s 12M
3.13 slim (glibc) send2trash - - 0.02s 12M
3.9 alpine (musl) -U wheel - 0.02s 17.4M
3.9 alpine (musl) send2trash wheel - 0.02s 17.4M
3.9 alpine (musl) -U - - 0.02s 17.4M
3.9 alpine (musl) send2trash - - 0.02s 17.4M
3.9 slim (glibc) -U wheel 1.8s 0.02s 18M
3.9 slim (glibc) send2trash wheel 1.7s 0.02s 18M
3.9 slim (glibc) -U - - 0.02s 18M
3.9 slim (glibc) send2trash - - 0.02s 18M
Imports
- send2trash
from send2trash import send2trash
Quickstart verified last tested: 2026-04-24
import os
from pathlib import Path
from send2trash import send2trash
# Create a dummy file to trash
dummy_file = Path('temp_file_to_trash.txt')
dummy_file.write_text('This file will go to trash.')
print(f"Created file: {dummy_file.resolve()}")
# Send the file to trash
try:
send2trash(str(dummy_file)) # Ensure path is a string
print(f"'{dummy_file}' sent to trash successfully.")
except Exception as e:
print(f"Error trashing '{dummy_file}': {e}")
# Clean up (if file was not trashed due to an error, ensure it's removed)
if dummy_file.exists():
os.remove(dummy_file)
print(f"'{dummy_file}' removed forcefully (was not trashed).")