A clean command-line tool for OCR processing using Mistral AI's API
Project description
Mistral OCR CLI
A command-line tool for OCR processing using Mistral AI's OCR API. Process PDFs and images to extract text, tables, equations, and images.
Disclaimer: This is an unofficial, community-created tool. Not affiliated with or endorsed by Mistral AI. For official tools, see the Mistral OCR docs.
Installation
Requires Python 3.11+ and a Mistral API key.
pip install mistral-ocr-cli
Or from source:
git clone https://github.com/r-uben/mistral-ocr-cli.git
cd mistral-ocr-cli
uv sync
Quick start
# Set your API key
export MISTRAL_API_KEY="your_key_here"
# Process a single file
mistral-ocr document.pdf
# Process a directory
mistral-ocr ./documents --output-path ./results
# Preview what would be processed (no API calls)
mistral-ocr ./documents --dry-run
# Process 4 files concurrently
mistral-ocr ./documents --workers 4
Options
Usage: mistral-ocr INPUT_PATH [OPTIONS]
Arguments:
INPUT_PATH Path to input file or directory (required)
Options:
-o, --output-path PATH Output directory (default: <input_dir>/mistral_ocr_output/)
--api-key TEXT Mistral API key (or set MISTRAL_API_KEY env var)
--model TEXT OCR model (default: mistral-ocr-latest)
--env-file PATH Path to .env file
--include-images/--no-images Extract embedded images (default: True)
--save-originals/--no-save-originals Copy original files to output (default: True)
--metadata/--no-metadata Include markdown header block (default: True)
--page-headings/--no-page-headings Include "## Page N" headings (default: True)
--table-format [markdown|html] Extract tables separately (OCR 3+)
--extract-headers/--no-extract-headers Extract page headers (OCR 3+)
--extract-footers/--no-extract-footers Extract page footers (OCR 3+)
-w, --workers N Concurrent workers for batch processing (default: 1)
--reprocess Reprocess already-processed files
--add-timestamp/--no-timestamp Timestamp output folder name (default: False)
--dry-run List files without calling the API
-q, --quiet Suppress all output except errors
-v, --verbose Enable verbose/debug output
--log-file PATH Write logs to file
--version Show version
--help Show this message
Output structure
mistral_ocr_output/
├── document_name/
│ ├── document_name.pdf # original copy (if --save-originals)
│ ├── document_name.md # OCR markdown
│ ├── figures/ # extracted images
│ │ ├── page1_img1.png
│ │ └── page2_img1.png
│ └── tables/ # extracted tables (if --table-format)
│ └── page1_table1.md
├── another_document/
│ └── ...
└── metadata.json # processing stats, file list, errors
Use --no-metadata and --no-page-headings for cleaner markdown output without the header block and page separators.
Configuration
All CLI options can also be set via environment variables or a .env file:
| CLI flag | Environment variable | Default |
|---|---|---|
--api-key |
MISTRAL_API_KEY |
(required) |
--model |
MISTRAL_MODEL |
mistral-ocr-latest |
--include-images |
INCLUDE_IMAGES |
true |
--save-originals |
SAVE_ORIGINAL_IMAGES |
true |
--metadata |
INCLUDE_METADATA |
true |
--page-headings |
INCLUDE_PAGE_HEADINGS |
true |
--table-format |
TABLE_FORMAT |
(none) |
--extract-headers |
EXTRACT_HEADER |
false |
--extract-footers |
EXTRACT_FOOTER |
false |
--workers |
MAX_WORKERS |
1 |
--verbose |
VERBOSE |
false |
MAX_FILE_SIZE_MB |
50 |
|
MAX_RETRIES |
3 |
|
RETRY_BASE_DELAY |
1.0 |
CLI flags override environment variables when explicitly passed.
Development
# Install dev dependencies
uv sync --extra dev
# Run tests
uv run pytest
# Lint
uv run ruff check .
# Format
uv run ruff format .
# Type check
uv run mypy mistral_ocr/ --ignore-missing-imports
Limitations
- Maximum file size: 50 MB (configurable via
MAX_FILE_SIZE_MB) - Supported formats: PDF, DOCX, PPTX, JPG, JPEG, PNG, WEBP, GIF, BMP, TIFF
Pricing
Mistral OCR API: ~$1 per 1,000 pages. See Mistral pricing for current rates.
License
MIT License - see LICENSE for details.
Legal
"Mistral AI" and "Mistral" are trademarks of Mistral AI. This project is not affiliated with or endorsed by Mistral AI. Use of Mistral AI's OCR API is subject to Mistral AI's Terms of Service.
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_cli-1.2.0.tar.gz.
File metadata
- Download URL: mistral_ocr_cli-1.2.0.tar.gz
- Upload date:
- Size: 23.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
022f84321d30a6fff0784cb0cc9a6a3a9542fe2825bbb082f7f5ad9615896feb
|
|
| MD5 |
0f576768454c3011a66db3d1f08d0236
|
|
| BLAKE2b-256 |
8cdd6f5e98af9fa17e156819340876bdd4d84f6aec82adba6a7f2e546ed37627
|
Provenance
The following attestation bundles were made for mistral_ocr_cli-1.2.0.tar.gz:
Publisher:
publish.yml on r-uben/mistral-ocr-cli
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mistral_ocr_cli-1.2.0.tar.gz -
Subject digest:
022f84321d30a6fff0784cb0cc9a6a3a9542fe2825bbb082f7f5ad9615896feb - Sigstore transparency entry: 1081535085
- Sigstore integration time:
-
Permalink:
r-uben/mistral-ocr-cli@39fc344300dcdf694fd33d9b04848c71503e031c -
Branch / Tag:
refs/tags/v1.2.0 - Owner: https://github.com/r-uben
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@39fc344300dcdf694fd33d9b04848c71503e031c -
Trigger Event:
release
-
Statement type:
File details
Details for the file mistral_ocr_cli-1.2.0-py3-none-any.whl.
File metadata
- Download URL: mistral_ocr_cli-1.2.0-py3-none-any.whl
- Upload date:
- Size: 18.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7a8b665bb29c5bf99465426e99369d0886af7344592803be9c4b82b9d49f0712
|
|
| MD5 |
c8191f0eeae0801c35916f58c0700597
|
|
| BLAKE2b-256 |
87ddedb1b441cb4dc7b3f6dbbfa5d1a15e81aa7f762805331058ef913a3a311c
|
Provenance
The following attestation bundles were made for mistral_ocr_cli-1.2.0-py3-none-any.whl:
Publisher:
publish.yml on r-uben/mistral-ocr-cli
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mistral_ocr_cli-1.2.0-py3-none-any.whl -
Subject digest:
7a8b665bb29c5bf99465426e99369d0886af7344592803be9c4b82b9d49f0712 - Sigstore transparency entry: 1081535180
- Sigstore integration time:
-
Permalink:
r-uben/mistral-ocr-cli@39fc344300dcdf694fd33d9b04848c71503e031c -
Branch / Tag:
refs/tags/v1.2.0 - Owner: https://github.com/r-uben
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@39fc344300dcdf694fd33d9b04848c71503e031c -
Trigger Event:
release
-
Statement type: