Python, no SDK required

OCR API Python: Extract Text and Data from PDFs and Images

Call DocuOCR from Python with a few requests calls: POST a PDF or image, start extraction, and read structured JSON back with named fields, tables and confidence scores. No OCR engine to host, no cloud SDK to wire.

The same endpoint reads digital and scanned PDFs, so one code path handles both. Copy the Python below and run it against your own document. Last updated July 2026.

  • Three requests calls, JSON out
  • Fields, tables and confidence
  • Reads scans and native PDFs
  • Webhooks for batch at scale
Try it now, no signup

PDF, JPG, PNG, BMP, HEIC, TIFF

Upload a document to extract

See the JSON your Python would receive, right in the browser.

SOC 2 Type II
256-bit encryption
US data handling
REST and JSON
3 calls
upload, extract, get JSON
0 SDKs
plain requests is enough
1 endpoint
scans and digital PDFs alike
JSON
fields, tables, confidence
// The short answer

How to call an OCR API from Python

To use an OCR API in Python, you send a document to an HTTPS endpoint and read the recognized data back as JSON, all through the requests library that ships with Python. There is no OCR engine to install, no model to train, and with a REST API like DocuOCR no SDK to add. You authenticate with a Bearer API key, POST the file to get a file_id, start an extraction job, then poll or receive a webhook for the result. Because the response is JSON, response.json() turns it into a Python dict of named fields, table rows and confidence scores you can drop straight into a database, a DataFrame or an accounting workflow. The same three calls work for a native PDF, a scanned PDF or a photo, so your code does not branch on how the document was made.

The three calls

  • Upload: POST the file, get a file_id.
  • Extract: POST the file_id, get a job id.
  • Get: poll or webhook for the JSON.
// Copy and run

OCR a PDF in Python with the DocuOCR API

Three requests calls, from a file on disk to structured JSON. Swap in your API key from the dashboard and point it at any PDF or image.

ocr_pdf.py
import time, requests

API_KEY = "YOUR_API_KEY"
BASE = "https://docuocr.com/api/documents"
headers = {"Authorization": f"Bearer {API_KEY}"}

# 1. Upload the PDF or image, get a file_id
with open("invoice.pdf", "rb") as f:
    up = requests.post(f"{BASE}/upload", headers=headers, files={"file": f})
file_id = up.json()["file_id"]

# 2. Start extraction, get a job hash
job = requests.post(f"{BASE}/extract", headers=headers, json={"file_id": file_id})
job_id = job.json()["extraction_hash"]

# 3. Poll until the JSON is ready
while True:
    res = requests.get(f"{BASE}/extraction/{job_id}", headers=headers).json()
    if res["status"] == "completed":
        break
    time.sleep(2)

# res["fields"] and res["tables"] are ready to use
for field in res["fields"]:
    print(field["name"], field["value"], field["confidence"])

That is the whole integration. For a production batch, wrap each call in a try or except block, add exponential backoff on HTTP 429, and register a webhook instead of the polling loop so results arrive as each document finishes. The document OCR API reference covers the full request and response shape.

// Python support, compared

Every major OCR API's Python package

The cloud providers ship a Python SDK; a REST API needs only requests. What you get back differs more than the language does. Package names verified July 2026.

OCR API Python package What it returns Best for
DocuOCR requests (plain REST, no SDK) Named fields, tables and confidence as JSON Fields plus tables from one call, scans included
Google Cloud Vision google-cloud-vision Text and bounding boxes, no named fields Raw text OCR on the Google stack
Google Document AI google-cloud-documentai Text plus entities, needs a service account Google-native document pipelines
AWS Textract boto3 Text, forms and tables as blocks AWS-stack teams that already use boto3
Azure AI Document Intelligence azure-ai-documentintelligence Text, layout and prebuilt-model fields Azure-stack, prebuilt invoice or receipt models
Mistral Document AI mistralai Markdown plus structured output LLM-based parsing of mixed content
Tesseract pytesseract (local, not a hosted API) Plain text only Offline, low-volume, no API cost

The split that matters: raw OCR APIs like Google Cloud Vision return text and coordinates, so you write the field mapping in Python yourself. A document extraction API returns named fields and table rows already, which is most of the code you would otherwise maintain. See the full OCR API pricing comparison for what each costs per 1,000 pages.

// How it works

From a file to a Python dict in four steps

1. Authenticate

Generate a key in the dashboard and send it as a Bearer token in the Authorization header.

2. Upload

POST a PDF, PNG, JPG, TIFF or WEBP to the upload endpoint and read the file_id from the JSON.

