Document Service (Docling)#
- class saia_python.documents.DocumentService(session: requests.Session, base_url: str, *, retry: RetryPolicy | bool | None = None)[source]#
Access the
/documents/convertendpoint (Docling).Converts PDF and other document formats to markdown, HTML, JSON, or token representations.
- Parameters:
session – A
requests.Sessionwith auth headers configured.base_url – The SAIA API base URL.
- convert(file_path: str | Path, *, response_type: str = 'markdown', extract_tables_as_images: bool | None = None, image_resolution_scale: int | None = None, retry: RetryPolicy | bool | None = None) ConversionResult[source]#
Convert a document using the Docling service.
- Parameters:
file_path – Path to the document file (PDF, etc.).
response_type – Output format —
"markdown"(default),"html","json", or"tokens".extract_tables_as_images – If
True, render tables as images instead of structured text.image_resolution_scale – Image quality multiplier (1–4).
- Returns:
A
ConversionResultwith the converted content and any extracted images.
- class saia_python.documents.ConversionResult(filename: str, response_type: str, content: str, images: list[ConversionImage] = <factory>)[source]#
Result of a document conversion via the Docling service.
- Variables:
filename (str) – The original document filename.
response_type (str) – The output format (
markdown,html,json, ortokens).content (str) – The converted content as a string.
images (list[saia_python.documents.ConversionImage]) – The extracted images as
ConversionImageobjects (decodedbytes+filename). Usesave_images()orsave_all()to write them to disk.
- save(path: str | Path) Path[source]#
Save the converted content to a file.
- Parameters:
path – Output file path.
- Returns:
The path written to.
- save_images(directory: str | Path) list[Path][source]#
Write every extracted image into
directory.Each
ConversionImageis written under itsfilename; decoding already happened at parse time.- Parameters:
directory – Target directory (created if missing).
- Returns:
The list of written image paths (empty if there are no images).
- save_all(directory: str | Path, *, stem: str | None = None) list[Path][source]#
Save the content file and all images into
directory.The content is written as
<stem>.<ext>whereextis inferred fromresponse_type(markdown→md) andstemdefaults to the sourcefilenamestem. Images are written viasave_images(), so anypicture-N.pnglinks in the content resolve next to it.- Parameters:
directory – Target directory (created if missing).
stem – Optional base name for the content file.
- Returns:
All written paths, content file first.