Skip to main content

Russian KASKO insurance policy field extractor — pulls 7 structured fields from PDF policies (text-layer + tables + OCR fallback).

Project description

polis-recognizer

A deterministic field extractor for Russian KASKO insurance policy PDFs. Pulls 7 structured fields without LLMs — text-layer extraction (pypdf) plus optional table-aware reading (pdfplumber), with Tesseract OCR fallback for scanned policies.

Status: pre-stable (0.x). API may change before 1.0.

What it extracts

Field Type Example
policy_number str "AC524160804"
policy_period {start, end} (date) {"start": date(2025, 2, 27), "end": date(2026, 2, 26)}
franchise {value, currency, absent} {"value": 30000, "currency": "RUB", "absent": False}
limit {value, currency} {"value": 5525000, "currency": "RUB"}
premium {value, currency} {"value": 220000, "currency": "RUB"}
sum_type "aggregate" / "non_aggregate" "non_aggregate"
repair_mode "dealer" / "service" / "cash" "dealer"

Quick start

from polis_recognizer import PolicyExtractor

extractor = PolicyExtractor()
result = extractor.extract_from_pdf("/path/to/polis.pdf")

print(result.policy_number)
# → "AC524160804"
print(result.policy_period)
# → {"start": date(2025, 2, 27), "end": date(2026, 2, 26)}
print(result.franchise)
# → {"value": 30000.0, "currency": "RUB", "absent": False}

Input methods:

extractor.extract_from_pdf("polis.pdf")
extractor.extract_from_bytes(pdf_bytes, filename="polis.pdf")
extractor.extract_from_text("сырой текст полиса")  # bypass PDF/OCR

Installation

pip install polis-recognizer

System dependencies

polis-recognizer shells out to Tesseract for OCR and to poppler for PDF→image conversion. These are NOT pip-installable; install them through your OS package manager.

Linux (Debian/Ubuntu):

sudo apt-get install -y tesseract-ocr tesseract-ocr-rus poppler-utils libgl1

macOS (Homebrew):

brew install tesseract tesseract-lang poppler

Windows: best-effort. Install Tesseract for Windows and add it to PATH; install Poppler binaries for PDF support. We don't test on Windows in CI.

The Russian language pack (tesseract-ocr-rus / tesseract-lang) is required — without it, OCR silently falls back to English and Cyrillic documents come back as garbage. The library logs a CRITICAL warning at import time if the pack is missing.

How it works

The extractor runs three stages:

  1. PDF ingestionPdfExtractionRouter tries text-layer extraction first (pypdf for text, pdfplumber for tables on the same page). If the result is too short (fewer than 100 chars by default) or detected as glued/EDI-envelope text, it falls back to Tesseract OCR.
  2. Text normalization — Unicode NFKC, NBSP stripping, hyphenated line-break healing, runs of multiple spaces collapsed.
  3. Field extraction — 7 deterministic parsers (one per field) run regex + table-aware patterns and emit Candidates with confidence scores. A ranker picks the winner per field.

There's no LLM and no cloud dependency. Everything runs locally.

PDF extractor choice

The default is "hybrid" — pypdf text plus pdfplumber tables in one pass. Two alternatives:

Option When to use
"hybrid" (default) Best for KASKO. pypdf preserves date/period text quality, pdfplumber's tables fix the column layout for limit/franchise/premium.
"pypdf" Faster, no tables. Use when document quality is uniform and tables aren't needed.
"pdfplumber" Fully layout-aware. Slower; on KASKO it slightly regresses date parsing. Use for table-heavy non-KASKO formats.
extractor = PolicyExtractor(pdf_extractor="pypdf")

Supported insurer formats

The parser ships with patterns for these Russian insurers' KASKO templates: АльфаСтрахование (XLS form-mask), СОГАЗ-АВТО, Чулпан, Ингосстрах, ВСК, АбсолютСтрахование, Росгосстрах, СОГАЗ Diadoc-wrapped PDFs. Recall on real-world KASKO corpora is ~50-65% per field; pulling above that requires per-format parser additions.

If you have a policy from an insurer not on this list — see CONTRIBUTING.md for how to add a parser pattern.

Configuration

Constructor arguments:

extractor = PolicyExtractor(
    ocr_language="rus+eng",       # Tesseract language string
    ocr_timeout_seconds=300,
    ocr_page_limit=50,
    ocr_max_text_size=500_000,
    pdf_extractor="hybrid",       # "pypdf" | "pdfplumber" | "hybrid"
    image_preprocessing="fallback", # "never" | "fallback" | "always"
    psm=None,                     # Tesseract --psm (None = auto)
    oem=None,                     # Tesseract --oem (None = auto)
    max_image_size_bytes=None,    # reject images larger than this
)

License

MIT © Grigorii Grachev. Free for any use, including commercial.

Roadmap

This 0.1.0 release focuses on KASKO. ОСАГО support is on the roadmap — the underlying field model already accommodates it; only parser patterns need to be added.

See CHANGELOG.md for release history.

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

polis_recognizer-0.2.0.tar.gz (70.7 kB view details)

Uploaded Source

Built Distribution

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

polis_recognizer-0.2.0-py3-none-any.whl (79.0 kB view details)

Uploaded Python 3

File details

Details for the file polis_recognizer-0.2.0.tar.gz.

File metadata

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

File hashes

Hashes for polis_recognizer-0.2.0.tar.gz
Algorithm Hash digest
SHA256 e572d6573d1d66669b9e8a6d85cc2219d929c22fb32b6e3ee8ea44d3b4488342
MD5 4dd8f3d61302eb048e47627bee25359c
BLAKE2b-256 0ad77f4d12877f424036924f81d45600be5ff2a965428553cb17bc060c399892

See more details on using hashes here.

Provenance

The following attestation bundles were made for polis_recognizer-0.2.0.tar.gz:

Publisher: publish.yml on grigra27/polis-recognizer

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

File details

Details for the file polis_recognizer-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for polis_recognizer-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 23206d215f053253d7e8581c73d37441825505e6f3f8c60c8753033698db31b1
MD5 abb96dc456183d69c44aae8e9134ca46
BLAKE2b-256 e985d3c92952b3c0b6eadd963a16d940862ec1ff668cd7372b38d0ece2c2bfdb

See more details on using hashes here.

Provenance

The following attestation bundles were made for polis_recognizer-0.2.0-py3-none-any.whl:

Publisher: publish.yml on grigra27/polis-recognizer

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