Python client for the FastOCR API. Send a scanned PDF or an image, get back its text or a searchable PDF. Send a bank statement, get back Excel, CSV, JSON or QuickBooks files.
Website · Docs · Get an API key
pip install fastocr-sdk
export FASTOCR_API_KEY="your_api_key"Python 3.9 or newer. The distribution is fastocr-sdk and the import is fastocr_sdk. Do not install the unrelated fastocr package from PyPI.
from fastocr_sdk import FastOCR
with FastOCR() as client:
print(client.extract_text("scanned_contract.pdf"))extract_text uploads the file, runs OCR, waits for it to finish, and returns the text. Images work the same way; pass filename when you send bytes.
| You get | How |
|---|---|
| The text of the document | client.extract_text(file) |
| A searchable PDF | client.documents.download_searchable_pdf(job.id, "out.pdf") |
| Status and page counts | job.status, job.pages_billed, job.pages_total |
| A bank statement as Excel, CSV, JSON or QuickBooks files (beta) | client.extract_statement(file), then client.bank_statements.save(job.id, "out.xlsx", "xlsx") |
| Pages left on the account | client.get_balance().pages_remaining, statement_pages_remaining |
Runnable scripts are in examples/, with RAG, archiving and cURL recipes in examples/cookbooks/. Full reference →
with FastOCR() as client:
job = client.documents.process("scanned_archive.pdf")
client.documents.download_searchable_pdf(job.id, "searchable.pdf")with FastOCR() as client:
job = client.extract_statement("statement.pdf") # upload, then wait for the result
print(job.pages_billed, job.needs_review)
client.bank_statements.save(job.id, "statement.xlsx", "xlsx")
data = client.bank_statements.json(job.id) # accounts, balances and transactionsFormats: json, csv, xlsx, qbo, quickbooks_csv, qfx and ofx. For a statement with several accounts, pass account=2 (1 is the first) to save or download for the accounting formats. job.outputs["xlsx"].url is a download link that works for one hour; call client.bank_statements.get(job.id) again for fresh links. If extraction fails, extract_statement raises StatementFailedError (a DocumentFailedError) with the failure code. Statements take PDF, PNG, JPG, JPEG and WebP files, and their pages come from a balance of their own, shared with the website's bank statement converter. A runnable script is in examples/extract_bank_statement.py.
import asyncio
from fastocr_sdk import AsyncFastOCR
async def main():
async with AsyncFastOCR() as client:
print(await client.extract_text("invoice.pdf"))
asyncio.run(main())Accounts process 2 documents at once by default. Cap concurrency with a semaphore, as in examples/async_batch.py.
Every error is a FastOCRError with status_code, code, request_id and message. Branch on code, never on message.
from fastocr_sdk import DocumentFailedError, FastOCR, FastOCRError
with FastOCR() as client:
try:
text = client.extract_text("scan.pdf")
except DocumentFailedError as error:
print(error.code, error.retryable, error.document_id)
except FastOCRError as error:
print(error.status_code, error.code, error.request_id)If the account runs out of pages partway, extract_text raises PartialResultError instead of returning truncated text; pass allow_partial=True to accept it. Transient failures are retried and a document is never created twice.
Exception classes
| Exception | When |
|---|---|
AuthenticationError |
HTTP 401 or 403 |
BadRequestError |
HTTP 400 |
NotFoundError |
HTTP 404 |
DocumentConflictError |
HTTP 409 |
RateLimitError |
HTTP 429, after retries |
ServerError, APIConnectionError |
HTTP 5xx or no response, after retries |
DocumentFailedError |
The document reached status failed |
StatementFailedError |
The bank statement reached status failed (a DocumentFailedError) |
PartialResultError |
The document was only partly processed |
Full reference: retries, idempotency, out-of-pages recovery, configuration.
Use langchain-fastocr for LangChain or llama-index-readers-fastocr for LlamaIndex. Both are built on this SDK, and both read bank statements too (one document per transaction).
- 100+ languages, detected automatically. No language setting is needed.
- PDF files up to 1 GiB, and PNG, JPG, JPEG, GIF, WebP and BMP images up to 20 MiB. An image counts as one page.
- Sync (
FastOCR) and async (AsyncFastOCR) clients. One runtime dependency:httpx.
Any signed-in FastOCR account can create an API key and start right away. Create one in the developer console; you accept the API terms with your first key. Every account gets 20 free pages a month, shared with PDFs on the website, and an image sent to the API is one page. When you need more, buy a Page Pack on the pricing page. Packs and the page balance are the same on the website and in the API. Bank statement pages are a separate balance that new accounts start with some free pages in; check both with client.get_balance().
Questions: [email protected]. Bugs and requests: GitHub issues. Full reference: docs/reference.md. MIT license; see LICENSE.