🧠 clipin
clipin is a pure-Python clipboard utility that supports multiple clipboard formats — text, HTML, and images (where supported) — with minimal third-party dependencies.
✅ Features
- ✅ Cross-platform: Windows, macOS, Linux. However, headless systems (without a display), like bare bones containers, are not supported.
- 🧩 Supports MIME formats1 (where supported, see table below):
text/plaintext/htmlimage/png ; image/bmp ; image/tiff
- 🔄 Copy and paste multiple formats at once (where supported)
- 🐍 Pure Python with minimal dependencies (Python 3.9+)
🚀 Installation
pip install clipin
📦 Usage
Copy and paste simple text:
import clipin as cb
cb.copy("Hello, World!")
print(cb.paste()) # Outputs: Hello, World!
Copy an image file to the clipboard (open files in binary mode):
import clipin
filename = "image_file.tiff"
with open(filename, "rb") as f:
clipin.copy(f.read(), "image/tiff")
Copy both a filename and image data (not supported on all platforms):
import clipin
filename = "image_file.png"
with open(filename, "rb") as f:
clipin.copy({"image/png": f.read(), "text/plain": filename})
See the capabilities of the clipboard on the current platform:
import clipin
caps = clipin.capabilities()
print(caps)
# Example output on Windows:
# {'textplain': True, 'mime': True, 'multiple_formats_copy': True, 'multiple_formats_paste': True}
See table below.
📚 Interacting with MIME Types across Platforms
clipin uses MIME types (e.g., text/plain, image/png) to identify clipboard data formats. This approach enhances cross-platform compatibility, as different operating systems have their own clipboard format identifiers.
However, note that Windows doesn't use MIME-style clipboard identifiers, so clipin maps between MIME types and Windows clipboard formats internally. To do this, clipin uses the Pillow library for image format conversions when necessary.
Here is a non-exhaustive list of the mappings performed:
| Linux | Windows2 | macOS (Darwin)3 |
|---|---|---|
| text/plain | CF_TEXT = 1 | NSPasteboardTypeString = public.utf8-plain-text |
| text/html | CF_UNICODETEXT = 13 | NSPasteboardTypeHTML = public.html |
| image/bmp | CF_BITMAP = 2 4 | No equivalent5 |
| image/png | No equivalent6 | NSPasteboardTypePNG = public.png |
| image/tiff | CF_TIFF = 6 | NSPasteboardTypeTIFF = public.tiff |
| image/jpeg | No equivalent6 | NSPasteboardTypeJPEG = public.jpeg |
| image/gif | No equivalent6 | NSPasteboardTypeGIF = com.compuserve.gif |
Recommended Libraries
clipin is designed to be lightweight, with minimal dependencies. However, for enhanced functionality, especially regarding image format conversions on Windows, the following optional libraries are recommended:
- Windows: Pillow (for image format conversions)
- Linux: xclip (command line tool for clipboard access)
- macOS: pyobjc (for advanced clipboard interactions)
Without these libraries, clipin will still function for basic text copy and paste operations. The table below summarizes the capabilities based on the presence of these optional libraries.
| Condition | textplain: text/plain |
mime: text/html image/* |
multiple_formats_copy | multiple_formats_paste |
|---|---|---|---|---|
| Windows | ✅ | ✅ | ✅ | ✅ |
| MacOS with pyobjc | ✅ | ✅ | ✅ | ✅ |
| MacOS, no pyobjc | ✅ | ❌ | ❌ | ❌ |
| Linux with xclip | ✅ | ✅ | ❌ | ✅ |
| Linux, with tkinter, no xclip | ✅ | ❌ | ❌ | ❌ |
| Linux, no tkinter nor xclip | ❌ | ❌ | ❌ | ❌ |
| Linux, headless | ❌ | ❌ | ❌ | ❌ |
📄 License
This project is licensed under the MIT License. See the LICENSE file for details.
🙏 Acknowledgements and Credits
This project was inspired on pyperclip, a library that almost everyone used and loved, but unfortunately was stalled. Firstly the pull-requests where not being attended and support for the new wheel package format was not being added. The initial goal of this project was to fork pyperclip and continue its development, but the scope quickly expanded.
The development of this library followed 4 basic principles:
- Keep it simple to use. No object-oriented API, just simple functions to copy and paste.
- Maintain cross-platform compatibility.
- Support multiple clipboard formats.
- Minimal dependencies. If third-party libraries are needed, they should be optional and only for enhanced functionality.
This project development was aided by ChatGPT-4 and GitHub Copilot. The long discussions on possibilities and implementation options were very helpful to clarify the design decisions. Also the implementation of DIB handling on Windows and NSPasteboard interactions on macOS were greatly simplified by the suggestions of these AI tools. Special thanks to the open-source community for creating and maintaining tools like pyperclip, Pillow, xclip, and pyobjc, which made this project possible.
Finally thanks to my wife and kids for their patience while I was working on this project.
I hope you find clipin useful! 😊 Stay well and happy coding! 🚀
⚙️ Notes
-
Requires
xclipon Linux andpyobjcon macOS. If these are not present, clipin will need python-tk installed to support only text copy and paste. If you run in a headless system, like bare bones linux container images, clipin will not work, unless you set up a virtual display (e.g., using Xvfb). ↩ -
Windows represents many clipboard formats as integer constants. ↩
-
macOS exposes common pasteboard types via AppKit (NSPasteboard / NSPasteboard.PasteboardType). ↩
-
On Windows, CF_BITMAP represents a device-dependent bitmap format. clipin is not exploiting this format directly; instead, it focuses on CF_DIB / CF_DIBV5 for image clipboard operations. ↩
-
macOS does not have a native Windows-style bitmap format; prefer PNG or TIFF. ↩
-
On Windows, images are typically stored on the clipboard as CF_DIB / CF_DIBV5 (Device Independent Bitmaps) rather than as PNG or JPEG files. clipin will:
- Detect native Windows bitmap formats
- Convert them to PNG if the Pillow library is available
If Pillow is not installed, clipin exposes the raw bitmap data and documents how to enable PNG conversion.
To enable PNG conversion, install Pillow:
pip install pillow
See: https://docs.microsoft.com/en-us/windows/win32/dataxchg/standard-clipboard-formats ↩ ↩2 ↩3
Metadata
Release files for clipin 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| clipin-1.0.0.tar.gz | 23.7 kB | Without provenance | Details for clipin-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| clipin-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for clipin-1.0.0-py3-none-any.whl |
Total release size: 49.4 kB
Release files / clipin-1.0.0.tar.gz
| Download URL | clipin-1.0.0.tar.gz |
|---|---|
| Size | 23.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f8204cfeb58db86d58e19787b68a4fa1363d9bc1b0d30725408199673850e4f9
|
|
BLAKE2b-256 checksum How to use checksums |
6cf2a1ce66cb03c85c56814b188e4bde5feb2b76edb35ffce17cf99307d72c6c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.9.13
|
Release files / clipin-1.0.0-py3-none-any.whl
| Download URL | clipin-1.0.0-py3-none-any.whl |
|---|---|
| Size | 25.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a2e70bd146cca9fed6aca0dae865d83a9bc275c8c72fe727c665953a8b54fbc7
|
|
BLAKE2b-256 checksum How to use checksums |
7a588451ebd54d311aa74975d8a5ff9dd973c03175022cda49281e00f704850f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.9.13
|
Security for clipin 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.