Skip to main content

bro-ocr

  • lightweight pydantic wrapper for quick OCR prototyping
  • aims to speed up your work on OCR with an llm-agnostic approach
  • constructing prompts, extracting information, validating result schemas — plug bro-ocr into your pipeline and it's handled

the problem

every OCR-with-LLM project ends up hand-rolling the same three things: crop the region you care about, describe what you want back as a schema, then validate whatever JSON the model hands back. bro-ocr turns that into two objects instead of a pile of copy-pasted glue code — and it never locks you into a specific LLM provider.

two objects you need to know

Template — serves as data model and configuration.

  • an image has a size (w, h) and a list of patches (regions of interest)
  • each Patch is a bounding box (x, y, w, h) plus its own schemas and an optional instruction
  • each Schema is one field to extract — a field name, a dtype, and an optional per-field instruction

it's just data. build it once, reuse it for every document of that layout.

SchemaConverter — integrates with Template to create a dynamic pydantic data model, usable as both a schema builder and a schema validator.

  • from_single — exactly one field, flat on the model (e.g. total_amount: float)
  • from_object — any number of fields (zero included), nested under the patch name (e.g. invoice_date: {year, month, day})
  • from_list — a repeating group of fields, nested as a list under the patch name (e.g. items: [...])

same model, two jobs: dump .model_json_schema() into your prompt so the LLM knows the shape you want back, then call .model_validate_json(...) on the response to make sure it actually came back that shape.

install

uv add bro-ocr
# or
pip install bro-ocr

for local development, clone the repo and install editable instead:

uv pip install -e .

quickstart

define a patch and its schema:

from bro_ocr.core.template import Dtype, Patch, Schema, SchemaType, Template

total_amount = Patch(
    name="total_amount",
    x=455, y=564, w=86, h=25,
    schema_type=SchemaType.SINGLE,
    schemas=[Schema(field="total_amount", dtype=Dtype.FLOAT)],
    instruction="amount is in float",
)

template = Template(name="invoice", w=578, h=750, patches=[total_amount])

turn it into a pydantic model, use it both ways:

from bro_ocr.utils.conversion import SchemaConverter as sc

model = sc.from_single(total_amount.name, total_amount.schemas)

# 1. shape your prompt
model.model_json_schema()

# 2. validate what the LLM sent back
model.model_validate_json('{"total_amount": 551.56}')

from_object (nested group of fields, any count) and from_list (nested repeating rows) follow the same pattern — build with .model_json_schema(), validate with .model_validate_json(...). See notebooks/dev.ipynb for a full invoice walkthrough covering all three SchemaTypes, cropping patches out of a real image with cv2, and a worked example calling a vision model over AWS Bedrock.

bring your own LLM

bro-ocr doesn't ship an LLM client and never will — that's the agnostic part. it preps the region, builds the schema, validates the response. wiring up OpenAI, Anthropic, Bedrock, a local VLM, whatever — that's on you, and it's about 20 lines (see the notebook for one way to do it).

status

early days — Template + SchemaConverter is the whole lite core for now. more pieces (prompt packing, provider adapters, etc.) land later as opt-in extras without touching this base.

license

Apache 2.0

Metadata

Release files for bro-ocr 0.1.2

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

Source distribution (sdist)

Source distribution for bro-ocr 0.1.2
File Size Uploaded Provenance Actions
bro_ocr-0.1.2.tar.gz 125.6 kB With provenance Details for bro_ocr-0.1.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for bro-ocr 0.1.2
File Interpreter ABI Platform Actions
bro_ocr-0.1.2-py3-none-any.whl Python 3 none any Details for bro_ocr-0.1.2-py3-none-any.whl

Total release size: 134.2 kB

Release files / bro_ocr-0.1.2.tar.gz

Download URL bro_ocr-0.1.2.tar.gz
Size 125.6 kB
Tags Source
SHA-256 checksum
How to use checksums
e85a15f4a12913c08c766d3e7a0f2e1162b1e37c6f6170567ab0d24b1b75aeb6
BLAKE2b-256 checksum
How to use checksums
20ceb90a2996c0e789a6de973a4f7dcd0430dc3fcd9ca5a0d6a44532815da288
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 15, 2026.

Transparency log

Release files / bro_ocr-0.1.2-py3-none-any.whl

Download URL bro_ocr-0.1.2-py3-none-any.whl
Size 8.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
734f8a6134ef010b1cd9be458c4e8b2d928cd3bbeea4bcd15a25e81441b5aa78
BLAKE2b-256 checksum
How to use checksums
12d67d4749ecacc56c9765ac6c192a58f917fa2233a4f2a615c4dce1aa7f56f9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 15, 2026.

Transparency log

Security for bro-ocr 0.1.2

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

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for bro_ocr-0.1.2.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 Sep 15, 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