A simple CLI to extract text from documents using the Mistral OCR API.
Project description
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 only (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
# 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 to process (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-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.
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 passed directly to Mistral.
Development
uv sync --group dev
uv run pytest tests/
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mistral_ocr_tool-1.2.0.tar.gz.
File metadata
- Download URL: mistral_ocr_tool-1.2.0.tar.gz
- Upload date:
- Size: 57.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b5e3b8cfb86b81b547801be341bff55ec0fd5fdcfb1d8116461596182d7ccef9
|
|
| MD5 |
bb96a991dc610ca408364d8217c36b71
|
|
| BLAKE2b-256 |
eaabb4be660eeb9927100e1b136e41511c237a11c6929bfa8496a2383d2dab0b
|
File details
Details for the file mistral_ocr_tool-1.2.0-py3-none-any.whl.
File metadata
- Download URL: mistral_ocr_tool-1.2.0-py3-none-any.whl
- Upload date:
- Size: 8.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
00866e647d538f25ecfb5a11fa11f013acff21edd44dbc0990aa8d9c416b7b77
|
|
| MD5 |
5764daa0149c70a43a7259d47f81a31a
|
|
| BLAKE2b-256 |
919d4977476f5b78ba6d63311f565294aa7811cc5c73f27ff8ebf0391a4778bd
|