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.1.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.1-py3-none-any.whl (10.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: clipboard_event-0.2.1.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.1.tar.gz
Algorithm Hash digest
SHA256 910230cca3c94ad727d13175c242af802a55e11dd8fe91c6771e5f61ff9aba56
MD5 86dc755a95ea1e37fe1dbddfb3330243
BLAKE2b-256 7f52c96a40be5d941835991e988ffa66bbcaca77a3c50aa1410385c3bb2566a5

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: clipboard_event-0.2.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 cb0a6b9040a56ffb35defbc3514d56438b0175beb7d610379700e51aa0ceca2c
MD5 f97fce31da4b24050b6a2a91fc3f9105
BLAKE2b-256 f69dd09cf486ba4028d88a09ad0c1c1a2c7924d103683dcb9214905d8fbf0bdf

See more details on using hashes here.

Provenance

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

This release

0.2.1 This release

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