Skip to main content

ppocr-lite

A lightweight PaddlePaddle-OCR runtime for images like screenshots.

Dependency Role
numpy All numerical computation
Pillow Image I/O and resize
onnxruntime Model inference
scipy (optional) Faster connected-component labelling

No OpenCV, deep-learning framework or utility libraries.


Install

pip install ppocr-lite        # CPU
pip install ppocr-lite[gpu]   # GPU (uses onnxruntime-gpu)
pip install ppocr-lite[fast]  # + scipy for faster CC labelling

Models (PP-OCRv5 mobile det/rec + v2 direction cls) can be auto-downloaded to ~/.cache/ppocr_lite/ on first use, or manually downloaded and configured.

Automatically downloaded models come from RapidOCR and are downloaded from huggingface (see here for details).

To manually download models see their huggingface - you'll need one det.onnx (for text detection), one rec.onnx (for text recognition) and the corresponding dict.txt (the model-output-to-character mapping). The mobile (= smaller) models as shipped by OnnxOCR also work quite well.


Quick Start

from ppocr_lite import PPOCRLite

ocr_engine = PPOCRLite()

for result in ocr_engine.run("screenshot.png"):
    print(f"{result.score:.2f}  {result.text}")
    # result.box is a np.ndarray (4, 2) - top-left, top-right, bottom-right, bottom-left

Use Your Own Models

from ppocr_lite import PPOCRLite, ModelConfig
from pathlib import Path

ocr_engine = PPOCRLite(
    ModelConfig(
        det_model=Path("models/PP-OCRv5/det.onnx"),
        rec_model=Path("models/PP-OCRv5/rec.onnx"),
        dict_path=Path("models/PP-OCRv5/dict.txt"),
        cls_model=False,   # skip direction classifier
    )
)

GPU inference

ocr_engine = PPOCRLite(providers=["CUDAExecutionProvider", "CPUExecutionProvider"])

Manage Downloaded Models

A few utility functions are available to configure from and to where models are downloaded:

from ppocr_lite import models

models.set_cache_directory("./my-cache-dir")
models.get_cache_directory()  # -> pathlib.Path

models.list_downloaded_models() # -> list[pathlib.Path]
models.download_default_models()
models.download_model("https://huggingface.co/me/my-repo/resolve/main/my-model.onnx?download=true")

Of course you are entirely free to not use the built-in model management functionality and instead do everything yourself – just configure your engine on initialization as described above.


Optimized Path to Check Whether Text is Present

To efficiently check whether a certain text is present in the image, use this function:

res_first_text, res_second_text = ocr_engine.check_contains(
    "./my-screenshot.png",
    
    # Phrases to look for:
    ["This is some text", "some other text"],
    
    # Optionally, position hints can speed up the search by starting to recognize text
    # close to them first; on images with much text, this can be a big boost:
    position_hints=[
        (0.5, 0.5),
        (0.5, 0.6)
    ],
  
    # You can control how far text can be from any given location hint. Text further away than this
    # distance will be ignored; it basically tells the engine how precise your location hints are. 
    # The value is relative to the shorter image side (0 - 1.0):
    position_max_dist=0.3,
    
    # Fuzzy matching is supported; set to zero to disable:
    fuzzy_match_min_similarity=0.8,
)

Design Notes

This project is very similar to the excellent RapidOCR, but more lightweight. Notably, it does not depend on OpenCV (which weighs around 200MB) and uses numpy-based alternatives instead. This does not hurt performance much, at least in my humble tests.

Please be aware that many of those numpy-based alternatives are only really feasible because this project assumes non-distorted input images (screenshots, clean document scans, …). I have not tested it, but I'd assume it doesn't work nearly as well on inputs like perspective-distorted real-world photographs.

What's different here?

  • Detection post-processing – contour finding is replaced with scipy ndimage.label (or a numpy fallback). The minimum-area rectangle is simplified under the assumption of non-perspective distorted input. Polygon offset ("unclip") is done analytically using the area/perimeter ratio and a per-vertex outward push — accurate enough for near-rectangular screenshot text.

  • Resize – PIL BILINEAR instead of cv2.resize. The two are numerically equivalent for the precision required by OCR.

  • Crop – axis-aligned bounding-rect crop instead of a perspective warp. Screenshot text is always axis-aligned, making this lossless.

  • No config YAML, no omegaconf – plain Python dataclasses.

Limitations vs. full PaddleOCR

  • No perspective correction
  • Direction classifier is only a 0°/180° binary; no 90°/270° support.

License

This project is GPL-3.0-or-later licensed. Note that the licenses of models (self-brought or auto-downloaded) will likely differ; refer to their creators for more information.

Metadata

Release files for ppocr-lite 0.5.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ppocr-lite 0.5.5
File Size Uploaded Provenance Actions
ppocr_lite-0.5.5.tar.gz 32.2 kB With provenance Details for ppocr_lite-0.5.5.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for ppocr-lite 0.5.5
File Interpreter ABI Platform Actions
ppocr_lite-0.5.5-py3-none-any.whl Python 3 none any Details for ppocr_lite-0.5.5-py3-none-any.whl

Total release size: 65.6 kB

Release files / ppocr_lite-0.5.5.tar.gz

Download URL ppocr_lite-0.5.5.tar.gz
Size 32.2 kB
Tags Source
SHA-256 checksum
How to use checksums
6f4f5c6e159018d89cfea51e1ac04fd541933ef299d72019e7f941851f17c5f9
BLAKE2b-256 checksum
How to use checksums
e9346b5a115dd759c1390ffe3aebc7e6c9b68fc6a76d18b49afb17af2deb9b22
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 6, 2026.

Transparency log

Release files / ppocr_lite-0.5.5-py3-none-any.whl

Download URL ppocr_lite-0.5.5-py3-none-any.whl
Size 33.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cf5b68a3ed18a53c24054d2c4b69ac462b91554161fd73b80d450a21fc9d34dc
BLAKE2b-256 checksum
How to use checksums
8b785a6975defe45c6cffc84f74813c5f30414b907e0e4f08c674557591edbd8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 6, 2026.

Transparency log

Security for ppocr-lite 0.5.5

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.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for ppocr_lite-0.5.5.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 6, 2026.

Transparency log

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.

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