Format parsers
parse_pdf, parse_docx, parse_pptx, and parse_html are format-specific variants of parse_document. They accept the same parameters and return the same ParseResult.
Use them when you want parsing to fail immediately if the file doesn't match the expected format. In all other cases, parse_document is simpler.
Signatures
docslicer.parse_pdf(source, **kwargs) -> ParseResult
docslicer.parse_docx(source, **kwargs) -> ParseResult
docslicer.parse_pptx(source, **kwargs) -> ParseResult
docslicer.parse_html(source, source_url=None, **kwargs) -> ParseResultAll **kwargs are identical to the parameters on parse_document.
What source accepts
| Function | Accepted sources |
|---|---|
parse_pdf | File path, raw PDF bytes, file-like object |
parse_docx | File path, raw DOCX bytes, file-like object |
parse_pptx | File path, raw PPTX bytes, file-like object |
parse_html | URL, file path, raw HTML string, file-like object |
parse_html also accepts a source_url keyword argument (original URL of the page, used for link normalisation when source is a file path or raw HTML string).
Example
# Raises immediately if the bytes aren't a valid PDF
with open(upload_path, "rb") as f:
result = docslicer.parse_pdf(f)