Registry / devops / send2trash

send2trash

JSON →
library2.1.0pypypi✓ verified 25d ago

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
INSTALL
IMPORT
SIG · SEND2TRASH
S
send2trash
devopspythonv2.1.0
Install
1.5s avg
Import
20ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v2.1.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.910 runs
installs and imports cleanly · install 0.0s · import 0.022s · 17.9MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 1.5s · import 0.018s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

send2trash
from send2trash import send2trash

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).")
Debug
Known issues
breakingVersions 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).
affects: >=2.0.0
gotchaThe `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')))`.
affects: All versions
gotchaOn 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).
affects: All versions
gotchaWhen 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.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'send2trash'
The send2trash package is not installed in the current Python environment.
fix
pip install send2trash
FileNotFoundError: [Errno 2] No such file or directory: 'path/to/non_existent_file_or_dir'
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.
OSError: [Errno 13] Permission denied: 'path/to/protected_file_or_dir'
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.
AttributeError: module 'send2trash' has no attribute 'trash'
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.
Upgrade
Version history
2.1.0latest on PyPI · released Jan 14, 2026
Audit
Dependencies
pythonrequiredRuntime environment
pywin32optionalOptional: Enhances native trash functionality on Windows Vista+.
pyobjcoptionalOptional: Enhances native trash functionality on macOS.
PyGObjectoptionalOptional: Enhances native trash functionality on Freedesktop systems.
GIOoptionalOptional: Enhances native trash functionality on Freedesktop systems (requires PyGObject).
Agent activity
21 hits · last 30 days
node
14
Resources