A simple Python utility to perform Optical Character Recognition (OCR) on a screen capture directly from your terminal. It uses the Windows Snipping Tool, detects the new screenshot, sends it to the Nanonets API for text extraction, and copies the result to your clipboard.
- Python 3.12+
- A Nanonets OCR API Key
- (Optional) uv - An extremely fast Python package installer and resolver.
Follow these steps to get the utility up and running.
First, clone this repository to your local machine.
git clone <your-repository-url>
cd <repository-directory>You can use either uv (recommended) or pip to install the required packages.
uv will create a virtual environment and install dependencies from requirements.txt in a single, fast step.
uv pip syncIf you don't have uv, you can use pip and venv to set up your environment.
python -m venv .venv
.\.venv\Scripts\Activate.ps1
pip install -r requirements.txtCreate a file named .env in the root of the project directory and add your Nanonets API key to it.
API_KEY="YOUR_NANONETS_API_KEY_HERE"
To make the script easily accessible from anywhere in your terminal, you can add a custom function to your PowerShell $PROFILE.
Open your PowerShell profile file for editing. If you're not sure where it is, run echo $PROFILE in PowerShell to find the path.
code $PROFILECopy the function that matches your installation method (uv or pip) into your profile file and update the $projectPath variable to point to the cloned repository's directory.
function ocr() {
Push-Location "C:\path\to\your\cloned_repository"
uv run main.py
Pop-Location
}This function directly calls the Python executable inside your project's virtual environment.
function ocr() {
$projectPath = "C:\path\to\your\cloned_repository"
$pythonExe = Join-Path $projectPath ".venv\Scripts\python.exe"
$scriptPath = Join-Path $projectPath "main.py"
& $pythonExe $scriptPath
}Save your profile file and restart your terminal. You can now run the utility from any directory.
ocrThe script will launch the Windows Snipping Tool. After you take a snip, it will perform OCR and copy the extracted text to your clipboard.