Python pyperclip

What is Python pyperclip?

Python pyperclip is a Python Library that can manipulate the clipboard by enabling us to use the copy and paste functions.


Windows users do not have to download any dependencies, however Linux users need to first install the xclip or xsel library from the command prompt first.


sudo apt-get install xclip
pip install pyperclip


pip install pyperclip

Example Usage

pyperclip.copy() is used to copy text into the clipboard.
pyperclip.paste() will return the contents of the clipboard.

The below code will first copy the string “Hello World” to the clipboard. Once the pyperclip.paste() function is called, the same string will be printed out.

import pyperclip

pyperclip.copy('Hello world')

Keep in mind that this library functions like a regular clipboard. If you consecutively copy two values into the clipboard, the first will be over-written. A clipboard can only have one value at a time.

import pyperclip

pyperclip.copy("Hello World")
pyperclip.copy("Goodbye World")
x = pyperclip.paste()


Goodbye World

This marks the end of the Python pyperclip article. Any questions can be directed to the comments section below. Contributions or suggestions for CodersLegacy are more than welcome.

Use this link to head back to the Python Libraries page: link

Notify of
Inline Feedbacks
View all comments