Skip to main content

Cross-platform screenshot & clipboard OCR with bbox, powered by RapidOCR.

Project description

clipocr

CI PyPI version Python versions License: MIT

Cross-platform screenshot & clipboard OCR for Python. Powered by RapidOCR. Returns text plus bounding boxes. Works on macOS / Windows / Linux.

中文文档

Why

You took a screenshot. You want the text out of it — without uploading it anywhere.

clipocr reads the image directly from your clipboard or a file, runs a fast on-device OCR model, and gives you back:

  • the recognized text (in reading order),
  • a list of Blocks, each with text, bbox (xmin, ymin, xmax, ymax) and confidence,
  • and overall metadata (engine, image size, average confidence).

Good for: error-screenshot to text, code screenshots, UI mock review, document snippets, anything where you don't want to send your image to a cloud API.

Install

pip install clipocr

The first run downloads ~15 MB of ONNX models into your site-packages (one-time, then cached).

Quick start

Python

from clipocr import ocr, ocr_clipboard

# From a file path
result = ocr("screenshot.png")
print(result.text)
for block in result.blocks:
    print(block.bbox, block.text, block.confidence)

# From the system clipboard
result = ocr_clipboard()
print(result.text)

OcrResult is a frozen dataclass:

result.text         # str  — full text in reading order, joined by "\n"
result.blocks       # list[Block] — text + bbox + confidence per region
result.confidence   # float — average confidence, 0..1
result.engine       # "rapidocr"
result.image_size   # (width, height)
result.is_empty     # True when no text was found
result.to_dict()    # JSON-serializable dict

CLI

clipocr screenshot.png              # plain text
clipocr screenshot.png --bbox       # text with bounding boxes
clipocr screenshot.png --json       # full result as JSON
clipocr --clip                      # read image from clipboard
clipocr --version

Set CLIPOCR_VERBOSE=1 to keep RapidOCR's INFO logs visible.

Platform notes

Platform Clipboard backend
macOS Pillow ImageGrab.grabclipboard()
Windows Pillow ImageGrab.grabclipboard()
Linux (Wayland) wl-paste --type image/png
Linux (X11) xclip -selection clipboard -t image/png -o

On Linux, install wl-clipboard (Wayland) or xclip (X11) to enable --clip.

Languages

clipocr ships with the default RapidOCR PP-OCRv4 mobile models. They handle:

  • Simplified & Traditional Chinese
  • English (Latin alphabet)
  • Numbers and common punctuation

Mixed Chinese + English content works out of the box.

Development

git clone https://github.com/lidongyangLeo/clipocr.git
cd clipocr

python3 -m venv .venv
source .venv/bin/activate
pip install -e ".[dev]"

pytest                       # unit tests with coverage
pytest -m integration        # also exercise the real RapidOCR engine
ruff check src tests         # lint

The test suite enforces ≥ 90% coverage via pytest-cov.

How it works

┌──────────────────┐     ┌─────────────┐     ┌──────────┐
│ image / clipboard │ --> │ RapidOCR    │ --> │ OcrResult │
└──────────────────┘     │ (ONNX, on-device) │  └──────────┘
                         └─────────────┘

clipocr is a thin shim around RapidOCR. It contributes:

  1. A clean Python API (ocr / ocr_clipboard / OcrResult).
  2. A cross-platform clipboard adapter.
  3. Reading-order block sorting (top-to-bottom rows, left-to-right within a row).
  4. A version-tolerant engine output normalizer (works with both legacy rapidocr-onnxruntime and the new rapidocr >= 2.x).
  5. A clipocr CLI with stdout-clean defaults.

Contributing

Issues and PRs welcome. Please run the tests and ruff check before submitting.

License

MIT — see LICENSE.

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

clipocr-0.1.0.tar.gz (17.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

clipocr-0.1.0-py3-none-any.whl (11.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: clipocr-0.1.0.tar.gz
  • Upload date:
  • Size: 17.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for clipocr-0.1.0.tar.gz
Algorithm Hash digest
SHA256 dd62a51392f88c8fc740be57e88aa5c532779a19d95e5b5b11ec750fe9c1ff9b
MD5 80a58a313ac2eceb7faed533effd85de
BLAKE2b-256 e3c81cd8cafa9f77730b8ee3baba2357291fa0935044ad00f656e2057efc2674

See more details on using hashes here.

Provenance

The following attestation bundles were made for clipocr-0.1.0.tar.gz:

Publisher: publish.yml on lidongyangLeo/clipocr

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file clipocr-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: clipocr-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 11.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for clipocr-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9ebb8ecc54e5647f45381fd1c80cfbe97e3bb2d9efd638ff478c7b914e7f4c6a
MD5 8c794a4851b95e4a061c979b42503da3
BLAKE2b-256 82840cf96ac406ccc75bc268857c43ab70504768a2b6c25022646a6c073310f6

See more details on using hashes here.

Provenance

The following attestation bundles were made for clipocr-0.1.0-py3-none-any.whl:

Publisher: publish.yml on lidongyangLeo/clipocr

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page