Python library to natively send files to Trash (or Recycle bin) on all platforms.

2.1.0 · active · verified Sat Mar 28

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

Install

Imports

Quickstart

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.

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).")

view raw JSON →