Skip to main content

OCR extraction and text grouping for product/nutrition label images

Project description

Lightweight, stateless Python library for extracting structured data from product packaging labels using OCR and LLM-based parsing.

PyPI version Python 3.8+ License: MIT

Features

  • Stateless & In-Memory: Processes raw image bytes—no disk I/O, ideal for serverless (FastAPI/Flask).

  • OCR + LLM Powered: Uses EasyOCR for text extraction and Mistral AI (mistral-small-latest) for structured parsing.

  • Noise Filtering: Automatically cleans low-confidence OCR text and groups spatial blocks (rows/columns/proximity).

  • Flexible Auth: Pass api_key directly or via MISTRAL_API_KEY environment variable.

  • Structured JSON Output: Extracts brand, product name, ingredients, nutrition facts, allergens, and more.

Installation

pip install tejas-label-ocr

Usage

Front Label Processing

from label_ocr import process_front_label

with open("product_label.jpg", "rb") as f:
    image_bytes = f.read()

result = process_front_label(image_bytes, api_key="your-mistral-api-key")
print(result)
# Output: {"brand": "Nestlé", "product_name": "Organic Oats", "claims": ["Gluten-Free", "Non-GMO"], ...}

Nutrition Label Processing

from label_ocr import process_nutrition_label

with open("nutrition_panel.jpg", "rb") as f:
    image_bytes = f.read()

result = process_nutrition_label(image_bytes, api_key="your-mistral-api-key")
print(result)
# Output: {"serving_size": "30g", "nutrients": [{"name": "Calories", "value": 120, "unit": "kcal", "%RDA": 6}], ...}

— Notes —–

  • Requires a Mistral AI API key (sign up at Mistral AI).

  • For best results, use high-resolution images of labels with clear text.

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

tejas_label_ocr-0.1.1.tar.gz (6.9 kB view details)

Uploaded Source

Built Distribution

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

tejas_label_ocr-0.1.1-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

Details for the file tejas_label_ocr-0.1.1.tar.gz.

File metadata

  • Download URL: tejas_label_ocr-0.1.1.tar.gz
  • Upload date:
  • Size: 6.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.9

File hashes

Hashes for tejas_label_ocr-0.1.1.tar.gz
Algorithm Hash digest
SHA256 fad76c28842a1a381de62c8c5a11cad2e0c2b13f1455516923c044403c9be9d8
MD5 3efd57cc3c06beca03ce45bd7ac50c8a
BLAKE2b-256 68a61f682bcdb6fbc92f41958f1ac7e6a92d68a3ca91527744d40c2d50c12ccb

See more details on using hashes here.

File details

Details for the file tejas_label_ocr-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for tejas_label_ocr-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5455be074f09f174177f5c741b8cb306509a095d07f83502440c15135163dea8
MD5 da481a564ba43fb185463f83ca931924
BLAKE2b-256 b4e966c7367e729521160f4ad66da44bae84b32baea4a17940cfebaa7ec2b46a

See more details on using hashes here.

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