CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-clipboard

A cross-platform clipboard operation library for Python providing simple copy and paste functionality

Pending

Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

Overview
Eval results
Files

Clipboard

A cross-platform clipboard operation library for Python providing simple copy and paste functionality. Works seamlessly across Windows, Mac, and Linux operating systems with a minimal, easy-to-use API.

Package Information

  • Package Name: clipboard
  • Language: Python
  • Installation: pip install clipboard

Core Imports

import clipboard

Direct function imports:

from clipboard import copy, paste

Basic Usage

import clipboard

# Copy text to clipboard
clipboard.copy("Hello, World!")

# Paste text from clipboard
text = clipboard.paste()
print(text)  # Output: Hello, World!

# Direct import usage
from clipboard import copy, paste

copy("Sample clipboard content")
content = paste()
print(content)  # Output: Sample clipboard content

Capabilities

Copy to Clipboard

Writes text to the system clipboard, making it available for pasting in other applications.

def copy(text):
    """
    Copy text to the system clipboard.

    Args:
        text (str): The text to copy to the clipboard

    Returns:
        None
    """

Paste from Clipboard

Reads text from the system clipboard, returning the current clipboard contents as a string.

def paste():
    """
    Paste text from the system clipboard.

    Returns:
        str: The current text content of the clipboard
    """

Version Information

Access the package version information.

VERSION = "0.0.2"

Usage Examples

Basic Text Operations

import clipboard

# Copy multiline text
clipboard.copy("""Line 1
Line 2
Line 3""")

# Retrieve and process clipboard content
content = clipboard.paste()
lines = content.split('\n')
print(f"Clipboard contains {len(lines)} lines")

Integration with File Operations

import clipboard

# Copy file content to clipboard
with open('sample.txt', 'r') as file:
    clipboard.copy(file.read())

# Save clipboard content to file
with open('output.txt', 'w') as file:
    file.write(clipboard.paste())

Command Line Tool Integration

import clipboard
import sys

def cli_copy():
    """Copy stdin to clipboard"""
    text = sys.stdin.read()
    clipboard.copy(text)
    print("Text copied to clipboard")

def cli_paste():
    """Print clipboard content to stdout"""
    print(clipboard.paste(), end='')

# Usage in CLI scripts
if __name__ == "__main__":
    if len(sys.argv) > 1 and sys.argv[1] == "paste":
        cli_paste()
    else:
        cli_copy()

Error Handling

The clipboard functions rely on the underlying pyperclip library. Common errors may include:

  • Platform-specific clipboard access issues
  • Permission errors in some environments
  • Empty clipboard when no text content is available
import clipboard

try:
    content = clipboard.paste()
    if content:
        print(f"Clipboard content: {content}")
    else:
        print("Clipboard is empty or contains non-text data")
except Exception as e:
    print(f"Clipboard access error: {e}")

Platform Support

  • Windows: Full support
  • macOS: Full support
  • Linux: Full support (requires X11 or Wayland display server)

The library automatically detects the platform and uses the appropriate clipboard mechanism through its pyperclip dependency.

Install with Tessl CLI

npx tessl i tessl/pypi-clipboard
Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/clipboard@0.0.x
Publish Source
CLI
Badge
tessl/pypi-clipboard badge