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 send2trashVerified import paths — ran on the pinned version, not inferred.
This quickstart creates a temporary file, sends it to the OS trash/recycle bin using `send2trash()`, and includes basic error handling. Note the explicit conversion of `pathlib.Path` objects to strings.
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).
Always ensure paths are converted to strings before passing them to `send2trash()`, for example, `send2trash(str(Path('/tmp/file.txt')))`.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).
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.
pip install send2trash
Ensure the provided path points to an existing file or directory.
Check file permissions and ownership, ensure no other process is using the file, or run the script with appropriate elevated privileges if necessary.
Use `send2trash.send2trash(path)` to move files or directories to the trash.