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!

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
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.2.0.tar.gz (5.4 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.2.0-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for philiprehberger_clipboard-0.2.0.tar.gz
Algorithm Hash digest
SHA256 abe886a765bfefd5310a565399beaa1956aa9a2b39199878bdfb239457e8b7c8
MD5 cdab54ef5068197acf837217b2d86874
BLAKE2b-256 673c4661f5adcfc06e9e32196235e9a9ecff317695f010fa15d89aea7f0e3fad

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for philiprehberger_clipboard-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d9888dcc89da344b8c968698296ec8aef6189d762bbce0a0d29b6ed86801c0dd
MD5 205a68bc3e5ef119f940ab72c7636f94
BLAKE2b-256 3d254baba54c90cb9d7a205697c5c30736e769a201cc5d302d7a0376e311e548

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