A LangChain document loader that reads scanned PDFs and images with FastOCR.
Website · Docs · Get an API key
Quickstart
pip install langchain-fastocr
export FASTOCR_API_KEY="your_api_key"
from langchain_fastocr import FastOCRLoader
documents = FastOCRLoader("scanned_contract.pdf").load()
print(documents[0].page_content)
Python 3.10 or newer. The distribution is langchain-fastocr and the import is langchain_fastocr.
What you get back
FastOCRLoader returns one Document per file.
| You get | Where |
|---|---|
| The text of the whole file | page_content |
| The file's path and name | metadata["source"], metadata["file_name"] |
| The FastOCR document id | metadata["fastocr_document_id"] |
| Pages billed | metadata["pages_billed"] |
completed or partial |
metadata["status"] |
A searchable PDF, with output="pdf" |
saved as <name>.searchable.pdf beside the input; its path is in metadata["searchable_pdf_path"] |
If the account runs out of pages partway through a file, you still get the text of the pages that were processed, with status set to partial and a warning in the log. A document that fails raises the error from fastocr-sdk with its message and code.
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.
Get an API key and pages
Any signed-in FastOCR account can create an API key and start right away.
- Sign in and create an API key in the developer console. You accept the API terms with your first key.
- Set the key as
FASTOCR_API_KEY, or passapi_key=to the loader. - When you need more than the free pages, buy a Page Pack on the pricing page. Packs work on the website and in the API.
Every account gets 50 free pages a month, shared with PDFs on the website. An image sent to the API is one page.
Examples
RAG over scanned PDFs
from langchain_core.vectorstores import InMemoryVectorStore
from langchain_fastocr import FastOCRLoader
from langchain_openai import OpenAIEmbeddings
from langchain_text_splitters import RecursiveCharacterTextSplitter
documents = FastOCRLoader("scanned_contract.pdf").load()
chunks = RecursiveCharacterTextSplitter(chunk_size=1000, chunk_overlap=150).split_documents(documents)
store = InMemoryVectorStore.from_documents(chunks, OpenAIEmbeddings())
for hit in store.as_retriever(search_kwargs={"k": 3}).invoke("When can the contract be terminated?"):
print(hit.metadata["file_name"], hit.page_content[:200])
Each chunk keeps its file's metadata, so answers can cite the source file. This example also needs pip install langchain-openai langchain-text-splitters numpy and an OpenAI key; any other embeddings class works the same way.
A folder of scans
from pathlib import Path
from langchain_fastocr import FastOCRLoader
scans = sorted(p for p in Path("scans").iterdir() if p.suffix.lower() in {".pdf", ".png", ".jpg", ".jpeg"})
for document in FastOCRLoader(scans).lazy_load():
print(document.metadata["file_name"], document.metadata["pages_billed"])
lazy_load() yields each document as soon as its file is finished. The loader runs one file at a time.
Searchable PDFs for an archive
from langchain_fastocr import FastOCRLoader
documents = FastOCRLoader(["invoice-001.pdf", "invoice-002.pdf"], output="pdf").load()
for document in documents:
print(document.metadata["searchable_pdf_path"])
Each searchable PDF is saved beside its input, as invoice-001.searchable.pdf. An existing file with that name is replaced. Index the text and keep the PDF.
Options
| Argument | Default | Meaning |
|---|---|---|
file_path |
required | One path or a list of paths |
api_key |
FASTOCR_API_KEY |
Your FastOCR API key |
output |
"text" |
"pdf" also saves a searchable PDF beside each input |
base_url |
FASTOCR_BASE_URL, then https://api.fastocr.org |
API address |
timeout |
300.0 |
Seconds to wait for each document |
Support and license
Questions: support@fastocr.org. Bugs and requests: GitHub issues. MIT license; see LICENSE.
Metadata
Release files for langchain-fastocr 0.1.1
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 | |
|---|---|---|---|---|
| langchain_fastocr-0.1.1.tar.gz | 3.1 MB | With provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| langchain_fastocr-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 3.1 MB
Release files / langchain_fastocr-0.1.1.tar.gz
| Download URL | langchain_fastocr-0.1.1.tar.gz |
|---|---|
| Size | 3.1 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8b6c56b8ae8329780ff967c0121dac342cd815944a16466f112ef8aabdceeaea
|
|
BLAKE2b-256 checksum How to use checksums |
9c69f5db0405660dc3890a01ed2521188f914a375522fd824c72c60fab974298
|
| 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 / langchain_fastocr-0.1.1-py3-none-any.whl
| Download URL | langchain_fastocr-0.1.1-py3-none-any.whl |
|---|---|
| Size | 6.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
225f9b615ba95d6f250dd9baebe96fcc1dd14d3736b581cb08abf4c7ca023be8
|
|
BLAKE2b-256 checksum How to use checksums |
855eab5d1cab8ccd33eac126ab2db9a1478044ddcec9d5b7ea57c1250bd4d2ac
|
| 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 langchain-fastocr 0.1.1
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 langchain_fastocr-0.1.1.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.