Skip to main content

clipboard-event

CI

clipboard-event provides clipboard text access and change callbacks for Python on Windows and macOS. 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.
  • 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", 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
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.1.0.tar.gz (12.2 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.1.0-py3-none-any.whl (9.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: clipboard_event-0.1.0.tar.gz
  • Upload date:
  • Size: 12.2 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.1.0.tar.gz
Algorithm Hash digest
SHA256 b4c6192bd6e895efdfefe937837792cc466f84b093b3b417fee4bdc157380de3
MD5 52df15e270c18ed929df60c71c746464
BLAKE2b-256 c8e89aad4e6b62177c5e27ec064659cac5b88df4591148bc426c300dcaeadcea

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for clipboard_event-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e802bd62e2ccc1a13fee5bc205e3a18b0b58a8753f05364f239debb75437b98f
MD5 d091538137ed84adf6036a8e23db0446
BLAKE2b-256 4a4b3092b395c3b2aa4d020034301d6db360d8f83fe6085cb9cdf16c5a3a386c

See more details on using hashes here.

Provenance

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

0.2.0

2 files

This release

0.1.0 This release

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