3. Extract

POST the file_id to start an async job and get an extraction_hash back.

4. Read JSON

Poll or receive a webhook, then response.json() gives you fields, tables and confidence.

// Where teams use it

What Python developers build on an OCR API

Document pipelines

A Python ETL job posts each incoming file, reads the JSON, and writes fields to a warehouse or database with no manual entry.

Accounts payable

A script pulls invoices from an inbox or bucket, extracts totals and line items, and posts them to QuickBooks, NetSuite or an ERP.

Table capture

A data team turns scanned statements and reports into rows and columns, then loads them into pandas for analysis.

Back-office automation

A background worker classifies and reads documents on upload so the rest of the app receives clean structured data.

Analytics ingestion

Research and ops teams convert PDFs into JSON at scale to feed dashboards and models.

Compliance and KYC

A verification flow reads IDs and forms, checks confidence scores, and routes low-confidence values to a human.

// Frequently asked

OCR API Python FAQ

How do I use an OCR API in Python?
You call it with the requests library over HTTPS. Pass your API key as a Bearer token, POST the PDF or image to the upload endpoint, start extraction, then read the structured JSON back. With DocuOCR that is three short calls and no SDK to install: upload returns a file_id, extract returns a job id, and a GET returns fields, tables and confidence scores as JSON your Python code can use directly.
What is the best OCR API for Python?
The best OCR API for Python depends on what you need back. For plain text from a clean scan, Tesseract through pytesseract runs offline for free. For structured fields and tables from real business documents, a hosted API returns cleaner data with no engine to host: DocuOCR posts a document and returns named fields and table rows as JSON in one call, while Google Cloud Vision, AWS Textract and Azure need their own cloud SDK and more wiring.
How do I extract text from a PDF in Python?
If the PDF has a real text layer, a library like pdfplumber can read it directly with no OCR. If it is a scanned or photographed PDF, it is an image and needs OCR first. Send it to an OCR API such as DocuOCR, which detects that the page is image-only, runs recognition, and returns the text plus structured fields as JSON. One code path then handles both digital and scanned PDFs.
Do I need a Python SDK to call an OCR API?
No. A REST OCR API only needs an HTTPS client, and Python ships requests for that. DocuOCR is called with plain requests, so there is nothing extra to install or keep updated. The cloud providers do publish Python SDKs (google-cloud-vision, google-cloud-documentai, boto3 for AWS Textract, azure-ai-documentintelligence), which help if you are already on that cloud but add a dependency and its own auth model.
How do I handle rate limits and retries in Python?
Wrap each API call in a try or except block and add exponential backoff on HTTP 429 and 5xx responses, honoring any Retry-After header the service returns. For large batches, send documents through a queue or a thread pool rather than one tight loop so you stay under the per-second limit. DocuOCR also supports webhooks, so at scale you register a callback URL instead of polling and let results arrive as each document finishes.
Can a Python OCR API read scanned PDFs and images?
Yes. A document OCR API reads native PDFs, scanned PDFs and image files (PNG, JPG, TIFF, WEBP) through the same endpoint. For a digital PDF it reads the embedded text, and for a scan it runs OCR on the page image. DocuOCR returns the same structured JSON either way, so your Python code does not branch on how the document was created.
How much does an OCR API cost to run from Python?
You pay per page or per document, not per line of code, so the language does not change the price. Raw text OCR runs about $1.50 per 1,000 pages at Azure, AWS and Google, Mistral is $4 per 1,000, and structured extraction runs higher. DocuOCR bills per page on a plan, roughly $14 to $20 per 1,000 pages, and includes fields and tables in that rate. The free tier lets you test the Python integration before you pay.
What does a Python OCR API return?
A good document OCR API returns JSON, which Python parses into a dict with response.json(). DocuOCR returns named fields (invoice number, date, totals), table rows with cells kept in order, and a confidence score on each value so you can flag anything below a threshold for review. Raw OCR APIs like Google Cloud Vision return text and bounding boxes but not named fields, so you write the field mapping yourself.
How do I OCR thousands of PDFs in Python?
Loop over your files, but push them through a worker pool or queue rather than one blocking loop, add backoff for rate limits, and collect results asynchronously. With DocuOCR you POST each document, then either poll the extraction endpoint or register a webhook so results arrive as jobs finish. That keeps a batch of thousands of pages moving without waiting on each call in sequence.

Ship OCR from Python this afternoon

Generate an API key, paste the three requests calls above, and read structured JSON back in minutes. No engine to host, no SDK to learn, and a free tier to test the integration before you pay per page.