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=}")
Metadata
Release files for clip-util 0.1.30
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| clip_util-0.1.30.tar.gz | 10.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| clip_util-0.1.30-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 23.9 kB
Release files / clip_util-0.1.30.tar.gz
| Download URL | clip_util-0.1.30.tar.gz |
|---|---|
| Size | 10.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7936c31ed0de175e294d0e9121564c813650e46ab5b6e62f809915063445611f
|
|
BLAKE2b-256 checksum How to use checksums |
56a9a1059696a91ac08adf6c2126120cb43169551c8aee5f362f8477fd02dd25
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.10
|
Release files / clip_util-0.1.30-py3-none-any.whl
| Download URL | clip_util-0.1.30-py3-none-any.whl |
|---|---|
| Size | 13.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e8a668c118d084554bfbdf37c49bf3e45d4c09017f3d0f6ee53ba45c7f1fd4e9
|
|
BLAKE2b-256 checksum How to use checksums |
e3723d351e1de82d6cdb5d942d4d6c2e6c46682faa41bcd6cd0170ecae7be93e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.10
|