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.

Installation

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.

Linux

sudo apt-get install xclip
pip install pyperclip

Windows

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')
print(pyperclip.paste())

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()
print(x)

Output

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

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments