Cross-platform clipboard copy and paste in one function call
pip install philiprehberger-clipboardCross-platform clipboard copy and paste in one function call.
pip install philiprehberger-clipboard
from philiprehberger_clipboard import copy, paste
copy("Hello, clipboard!")
text = paste()
print(text) # Hello, clipboard!
from philiprehberger_clipboard import copy, is_available
if is_available():
copy("hello")
else:
print("install xclip / xsel / wl-clipboard to enable copy")
Copy text from stdin:
echo "Hello" | python -m philiprehberger_clipboard copy
Paste clipboard contents to stdout:
python -m philiprehberger_clipboard paste
Or use the installed script:
echo "Hello" | clipboard copy
clipboard paste
| Function | Description |
|---|---|
copy(text: str) -> None | Copy a string to the system clipboard |
paste() -> str | Read a string from the system clipboard |
is_available() -> bool | Return True if a clipboard backend is detected on the current platform |
ClipboardError | Raised when clipboard tool is unavailable or operation fails |
| Platform | Copy | Paste |
|---|---|---|
| Windows | clip.exe | PowerShell Get-Clipboard |
| macOS | pbcopy | pbpaste |
| Linux (X11) | xclip or xsel | xclip or xsel |
| Linux (Wayland) | wl-copy | wl-paste |
pip install -e .
python -m pytest tests/ -v
If you find this project useful: