A robust, dependency-free way to use the system clipboard in Python.
Project description
copykitten
A robust, dependency-free way to use the system clipboard in Python.
Installation
copykitten
supports Python >= 3.8.
You can install copykitten
from PyPI using pip
or any other Python package manager.
pip install copykitten
Usage
Text
To copy or paste text content, use copykitten.copy
and copykitten.paste
functions.
import copykitten
copykitten.copy("The kitten says meow")
import copykitten
text = copykitten.paste()
Image
To copy or paste images, use copykitten.copy_image
and copykitten.paste_image
functions.
Working with images is a bit complex, so read further.
import copykitten
from PIL import Image
image = Image.open("image.png")
pixels = image.tobytes()
copykitten.copy_image(pixels, image.width, image.height)
import copykitten
from PIL import Image
pixels, width, height = copykitten.paste_image()
image = Image.frombytes(mode="RGBA", size=(width, height), data=pixels)
image.save("image.png")
To copy an image to the clipboard, you have to pass three arguments - pixel data, width, and height.
Pixel data must be a bytes
object containing the raw RGBA value for each pixel. You can easily get it using an imaging
library like Pillow.
If your image is not of RGBA type (like a typical JPEG, which is RGB), you first have to convert it to RGBA, otherwise
copy_image
will raise an exception.
When pasting an image from the clipboard you will receive a 3-tuple of (pixels, width, height). Pixels here are the same
RGBA bytes
object. Please note that it is not guaranteed that any image copied to the clipboard by another program
will be successfully pasted with copykitten
.
You can read more about the data format and the
implications of working with images in
the arboard
documentation.
Clear
To clear the clipboard, use copykitten.clear
function.
import copykitten
copykitten.clear()
Rationale
At the time of writing, there are very few Python packages that handle the clipboard. Most of them are simply no longer maintained (including the most popular solution around the web, pyperclip).
They all depend on external command-line tools like xclip/pbcopy or libraries like PyQt/GTK. You have to make sure these dependencies are installed on the target machine, otherwise they won’t work.
There are some solutions using the Tkinter library, which comes with the standard Python suite. However, these solutions are fragile and may leave your app unresponsive.
Copykitten is a lightweight wrapper around the Rust arboard library. It comes with pre-built wheels for Linux (x64, ARM64), macOS (x64, ARM64), and Windows (x64), so you don't have to worry about anything.
What's in a name?
You can’t even imagine, how many Python packages devoted to the clipboard management there are on PyPI! Most of them are abandoned for a decade, and all the neat obvious names (and even some rather creative ones) are already taken. So I had no choice, but to invent this tongue-in-cheek name. Also, my wife approved it.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
File details
Details for the file copykitten-1.2.2.tar.gz
.
File metadata
- Download URL: copykitten-1.2.2.tar.gz
- Upload date:
- Size: 17.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.7.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d1ee05abecca7a41605d22e1a514c762656e8d5483a9da09e2623071fca22c0a |
|
MD5 | 76e9096ccdb307037b03ad6d1a3f76f8 |
|
BLAKE2b-256 | d07b91dcfab849d3f53a2308be30fa8d77cbdc3f1caad994c2b610b1fbcb25c7 |
File details
Details for the file copykitten-1.2.2-cp38-abi3-win_amd64.whl
.
File metadata
- Download URL: copykitten-1.2.2-cp38-abi3-win_amd64.whl
- Upload date:
- Size: 192.6 kB
- Tags: CPython 3.8+, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.7.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f1783b69c02a2c073964e477dade48840e80015488d81115a6ff78998ea31969 |
|
MD5 | 24087d4f28e926a63f1b40856ba6acda |
|
BLAKE2b-256 | effe262377e82a381e424a4902cf7984abf3a76c5911f4b8f1126be4011392e2 |
File details
Details for the file copykitten-1.2.2-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: copykitten-1.2.2-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 432.5 kB
- Tags: CPython 3.8+, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.7.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 83c8aff0971ba54d73f645c464f8e105e08042e101d246c965032cf0946566f8 |
|
MD5 | cb5ac9ee8ce9cbf439d31c04d81b244e |
|
BLAKE2b-256 | e738c2470add369e2404ee095dd06d29537473ed7e2706336a3aa7494db1911d |
File details
Details for the file copykitten-1.2.2-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
.
File metadata
- Download URL: copykitten-1.2.2-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 410.4 kB
- Tags: CPython 3.8+, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.7.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6362c526fcb4a69b5dfdbcc4ea189a880c29fae58a0bcab558837c1d59078c44 |
|
MD5 | eff3dfee4b40e8600b7cb73d5a9b7b9a |
|
BLAKE2b-256 | c8882a0fb779f1f748902ec057ad1c72395483340f9a9f26ec4d3880086a7a8e |
File details
Details for the file copykitten-1.2.2-cp38-abi3-macosx_11_0_arm64.whl
.
File metadata
- Download URL: copykitten-1.2.2-cp38-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 369.4 kB
- Tags: CPython 3.8+, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.7.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8b8aeef4a24f7425031df87ced2a569ced1be89ed4f2d894793a4e3697df644f |
|
MD5 | b5ca7295fff56af477c158a811bbc727 |
|
BLAKE2b-256 | 7de8add871a79d8ee113008a438d8f2df6740c6bd5e580e922a92a83cdee7fbe |
File details
Details for the file copykitten-1.2.2-cp38-abi3-macosx_10_12_x86_64.whl
.
File metadata
- Download URL: copykitten-1.2.2-cp38-abi3-macosx_10_12_x86_64.whl
- Upload date:
- Size: 381.1 kB
- Tags: CPython 3.8+, macOS 10.12+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.7.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e59b1c9cc5e8ec723b9426a92e7868cdbeed0468596ca28313cf8ba1405b7128 |
|
MD5 | 3c69935eb76550f2dee91153363ce354 |
|
BLAKE2b-256 | 93a34b8b69d668d2967cff5ccc0791b0c85e725259bad8fc3a51a5021fa798d5 |