Skip to main content

Clipboard utilities for use with Python.

Project description

PyPI Read the Docs Tests

PyPI - Python Version PyPI - License

pre-commit Code style: black

Description

Package for accessing the clipboard with Python.

Installation

pip install clip-util

Features

Windows Only

Allows you to set text, RTF, and HTML to the clipboard on Windows. Any other format can also be specified using the format type integer, specified by Windows.

Supported Clipboard Formats

  • Text
  • HTML
  • RTF

Usage

Clipboard

Will open and close every time the values are set, or retrieved. It's better to use a context manager.

from clipboard import Clipboard


clipboard = Clipboard()

# Set Clipboard
clipboard["text"] = "Hello World!"
# OR
clipboard.set_clipboard("Hello World!")

# Get Clipboard
text = clipboard["text"]
# OR
text = clipboard.get_clipboard("text")

# Supports HTML
clipboard["html"] = "<h1>Hello World</h1>"

Context Manager

from clipboard import Clipboard


with Clipboard() as clipboard:

    # Set Clipboard
    clipboard["text"] = "Hello World!"
    # OR
    clipboard.set_clipboard("Hello World!")

    # Get Clipboard
    text = clipboard["text"]
    # OR
    text = clipboard.get_clipboard("text")

    # HTML
    clipboard["html"] = "<h1>Hello World</h1>"

Clipboard Formats

You can use clip-util to access the clipboard formats directly.

ClipboardFormat: Enum for clipboard formats.

ClipboardFormat.CF_HTML: Represents HTML format.

ClipboardFormat.CF_RTF: Represents RTF format.

from clipboard import Clipboard
from clipboard import ClipboardFormat
from clipboard import get_format_name


with Clipboard() as clipboard:

    # Get All Available Formats
    format_ids: list[int] = clipboard.available_formats()

    # Get Specific Format by ID
    # Use parentheses to access the format by ID
    formats: list[ClipboardFormat] = []
    format_id: int
    for format_id in format_ids:
        if format_id in ClipboardFormat:
            format_: ClipboardFormat = ClipboardFormat(format_id)
            formats.append(format_)
        else:
            # Format is not supported directly by this library
            pass

    # Get Specified Format by Name (directly)
    format_names: list[str] = []
    format_id: int
    for format_id in format_ids:
        name: str = get_format_name(format_id)
        format_names.append(name)

    # Get Specified Format by Name (using enum)
    # Use bracket notation to access the format
    #
    # Note: this method is not as robust as using `get_format_name`
    formats: list[ClipboardFormat] = []
    format_names: list[str] = []
    format_name: str
    for format_name in [f.name for f in formats]:
        if format_name in ClipboardFormat:
            format_: ClipboardFormat = ClipboardFormat[format_name]
            name: str = format_.name
            formats.append(format_)
            format_names.append(name)
        else:
            # Format is not supported directly by this library
            pass

Get All Supported Formats

You can even get the content of all available formats currently in the clipboard.

from clipboard import get_available_formats
from clipboard import get_format_name
from clipboard import get_clipboard


available: list[int] = get_available_formats()
print(f"{available=}")

for format_id in available:
    name: str = get_format_name(format_id)
    content: str = get_clipboard(format_id)
    print(f"{format_id=}", f"{name=}, {content=}")

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

clip_util-0.1.28.tar.gz (11.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

clip_util-0.1.28-py3-none-any.whl (13.1 kB view details)

Uploaded Python 3

File details

Details for the file clip_util-0.1.28.tar.gz.

File metadata

  • Download URL: clip_util-0.1.28.tar.gz
  • Upload date:
  • Size: 11.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.2

File hashes

Hashes for clip_util-0.1.28.tar.gz
Algorithm Hash digest
SHA256 008caedb3efd58806b2a7192abe1d18182ae817186b7b108f6194f65f3150ed0
MD5 a4081f1fdcf80342adc2d9cf352aa4ec
BLAKE2b-256 558bc25e99cf8be56a36a225f8ecb9311050eeabce9bc979d5bbea8824e92208

See more details on using hashes here.

File details

Details for the file clip_util-0.1.28-py3-none-any.whl.

File metadata

  • Download URL: clip_util-0.1.28-py3-none-any.whl
  • Upload date:
  • Size: 13.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.2

File hashes

Hashes for clip_util-0.1.28-py3-none-any.whl
Algorithm Hash digest
SHA256 cd1609debecbf6c2576e45b29aa3aff22242ee0fb122ef313d45cf62c05d910b
MD5 62ab55e5081ae8e779b313a56bca7062
BLAKE2b-256 0be762f6a6c55f09aeddee8d0ad45ed73086193e31ff93e6341181ececefd208

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page