CAPTCHA solvers¶
The live portals are Securimage-CAPTCHA gated. Solving is pluggable: implement the CaptchaSolver ABC, or use one of the bundled solvers. See the CAPTCHA guide.
CaptchaSolver (base class)¶
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_courts/captcha/base.py
OCRCaptchaSolver¶
OCRCaptchaSolver ¶
Bases: CaptchaSolver
CAPTCHA solver using ddddocr for Securimage CAPTCHAs.
Requires the ocr extra: pip install bharat-courts[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_courts/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_courts/captcha/ocr.py
ONNXCaptchaSolver¶
ONNXCaptchaSolver ¶
Bases: CaptchaSolver
CAPTCHA solver using ONNX Runtime for Securimage CAPTCHAs.
Requires the onnx extra: pip install bharat-courts[onnx]
Uses a pre-trained ONNX model (captchabreaker from HuggingFace). The model is lazily downloaded on first use to ~/.cache/bharat-courts/.
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_courts/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_courts/captcha/onnx.py
ManualCaptchaSolver¶
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.