Python client for the FastOCR Document OCR API. Send a scanned PDF or an image, get back its text or a searchable PDF.
Website · Docs · Get an API key
Install
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.
Quickstart
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.
What you get back
| 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 |
| Pages left on the account | client.get_balance().pages_remaining |
Examples
Runnable scripts are in examples/, with RAG, archiving and cURL recipes in examples/cookbooks/. Full reference →
Searchable PDF
with FastOCR() as client:
job = client.documents.process("scanned_archive.pdf")
client.documents.download_searchable_pdf(job.id, "searchable.pdf")
Async and batches
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.
Errors
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 |
PartialResultError |
The document was only partly processed |
Full reference: retries, idempotency, out-of-pages recovery, configuration.
RAG integrations
Use langchain-fastocr for LangChain or llama-index-readers-fastocr for LlamaIndex. Both are built on this SDK.
Languages and files
- 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.
Pages and pricing
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 50 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. Check what is left with client.get_balance().
Support and license
Questions: support@fastocr.org. Bugs and requests: GitHub issues. Full reference: docs/reference.md. MIT license; see LICENSE.
Metadata
Release files for fastocr-sdk 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| fastocr_sdk-0.3.0.tar.gz | 3.2 MB | With provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| fastocr_sdk-0.3.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 3.2 MB
Release files / fastocr_sdk-0.3.0.tar.gz
| Download URL | fastocr_sdk-0.3.0.tar.gz |
|---|---|
| Size | 3.2 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
245e1ca5f18444588259b60de8f5f200993f88069482c968cd6ae5fec3222d7e
|
|
BLAKE2b-256 checksum How to use checksums |
58a8ccacb030f588d33dfb2849f903eb37c6725bc28dae99bef2e1b4e37190dd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 25, 2026.
Transparency logRelease files / fastocr_sdk-0.3.0-py3-none-any.whl
| Download URL | fastocr_sdk-0.3.0-py3-none-any.whl |
|---|---|
| Size | 20.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
eaf598ec73555dfdec57fc17d1bedc5fb206b3fd50c9acc94f54908cc2fbd60d
|
|
BLAKE2b-256 checksum How to use checksums |
9ea3da4a01757e4130666abc6978025bd2b190aaa4c8383646f63f40db6e9f50
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 25, 2026.
Transparency logSecurity for fastocr-sdk 0.3.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for fastocr_sdk-0.3.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 25, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.