Quick Overview
Pyperclip is a cross-platform Python module for copying and pasting text to and from the clipboard. It provides a simple interface to interact with the system clipboard, making it easy to programmatically manipulate clipboard content across different operating systems.
Pros
- Cross-platform compatibility (Windows, macOS, Linux)
- Simple and easy-to-use API
- No external dependencies for most platforms
- Lightweight and focused on a single task
Cons
- Limited to text-based clipboard operations
- Requires additional setup on some Linux distributions
- Not suitable for handling complex clipboard data types (e.g., images, files)
- May have occasional issues with certain clipboard managers or system configurations
Code Examples
- Copying text to clipboard:
import pyperclip
text_to_copy = "Hello, Pyperclip!"
pyperclip.copy(text_to_copy)
- Pasting text from clipboard:
import pyperclip
pasted_text = pyperclip.paste()
print(f"Clipboard content: {pasted_text}")
- Checking if pyperclip is working:
import pyperclip
if pyperclip.is_available():
print("Pyperclip is working correctly")
else:
print("Pyperclip is not available on this system")
Getting Started
To get started with Pyperclip, follow these steps:
-
Install Pyperclip using pip:
pip install pyperclip
-
Import the module in your Python script:
import pyperclip
-
Use the
copy()
andpaste()
functions to interact with the clipboard:pyperclip.copy("Text to be copied") pasted_text = pyperclip.paste()
That's it! You can now use Pyperclip to manipulate the clipboard in your Python projects.
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
Pyperclip is a cross-platform Python module for copy and paste clipboard functions. It works with Python 2 and 3.
Install on Windows: pip install pyperclip
Install on Linux/macOS: pip3 install pyperclip
Al Sweigart al@inventwithpython.com BSD License
Example Usage
>>> import pyperclip
>>> pyperclip.copy('The text to be copied to the clipboard.')
>>> pyperclip.paste()
'The text to be copied to the clipboard.'
Currently only handles plaintext.
On Windows, no additional modules are needed.
On Mac, this module makes use of the pbcopy and pbpaste commands, which should come with the os.
On Linux, this module makes use of the xclip or xsel commands, which should come with the os. Otherwise run "sudo apt-get install xclip" or "sudo apt-get install xsel" (Note: xsel does not always seem to work.)
Otherwise on Linux, you will need the qtpy or PyQT5 modules installed.
Support
If you find this project helpful and would like to support its development, consider donating to its creator on Patreon.
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot