PyClip
Cross-platform clipboard utilities supporting both binary and text data.
Some key features include:
- A cross-platform API (supports MacOS, Windows, Linux)
- Can handle arbitrary binary data
- On Windows, some additional clipboard formats
are supported
Installation
Requires python 3.7+
pip install pyclip
Usage
pyclip can be used in Python code
import pyclip
pyclip.copy("hello clipboard")
cb_data = pyclip.paste()
print(cb_data)
cb_text = pyclip.paste(text=True)
print(cb_text)
pyclip.clear()
assert not pyclip.paste()
Or a CLI
python -m pyclip paste
python -m pyclip copy < myfile.text
some-program | python -m pyclip copy
Installing via pip also provides the console script pyclip
:
pyclip copy < my_file.txt
This library implements functionality for several platforms and clipboard utilities.
If there is a platform or utility not currently listed, please request it by creating an issue.
Platform specific notes/issues
Windows
- On Windows, the
pywin32
package is installed as a requirement. - On Windows, additional clipboard formats are supported, including copying from a file
(like if you right-click copy from File Explorer)
MacOS
MacOS has support for multiple backends. By default, the pasteboard
package is used.
pbcopy
/pbpaste
can also be used as a backend, but does not support arbitrary binary data, which may lead to
data being lost on copy/paste. This backend may be removed in a future release.
Linux
Linux on X11 requires xclip
to work. Install with your package manager, e.g. sudo apt install xclip
Linux on Wayland requires wl-clipboard
to work. Install with your package manager, e.g. sudo apt install wl-clipboard
Acknowledgements
Big thanks to Howard Mao for donating the PyClip project name on PyPI to
this project.