Upstream slow to to respond to PRs. Also consider https://github.com/asweigart/pyperclip where there is a PR for Wayland support (note as of 2021-08-13 it also has a backlog of PRs, also see https://github.com/clach04/pyperclip/tree/html_linux_win32). Differences to upstream:
- Doesn't crash when clipboard empty or contains non-text data (like bitmaps)
- Html formatted intent for both copy and paste (windows only)
Xerox is a copy + paste module for python. It's aim is simple: to be as incredibly simple as possible.
Supported platforms are currently OS X, X11 (Linux, BSD, etc.), and Windows.
If you can make it simpler, please fork.
Usage is as follows:
xerox.copy(u'some string')
And to paste:
>>> xerox.paste() u'some string'
On Linux you can optionally also copy into the X selection clipboard for middle-click-paste capability:
xerox.copy(u'Some string', xsel=True)
And you can choose to paste from the X selection rather than the system clipboard:
xerox.paste(xsel=True)
On Windows you can optionally copy into the clipboard in html mode:
xerox.copy(u'<p>Writing to the clipboard is <strong>easy</strong> with this code.</p>', html=True)
This will also paste the html into the text clipboard for applications that do not support html mode. HTML paste from the clipboard is not implemented. Unlike xsel support, there is no silent failure if html mode is requested with a backend that does not support it.
And, that's it.
To copy:
$ xerox some string
or:
$ echo some string | xerox
To paste:
>>> xerox some string
To install Xerox, simply:
$ pip install xerox
Note: If you are installing xerox on Windows, you will also need to install the pywin32 module. FIXME see https://github.com/mu-editor/mu/blob/0203b6e850c16cbb95442026193f1f5bef33a3d4/setup.py#L77 for how to handle this in setup.py.
Note: On X11 systems, Xerox requires Xclip, which can be found through your system package manager (e.g. apt-get install xclip) or at https://github.com/astrand/xclip
- Android support (see https://github.com/clach04/toys4droids/blob/master/remote_clipboard.py)
- RTF copy support (for Windows and xclip), see html support
- CF_CLIPBOARD_VIEWER_IGNORE http://www.clipboardextender.com/developing-clipboard-aware-programs-for-windows/ignoring-clipboard-updates-with-the-cf_clipboard_viewer_ignore-clipboard-format
- See if https://github.com/jaraco/jaraco.windows/blob/main/jaraco/windows/clipboard.py https://github.com/enthought/pywin32-ctypes could be used
- Jython / Have support https://github.com/fracpete/jclipboardhelper
MIT License.
(c) 2016 Kenneth Reitz.