Skip to main content

Simple batch OCR for PDFs using Mistral's state-of-the-art vision model

Project description

mistocr

Why mistocr?

Performance: Mistral’s OCR delivers state-of-the-art accuracy on complex documents including tables, charts, and multi-column layouts.

Scale: Process entire folders of PDFs in a single batch job. Upload once, process asynchronously, and retrieve results when ready - perfect for large document sets.

Cost savings: Batch OCR mode reduces costs from $1/1000 pages to $0.50/1000 pages - a 50% reduction compared to synchronous processing.

Simplicity: A single ocr() function handles everything - uploading, batch submission, polling for completion, and saving results as markdown with extracted images. Process one PDF or an entire folder with the same simple interface.

Organized output: Each PDF is automatically saved to its own folder with pages as separate markdown files and images in an img subfolder, making results easy to navigate and process further.

Installation

Install latest from the GitHub repository:

$ pip install git+https://github.com/franckalbinet/mistocr.git

or from pypi

$ pip install mistocr

How to use

Basic usage

Process a single PDF:

from mistocr.core import ocr

fname = 'files/test/attention-is-all-you-need.pdf'
result = ocr(fname)

Or process an entire folder:

results = ocr('files/test')

Output structure

Each PDF is saved to its own folder with pages as separate markdown files and images in an img subfolder:

files/test/md/
├── attention-is-all-you-need/
│   ├── img/
│   │   ├── img-0.jpeg
│   │   ├── img-1.jpeg
│   │   └── ...
│   ├── page_1.md
│   ├── page_2.md
│   └── ...
└── resnet/
    ├── img/
    └── ...

Reading results

Read all pages from a processed PDF:

from mistocr.core import read_pgs

text = read_pgs('files/test/md/attention-is-all-you-need')

Or read a specific page:

text = read_pgs('files/test/md/attention-is-all-you-need', 10)

Customization

Customize output directory, image inclusion, and polling interval:

results = ocr('files/test', out_dir='output', inc_img=False, poll_interval=5)

Parameters:

  • path: A single PDF file or folder containing multiple PDFs
  • out_dir: Directory name for saving markdown output (default: 'md')
  • inc_img: Include extracted images in the output (default: True)
  • key: Your Mistral API key (uses MISTRAL_API_KEY environment variable if not provided)
  • poll_interval: Seconds between batch job status checks (default: 2)

Returns: List of paths to the generated markdown files

Developer Guide

If you are new to using nbdev here are some useful pointers to get you started.

Install mistocr in Development mode

# make sure mistocr package is installed in development mode
$ pip install -e .

# make changes under nbs/ directory
# ...

# compile to have changes apply to mistocr
$ nbdev_prepare

Documentation

Documentation can be found hosted on this GitHub repository’s pages. Additionally you can find package manager specific guidelines on conda and pypi respectively.

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

mistocr-0.1.6.tar.gz (15.1 kB view details)

Uploaded Source

Built Distribution

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

mistocr-0.1.6-py3-none-any.whl (13.2 kB view details)

Uploaded Python 3

File details

Details for the file mistocr-0.1.6.tar.gz.

File metadata

  • Download URL: mistocr-0.1.6.tar.gz
  • Upload date:
  • Size: 15.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.16

File hashes

Hashes for mistocr-0.1.6.tar.gz
Algorithm Hash digest
SHA256 8ef78fe470548cec219cdfc11ae18dde62ef536a3fb5c04c5728b4d7957fd93a
MD5 bc1493e88f7b270bb2642f83cd340bcd
BLAKE2b-256 f4cd8b932f20bdb69fa48b5e030a2c0462b7e1fdb8d52ee5b10e69ab402e1c59

See more details on using hashes here.

File details

Details for the file mistocr-0.1.6-py3-none-any.whl.

File metadata

  • Download URL: mistocr-0.1.6-py3-none-any.whl
  • Upload date:
  • Size: 13.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.16

File hashes

Hashes for mistocr-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 64303e056d07bb2ca8fad8b8b19a12774709bde03af6b1525daff7121ad6c709
MD5 4899084c4d85aa01b15d001f73d5a7c3
BLAKE2b-256 e525f74bf2c640c7294eb53b78643fe3b39a0d8dd8f620a7b5063d2969d1c61a

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