You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

mistral-ai-ocr

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mistral-ai-ocr

1.4
pipPyPI
Maintainers
1

Mistral AI OCR

This is a simple script that uses the Mistral AI OCR API to get the Markdown text from a PDF or image file

Usage

Install the Requirements

To install the necessary requirements, run the following command:

pip install mistral-ai-ocr

Typical Usage

mistral-ai-ocr paper.pdf
mistral-ai-ocr paper.pdf --api-key jrWjJE5lFketfB2sA6vvhQK2SoHQ6R39
mistral-ai-ocr paper.pdf -o revision
mistral-ai-ocr paper.pdf -e
mistral-ai-ocr paper.pdf -m FULL
mistral-ai-ocr page74.jpg -e
mistral-ai-ocr -j paper.json
mistral-ai-ocr -j paper.json -m TEXT_NO_PAGES -n

Arguments

ArgumentDescription
input PDF or image file
-k API_KEY--api-key API_KEYMistral API key, can be set via the MISTRAL_API_KEY environment variable
-o OUTPUT--output OUTPUToutput directory path. If not set, a directory will be created in the current working directory using the same stem (filename without extension) as the input file
-j JSON_OCR_RESPONSE--json-ocr-response JSON_OCR_RESPONSEpath from which to load a pre-existing JSON OCR response (any input file will be ignored)
-m MODE--mode MODEmode of operation: either the name or numerical value of the mode. Defaults to FULL_NO_PAGES
-s PAGE_SEPARATOR--page-separator PAGE_SEPARATORpage separator to use when writing the Markdown file. Defaults to \n
-n--no-jsondo not write the JSON OCR response to a file. By default, the response is written
-e--load-dot-envload the .env file from the current directory using python-dotenv, to retrieve the Mistral API key
-E--load-path-dot-envload the .env file from the specified path using python-dotenv, to retrieve the Mistral API key. Defaults to ~/.mistral_ai_ocr.env

Modes

ValueName
0FULL
1FULL_ALT
2FULL_NO_DIR
3FULL_NO_PAGES
4TEXT
5TEXT_NO_PAGES

Given the input file paper.pdf, the directory structure for each mode is shown below:

0 - FULL

Structure

paper
├── full
│   ├── image1.png
│   ├── image2.png
│   ├── image3.png
│   └── paper.md
├── page_0
│   ├── image1.png
│   └── paper.md
├── page_1
│   ├── image2.png
│   └── paper.md
└── page_2
    ├── image3.png
    └── paper.md

1 - FULL_ALT

Structure

paper
├── image1.png
├── image2.png
├── image3.png
├── paper.md
├── page_0
│   ├── image1.png
│   └── paper.md
├── page_1
│   ├── image2.png
│   └── paper.md
└── page_2
    ├── image3.png
    └── paper.md

2 - FULL_NO_DIR

Structure

paper
├── image1.png
├── image2.png
├── image3.png
├── paper.md
├── paper0.md
├── paper1.md
└── paper2.md

3 - FULL_NO_PAGES default

Structure

paper
├── image1.png
├── image2.png
├── image3.png
└── paper.md

4 - TEXT

Structure

paper
├── paper.md
├── paper0.md
├── paper1.md
└── paper2.md

5 - TEXT_NO_PAGES

Structure

paper
└── paper.md

By default, the JSON response from the Mistral AI OCR API is saved in the output directory. To disable JSON output, use the -n or --no-json argument. To experiment with a different mode without using additional API calls, reuse an existing JSON response instead of the original input file

Mistral AI API Key

To obtain an API key, you need a Mistral AI account. Then visit https://admin.mistral.ai/organization/api-keys and click the Create new key button

To avoid using -e to load the .env file, you can create one at $HOME/.mistral_ai_ocr.env (where $HOME is your home directory). It will then be automatically loaded at the start of the script

For example, for an user called vavilov, the path would look like this:

  • Linux

    /home/vavilov/.mistral_ai_ocr.env  
    
  • macOS

    /Users/vavilov/.mistral_ai_ocr.env  
    
  • Windows

    C:\Users\vavilov\.mistral_ai_ocr.env  
    

and the content will be something like this:

MISTRAL_API_KEY=jrWjJE5lFketfB2sA6vvhQK2SoHQ6R39

FAQs

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.