Skip to main content

clipboard-event

CI

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_CLIPBOARDUPDATE on a message-only window.
  • macOS: reads and writes through pbpaste and pbcopy, then observes NSPasteboard.changeCount without polling clipboard content continuously.
  • Linux / Wayland: reads and writes through wl-paste and wl-copy, then uses wl-paste --watch for event-driven change detection with zero idle CPU.
  • Linux / X11: reads and writes through xclip (fallback xsel) 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

clipboard_event-0.2.0.tar.gz (13.4 kB view details)

Uploaded Source

Built Distribution

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

clipboard_event-0.2.0-py3-none-any.whl (10.6 kB view details)

Uploaded Python 3

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

Hashes for clipboard_event-0.2.0.tar.gz
Algorithm Hash digest
SHA256 e701df58ed81f712e7248de8daa191650f0dee5b5af1d2d289d97d2886b8dd7f
MD5 d9d60c3ff02c0d2e087686028c38d9e5
BLAKE2b-256 96a9d4f966255bc88121f3f6d92f31d9998fa66ac73b816563752185a30822e1

See more details on using hashes here.

Provenance

The following attestation bundles were made for clipboard_event-0.2.0.tar.gz:

Publisher: publish.yml on jordi-murgo/clipboard-event

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for clipboard_event-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 abdcc169003569b4f07d30d02496ba57db416d118881e3eaa9893f9d2832ee06
MD5 b885a71dddde512c328e34f91333343f
BLAKE2b-256 7743844e3194b39bda15bb4f38ffd5dda1550de9232bfdf04a36e0a172af30b5

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

0.2.2

2 files

0.2.1

2 files

This release

0.2.0 This release

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page