A LlamaIndex reader that reads scanned PDFs and images with FastOCR and returns their text.
Website · Docs · Get an API key
Quickstart
pip install llama-index-readers-fastocr
export FASTOCR_API_KEY="your_api_key"
from llama_index.readers.fastocr import FastOCRReader
documents = FastOCRReader().load_data("scanned_contract.pdf")
print(documents[0].text)
Python 3.10 or newer. The distribution is llama-index-readers-fastocr and the import is llama_index.readers.fastocr.
What you get back
FastOCRReader.load_data returns one Document per file.
| You get | Where |
|---|---|
| The text of the whole file | text |
| 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"] |
The FastOCR keys (fastocr_document_id, pages_billed, status, searchable_pdf_path) are left out of the text that embedding models and LLMs see. Pass extra_info={...} to load_data to add your own metadata.
If the account runs out of API 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 reader. - When you need more than the free pages, buy a prepaid API page pack by card in the developer console.
Each account gets 50 free document pages per month.
Examples
RAG over scanned PDFs
from llama_index.core import VectorStoreIndex
from llama_index.readers.fastocr import FastOCRReader
documents = FastOCRReader().load_data("scanned_contract.pdf")
index = VectorStoreIndex.from_documents(documents)
print(index.as_query_engine().query("When can the contract be terminated?"))
This example uses LlamaIndex's default OpenAI models, so it needs OPENAI_API_KEY. Set another embedding model and LLM in Settings to use a different provider.
A folder of scans
from pathlib import Path
from llama_index.readers.fastocr import FastOCRReader
scans = sorted(p for p in Path("scans").iterdir() if p.suffix.lower() in {".pdf", ".png", ".jpg", ".jpeg"})
for document in FastOCRReader().load_data(scans):
print(document.metadata["file_name"], document.metadata["pages_billed"])
The reader runs one file at a time and returns when all files are done.
Use it with SimpleDirectoryReader
from llama_index.core import SimpleDirectoryReader
from llama_index.readers.fastocr import FastOCRReader
documents = SimpleDirectoryReader(
"scans",
file_extractor={".pdf": FastOCRReader(), ".png": FastOCRReader(), ".jpg": FastOCRReader()},
).load_data()
Searchable PDFs for an archive
from llama_index.readers.fastocr import FastOCRReader
documents = FastOCRReader(output="pdf").load_data(["invoice-001.pdf", "invoice-002.pdf"])
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 |
|---|---|---|
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 |
load_data(file_path, extra_info=None) takes one path or a list of paths.
Support and license
Questions: support@fastocr.org. Bugs and requests: GitHub issues. MIT license; see LICENSE.
Metadata
Release files for llama-index-readers-fastocr 0.1.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 | |
|---|---|---|---|---|
| llama_index_readers_fastocr-0.1.0.tar.gz | 3.1 MB | With provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| llama_index_readers_fastocr-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 3.1 MB
Release files / llama_index_readers_fastocr-0.1.0.tar.gz
| Download URL | llama_index_readers_fastocr-0.1.0.tar.gz |
|---|---|
| Size | 3.1 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
457d1921bb2fe01e41f7be208f0447192193cf7ecfb3238f9bfd5a2238c92c04
|
|
BLAKE2b-256 checksum How to use checksums |
2328e041044ed959fe7ca9a589c25c8d16a5adf1107f39852d87733fd4e88f7d
|
| 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 / llama_index_readers_fastocr-0.1.0-py3-none-any.whl
| Download URL | llama_index_readers_fastocr-0.1.0-py3-none-any.whl |
|---|---|
| Size | 7.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f793ccbb4e3abe0324950c22be8e9ee47a1f0d3cb5fe546c106b0cd4c798e7b1
|
|
BLAKE2b-256 checksum How to use checksums |
eb71976c097d23ee0810224e08e8af220a83f0eee5f18d28462c50b3805205aa
|
| 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 llama-index-readers-fastocr 0.1.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 llama_index_readers_fastocr-0.1.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.