CAPTCHA solvers¶
Choose a solver for CAPTCHA-gated portal clients. The default prefers OCR when available and otherwise requests manual input; ONNX must be selected explicitly.
See solver setup and retries for optional dependencies, model access and unattended execution.
Solver interface¶
CaptchaSolver ¶
Bases: ABC
Base class for solving eCourts Securimage CAPTCHAs.
solve abstractmethod async ¶
Given raw CAPTCHA image bytes, return the solved text.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image_bytes | bytes | PNG/JPEG bytes of the CAPTCHA image. | required |
Returns:
| Type | Description |
|---|---|
str | The CAPTCHA text as a string. |
Source code in src/bharat_judgements/captcha/base.py
OCR solver¶
OCRCaptchaSolver ¶
Bases: CaptchaSolver
CAPTCHA solver using ddddocr for Securimage CAPTCHAs.
Requires the ocr extra: pip install bharat-judgements[ocr]
Uses ddddocr (deep-learning CAPTCHA recognition) which works well with eCourts' Securimage CAPTCHAs. Optionally applies Pillow preprocessing to improve accuracy on noisy images.
Initialize the OCR solver.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
preprocess | bool | Apply Pillow preprocessing before OCR. | False |
threshold | int | Binarization threshold (0-255) for preprocessing. | 128 |
Source code in src/bharat_judgements/captcha/ocr.py
solve async ¶
Recognize CAPTCHA text from image bytes.
Returns an empty string if the OCR output isn't a valid 6-char alphanumeric — eCourts portals reject anything else with a length-validation error, so we short-circuit and signal upstream callers to skip this attempt.
Source code in src/bharat_judgements/captcha/ocr.py
ONNX solver¶
ONNXCaptchaSolver ¶
Bases: CaptchaSolver
CAPTCHA solver using ONNX Runtime for Securimage CAPTCHAs.
Requires the onnx extra: pip install bharat-judgements[onnx]
Uses a pre-trained ONNX model (captchabreaker from HuggingFace). The model is lazily downloaded on first use to ~/.cache/bharat-judgements/.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_path | str | Path | None | Optional path to a custom ONNX model file. If not provided, downloads the default captchabreaker model. | None |
Source code in src/bharat_judgements/captcha/onnx.py
solve async ¶
Recognize CAPTCHA text from image bytes using ONNX model.
Returns the recognized text if it's exactly 6 characters, otherwise returns empty string to trigger a client retry.
Source code in src/bharat_judgements/captcha/onnx.py
Manual solver¶
ManualCaptchaSolver ¶
Bases: CaptchaSolver
Solver that asks a human to read the CAPTCHA.
By default, saves the image to a temp file and prompts on stdin. Pass a custom callback for GUI or web-based workflows.