Skip to main content

Cross-platform clipboard copy and paste in one function call.

Project description

philiprehberger-clipboard

Tests PyPI version Last updated

Cross-platform clipboard copy and paste in one function call.

Installation

pip install philiprehberger-clipboard

Usage

from philiprehberger_clipboard import copy, paste

copy("Hello, clipboard!")
text = paste()
print(text)  # Hello, clipboard!

Clearing and checking

from philiprehberger_clipboard import clear, copy, equals

copy("secret")
equals("secret")  # True
equals("other")   # False

clear()
equals("")        # True

Detect availability

from philiprehberger_clipboard import copy, is_available

if is_available():
    copy("hello")
else:
    print("install xclip / xsel / wl-clipboard to enable copy")

CLI

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

API

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
clear() -> None Clear the clipboard (equivalent to copy(""))
equals(text: str) -> bool Return True if the clipboard contains exactly text; non-destructive, returns False when backend is unavailable
ClipboardError Raised when clipboard tool is unavailable or operation fails

Platform support

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

Development

pip install -e .
python -m pytest tests/ -v

Support

If you find this project useful:

Star the repo

🐛 Report issues

💡 Suggest features

❤️ Sponsor development

🌐 All Open Source Projects

💻 GitHub Profile

🔗 LinkedIn Profile

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

philiprehberger_clipboard-0.3.0.tar.gz (182.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

philiprehberger_clipboard-0.3.0-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

Details for the file philiprehberger_clipboard-0.3.0.tar.gz.

File metadata

File hashes

Hashes for philiprehberger_clipboard-0.3.0.tar.gz
Algorithm Hash digest
SHA256 3e3ac545f8ce7c9bd9143205a20b382cfb61a26025f4f875cbfc76259ad1256c
MD5 f7cf60297bd587bd31f0a4f745f690ac
BLAKE2b-256 d6df9714a19803b0bafc74a279af02fc2f7cf39962bb30ba6db241802ff4d62d

See more details on using hashes here.

File details

Details for the file philiprehberger_clipboard-0.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for philiprehberger_clipboard-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b323ede95238090025be6543b3e63524ed3e3f17c25454be844e3275bc00f360
MD5 24e606d161a10a6710db87bf44fc9f88
BLAKE2b-256 1a59e4133e9dcaebbce9ea859c44c12079dc5132b267dd7e9e739c9ea54ac132

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page