Python library: pyperclip

Python module for copy and paste clipboard functions.

30 Nov 2022

Library resources
PyPI https://pypi.org/project/pyperclip/
Github https://github.com/asweigart/pyperclip
Documentation ---

Created by Al Sweigart, author of "Automate the boring stuff with Python" Automate the Boring Stuff with Python, by Al Sweigart.md

Getting Started

pip3 install pyperclip

Usage

to use data from clipboard in Python script:

import pyperclip

pyperclip.paste()

to copy back to clipboard:

pyperclip.copy('The text to be copied to the clipboard.')

Resources

other modules:

Alternative without library

def copy_to_clipboard(text: str):
    import subprocess
    process = subprocess.Popen("pbcopy", universal_newlines=True, stdin=subprocess.PIPE)
    process.communicate(text)
    return process.returncode == 0

links

social