You do not need to run the FastAPI server to use RAG PDF Highlighter. The package exposes its core utilities as importable functions, so you can embed PDF highlighting directly inside any Python application — a script, a Jupyter notebook, or a larger service — without spinning up a separate process.
Install the Package
Python 3.10 or later is required.
Complete Workflow Example
The snippet below shows the full end-to-end flow: download a PDF, apply highlights, read the result into memory, and clean up the temporary files.
Always call cleanup_file() in a finally block for both pdf_path and output_path. Both functions write to temporary files on disk. If your code raises an exception before cleanup runs, those files will accumulate and consume disk space. The finally pattern above guarantees cleanup regardless of whether an error occurs.
Error Handling
Import the exception classes to handle specific failure modes gracefully.
The exception hierarchy is:
download_pdf is an async function and must be called with await. highlight_chunks_in_pdf is a regular synchronous function — call it directly without await. If you are calling from synchronous code, wrap the async parts with asyncio.run() as shown in the example above. If you are already inside an async context (e.g., a FastAPI route or an async test), use await for download_pdf directly.