Mistral OCR
A simple CLI to extract text from documents using the Mistral OCR API.
Installation
pip install mistral-ocr-tool
To render HTML files or pages before OCR, install the optional HTML support:
pip install "mistral-ocr-tool[html]"
python -m playwright install chromium
Or install from source:
git clone https://github.com/aburkard/mistral-ocr.git
cd mistral-ocr
pip install .
Configuration
Set your Mistral API key as an environment variable or in a .env file:
MISTRAL_API_KEY="your-api-key"
Usage
mistral-ocr <document_source> [options]
The document source can be a URL, a bare domain URL, a local file path, or - to read from stdin. Bare domain URLs such as example.com/report are treated as https://example.com/report.
Examples
# Process a PDF from a URL
mistral-ocr https://example.com/document.pdf
# Process a local file
mistral-ocr ./invoice.pdf
# Render a local HTML file to PDF before OCR
mistral-ocr ./report.html
# Render an HTML page URL to PDF before OCR
mistral-ocr https://example.com/report
# URLs can omit https://
mistral-ocr example.com/report
# Pipe from stdin
cat document.pdf | mistral-ocr -
# Process specific pages or inclusive ranges (0-indexed)
mistral-ocr large-doc.pdf --pages 0,2-5
# Output as JSON (great for piping to jq)
mistral-ocr document.pdf --json | jq '.pages[0].markdown'
# Extract tables as HTML
mistral-ocr document.pdf --table-format html
# Include headers and footers
mistral-ocr document.pdf --extract-headers --extract-footers
# Preserve OCR 4 reading-order blocks, bounding boxes, and word confidence
mistral-ocr document.pdf -o output/ --include-blocks --confidence-scores word
# Save markdown and images to a directory
mistral-ocr document.pdf -o output/
# Include base64 images in JSON output (for programmatic use)
mistral-ocr document.pdf --json --include-images
# Check page count and estimated cost before processing
mistral-ocr large-doc.pdf --dry-run
Options
| Option | Description |
|---|---|
-p, --pages |
Comma-separated page numbers and inclusive ranges (0-indexed) |
--json |
Output full JSON response instead of markdown |
-o, --output-dir |
Save markdown and images to a directory |
--table-format |
Table output format: markdown or html |
--extract-headers |
Include page headers |
--extract-footers |
Include page footers |
--include-blocks |
Include OCR 4 structural blocks and bounding boxes |
--confidence-scores |
Confidence granularity: page or word |
--include-images |
Include images (requires --json or -o) |
--image-limit N |
Maximum number of images to extract; use 0 to disable image extraction |
--image-min-size N |
Minimum image dimension in pixels |
--model NAME |
Model override (default: mistral-ocr-latest) |
--render-html MODE |
HTML rendering mode: auto, always, or never (default: auto) |
--html-timeout N |
Seconds to wait while rendering HTML (default: 30) |
--dry-run |
Show page count and estimated cost without processing |
-v, --verbose |
Enable verbose logging |
Image extraction options require image output mode (-o/--output-dir or --json --include-images), except --image-limit 0, which is allowed in text-only mode to explicitly disable image extraction.
Output-directory mode writes both <document>.md and <document>.json. The JSON preserves blocks, confidence scores, tables, headers, footers, and other API metadata; extracted image base64 is replaced with an image_path to avoid duplicating image data.
HTML inputs are rendered to a temporary PDF with Chromium via Playwright before being sent to Mistral OCR. In auto mode, local .html/.htm files and URLs with Content-Type: text/html are rendered. Other URLs are downloaded locally and uploaded to Mistral, avoiding failures when Mistral cannot fetch the source URL directly.
Development
uv sync --group dev
uv run pytest tests/
Metadata
Release files for mistral-ocr-tool 1.3.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| mistral_ocr_tool-1.3.1.tar.gz | 46.2 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| mistral_ocr_tool-1.3.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 55.7 kB
Release files / mistral_ocr_tool-1.3.1.tar.gz
| Download URL | mistral_ocr_tool-1.3.1.tar.gz |
|---|---|
| Size | 46.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1f62e283270de6b06cb061ff3386a3468d32338bbe34b680ec395ec659b706da
|
|
BLAKE2b-256 checksum How to use checksums |
4e6f8beff371e20f46d83b66eafe1abb1b69858a88c68f5b4450a7202da02811
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.29 {"installer":{"name":"uv","version":"0.11.29","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / mistral_ocr_tool-1.3.1-py3-none-any.whl
| Download URL | mistral_ocr_tool-1.3.1-py3-none-any.whl |
|---|---|
| Size | 9.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
483fb0a1b50a99c97fbfc5c8280da384334fdbd6fcfc1071a3ff463011503298
|
|
BLAKE2b-256 checksum How to use checksums |
324dc3c32dce79365571df7da44501c6f530862a831350c65f6fcf1a2ef16e72
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.29 {"installer":{"name":"uv","version":"0.11.29","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for mistral-ocr-tool 1.3.1
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
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.