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.2.tar.gz (15.3 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.2-py3-none-any.whl (11.2 kB view details)

Uploaded Python 3

File details

Details for the file clipboard_event-0.2.2.tar.gz.

File metadata

  • Download URL: clipboard_event-0.2.2.tar.gz
  • Upload date:
  • Size: 15.3 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.2.tar.gz
Algorithm Hash digest
SHA256 980f850d324f4ca3986dad3d8360b6f6b5cf5c1b915b27d089e459553d0dea32
MD5 b7fee63b36f9c3bece79d67fd3ca7c84
BLAKE2b-256 271100526abbf224f8aaa5875bdaf0008b26abe6a7457b94727ad756e32117a7

See more details on using hashes here.

Provenance

The following attestation bundles were made for clipboard_event-0.2.2.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.2-py3-none-any.whl.

File metadata

  • Download URL: clipboard_event-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 11.2 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 96d4e9db3b566e109a9e338ac262bd4d8ec36843301cbdd3fd011f6beabf35fb
MD5 f27d11a945c6621ef42844a78756a636
BLAKE2b-256 240838321df4c15fbcac64136b32a658a8c45b21b17d85988c5f9f5ddd1bd192

See more details on using hashes here.

Provenance

The following attestation bundles were made for clipboard_event-0.2.2-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

This release

0.2.2 This release

2 files

0.2.1

2 files

0.2.0

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