Skip to main content

Extract structured data from receipt images using Gemini AI

Project description

receipt-ocr

Extract structured data from receipt images using Gemini AI.

Features

  • 📷 Extract date, amount, vendor, category from receipt images
  • 🚀 Fast and cheap with Gemini Flash
  • 🎯 ~95% accuracy on common receipt formats
  • 🔧 CLI and Python API

Installation

pip install receipt-ocr

Quick Start

CLI

# Set API key
export GEMINI_API_KEY=your_api_key

# Extract from image
receipt-ocr receipt.jpg

# Pretty print
receipt-ocr receipt.jpg --pretty

# From URL
receipt-ocr https://example.com/receipt.jpg

Output:

{
  "receipt_date": "2025-01-15",
  "amount": 4599,
  "amount_dollars": 45.99,
  "category": 0,
  "category_name": "grocery",
  "vendor_name": "Whole Foods Market",
  "payment_method": 0
}

Python API

from receipt_ocr import extract, set_api_key

# Set API key (or use GEMINI_API_KEY env var)
set_api_key("your_api_key")

# Extract from file
result = extract("receipt.jpg")
print(result.amount_dollars)  # 45.99
print(result.vendor_name)     # "Whole Foods Market"
print(result.receipt_date)    # "2025-01-15"

# Extract from URL
result = extract("https://example.com/receipt.jpg")

# Extract from bytes
with open("receipt.jpg", "rb") as f:
    result = extract(f.read())

# With date context (helps infer year)
result = extract("receipt.jpg", reference_date="2025-01")

Output Fields

Field Type Description
receipt_date str Date in YYYY-MM-DD format
amount int Total amount in cents
amount_dollars float Total amount in dollars
category int 0=grocery, 1=gas station, 2=other
category_name str Human-readable category
vendor_name str Merchant/store name
payment_method int 0=credit, 1=debit, null=unknown

CLI Options

receipt-ocr [OPTIONS] IMAGE

Arguments:
  IMAGE                 Path to receipt image or URL

Options:
  --api-key TEXT        Gemini API key
  --reference-date TEXT Expected date (YYYY-MM) for year inference
  --model TEXT          Gemini model (default: gemini-2.0-flash)
  --raw                 Include raw AI response
  --pretty              Pretty print JSON

Accuracy

Tested on ~1000 receipts:

Field Accuracy
Amount ~98%
Date ~95%
Vendor ~90%

Tips for better accuracy:

  • Clear, well-lit photos
  • Include the total amount in frame
  • Avoid heavy shadows/glare

Cost

Using Gemini Flash: ~$0.001 per receipt

License

MIT

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

gemini_receipt_ocr-0.1.0.tar.gz (6.5 kB view details)

Uploaded Source

Built Distribution

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

gemini_receipt_ocr-0.1.0-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

Details for the file gemini_receipt_ocr-0.1.0.tar.gz.

File metadata

  • Download URL: gemini_receipt_ocr-0.1.0.tar.gz
  • Upload date:
  • Size: 6.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for gemini_receipt_ocr-0.1.0.tar.gz
Algorithm Hash digest
SHA256 8478a4592b00b6c33cfb95d96eac339d1c39fb4e793331e124e98af083d85bf9
MD5 499ed8f86cb7ef38d1e53f8efb8004dd
BLAKE2b-256 dac4e329750a985b3289c156c0a1da848387c854160a85cd1c1d5d09bf230913

See more details on using hashes here.

File details

Details for the file gemini_receipt_ocr-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for gemini_receipt_ocr-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 82ea689c2d683c39a6496418420a0ccb1d88959c582ab23aab20f8fc2e66cb78
MD5 b906e858091b7e1aa0e45d796ea51dce
BLAKE2b-256 5729253d9c2bf14d32682c96b641d7943f9461438cb11922492707d1da1f6ae9

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