clipboard-event
clipboard-event provides clipboard text access and change callbacks for Python on Windows, macOS, and Linux. It uses native change notifications where available and has no runtime dependencies.
- Windows: reads and writes Unicode text through Win32 and listens for
WM_CLIPBOARDUPDATEon a message-only window. - macOS: reads and writes through
pbpasteandpbcopy, then observesNSPasteboard.changeCountwithout polling clipboard content continuously. - Linux / Wayland: reads and writes through
wl-pasteandwl-copy, then useswl-paste --watchfor event-driven change detection with zero idle CPU. - Linux / X11: reads and writes through
xclip(fallbackxsel) and polls with content hashing, since X11 has no clipboard-change notification. - If native monitoring cannot start on a supported platform, the library falls back to polling. Other platforms fail explicitly.
Installation
Once the package is published on PyPI:
pip install clipboard-event
The project requires Python 3.10 or newer.
Quick start
The module facade creates its default clipboard instance only when first used:
import clipboard_event
print(clipboard_event.read())
clipboard_event.write("Hello from Python")
subscription = clipboard_event.on_change(
lambda value: print(f"Clipboard changed: {value!r}"),
emit_initial=True,
)
# Later:
subscription.cancel()
clipboard_event.close()
Explicit instances
Use Clipboard when you need an independent lifecycle:
from clipboard_event import Clipboard, Subscription
clipboard = Clipboard()
def changed(value: str | None) -> None:
print(value)
subscription: Subscription = clipboard.on_change(changed)
clipboard.write("This write also triggers the callback")
subscription.cancel()
clipboard.close()
Subscription.cancel() and Clipboard.close() are idempotent. Closing a Clipboard cancels its subscriptions and releases monitor threads and native watcher resources. read() and write() remain usable after close, and a later on_change() call starts monitoring again.
Callbacks run sequentially on one Python dispatcher thread, never on a native watcher thread. One callback's exception does not stop other subscriptions. Rapid changes may coalesce, so a callback can receive only the latest value. A callback receives str for text or None when no text is available. Writes made through the library are observed like external changes.
For diagnostics, inspect the selected backend:
print(clipboard.backend_name) # "win32", "macos", "wayland", "x11", or "polling"
Support
| Platform | Python | Clipboard I/O | Change monitoring |
|---|---|---|---|
| Windows | 3.10–3.14 | Win32 Unicode text | WM_CLIPBOARDUPDATE, with polling fallback |
| macOS | 3.10–3.14 | pbcopy / pbpaste |
NSPasteboard.changeCount, with polling fallback |
| Linux / Wayland | 3.10–3.14 | wl-copy / wl-paste |
wl-paste --watch, with polling fallback |
| Linux / X11 | 3.10–3.14 | xclip (fallback xsel) |
Content-hash polling |
| Other platforms | — | Unsupported | Unsupported |
The package is pure Python. Its wheel is universal because platform integration happens at runtime through the standard library and system tools; no compiled extension is included.
Development
Create and activate a virtual environment, then install the project in editable mode:
python -m pip install -e .
python -m unittest discover -s tests -t .
python tests/native_smoke.py
Build and inspect distribution artifacts with:
python -m pip install build twine
python -m build
python -m twine check dist/*
License
MIT © 2026 Jordi Murgó.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file clipboard_event-0.2.0.tar.gz.
File metadata
- Download URL: clipboard_event-0.2.0.tar.gz
- Upload date:
- Size: 13.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e701df58ed81f712e7248de8daa191650f0dee5b5af1d2d289d97d2886b8dd7f
|
|
| MD5 |
d9d60c3ff02c0d2e087686028c38d9e5
|
|
| BLAKE2b-256 |
96a9d4f966255bc88121f3f6d92f31d9998fa66ac73b816563752185a30822e1
|
Provenance
The following attestation bundles were made for clipboard_event-0.2.0.tar.gz:
Publisher:
publish.yml on jordi-murgo/clipboard-event
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
clipboard_event-0.2.0.tar.gz -
Subject digest:
e701df58ed81f712e7248de8daa191650f0dee5b5af1d2d289d97d2886b8dd7f - Sigstore transparency entry: 2545629221
- Sigstore integration time:
-
Permalink:
jordi-murgo/clipboard-event@3f9e525dd27e28477875d7e9acceea78aa9473cc -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/jordi-murgo
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@3f9e525dd27e28477875d7e9acceea78aa9473cc -
Trigger Event:
release
-
Statement type:
File details
Details for the file clipboard_event-0.2.0-py3-none-any.whl.
File metadata
- Download URL: clipboard_event-0.2.0-py3-none-any.whl
- Upload date:
- Size: 10.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
abdcc169003569b4f07d30d02496ba57db416d118881e3eaa9893f9d2832ee06
|
|
| MD5 |
b885a71dddde512c328e34f91333343f
|
|
| BLAKE2b-256 |
7743844e3194b39bda15bb4f38ffd5dda1550de9232bfdf04a36e0a172af30b5
|
Provenance
The following attestation bundles were made for clipboard_event-0.2.0-py3-none-any.whl:
Publisher:
publish.yml on jordi-murgo/clipboard-event
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
clipboard_event-0.2.0-py3-none-any.whl -
Subject digest:
abdcc169003569b4f07d30d02496ba57db416d118881e3eaa9893f9d2832ee06 - Sigstore transparency entry: 2545629265
- Sigstore integration time:
-
Permalink:
jordi-murgo/clipboard-event@3f9e525dd27e28477875d7e9acceea78aa9473cc -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/jordi-murgo
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@3f9e525dd27e28477875d7e9acceea78aa9473cc -
Trigger Event:
release
-
Statement type: