Python library to natively send files to Trash (or Recycle bin) on all platforms.
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.
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.
- 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.
- 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.
- 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.
Install
-
pip install send2trash -
pip install -U send2trash[nativeLib]
Imports
- send2trash
from send2trash import send2trash
Quickstart
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).")