Pyperclip is a cross-platform Python module (current version 1.11.0) for copying and pasting plain text to and from the clipboard. It provides a simple API (`copy()` and `paste()`) and is actively maintained with regular updates, enabling clipboard interaction across Windows, macOS, and Linux.
pip install pyperclipVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates basic text copying and pasting using `pyperclip.copy()` and `pyperclip.paste()`. It also includes commented-out code for `pyperclip.waitForNewPaste()` to illustrate waiting for new clipboard content, handling a timeout gracefully.
Install one of the required system utilities or Python modules. E.g., `sudo apt-get install xclip` or `pip install PyQt5`.
Use libraries like `pyperclipimg` (a separate module) or Pillow's `ImageGrab` for image-specific clipboard operations.
Be aware of the execution environment. For client-side clipboard interaction in web apps, client-side JavaScript solutions are typically required. For Docker/WSL, ensure necessary X server/display settings are configured if GUI clipboard access is truly needed.
Ensure you are running Python 3.x. If Python 2 compatibility is strictly required, pin to an older `pyperclip` version (e.g., <1.9.0) at your own risk, or migrate your application to Python 3.
Use string methods like `.strip()` or `.replace('\n', '')` to clean the text before copying: `pyperclip.copy(my_text.strip())`.Call `pyperclip.paste()` without any arguments: `pasted_content = pyperclip.paste()`.
Install `xclip` or `xsel` using your package manager (e.g., `sudo apt-get install xclip` or `sudo apt-get install xsel` on Debian/Ubuntu-based systems).
Install the library using pip: `pip install pyperclip`
Add `import pyperclip` at the beginning of your Python script or before using any `pyperclip` functions.