pyperclip

1.11.0 · active · verified Sat Mar 28

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.

Warnings

Install

Imports

Quickstart

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.

import pyperclip

text_to_copy = 'Hello, world! This is copied by pyperclip.'
pyperclip.copy(text_to_copy)
print(f'Copied: "{text_to_copy}" to clipboard.')

pasted_text = pyperclip.paste()
print(f'Pasted: "{pasted_text}" from clipboard.')

# Example of waiting for new paste (requires manual paste action by user)
# print('Waiting for a new paste (max 5 seconds)...')
# try:
#     new_paste = pyperclip.waitForNewPaste(timeout=5)
#     print(f'New text pasted: "{new_paste}"')
# except pyperclip.PyperclipTimeoutException:
#     print('No new paste detected within 5 seconds.')

view raw JSON →