Skip to main content

langchain-pdfluent

A LangChain document loader for PDFluent. It reads a PDF with PDFluent's structured extraction and hands LangChain Documents in reading order, with the page and box each came from in its metadata so an answer can cite its source. Everything runs locally. Your documents stay on your machine.

Install

pip install langchain-pdfluent

It needs Python 3.9 or later and pdfluent 1.2.0 or later, which pip pulls in automatically. It also depends on langchain-core (MIT).

Quick start

from langchain_pdfluent import PDFluentLoader

docs = PDFluentLoader("report.pdf").load()
print(docs[0].page_content, docs[0].metadata["page"])

A runnable notebook, load and split, is in examples/load_and_split.ipynb.

Modes

mode decides what one Document is.

Blocks mode

One document per paragraph, heading, list item or table (a table is one document), in reading order. This is the default.

from langchain_pdfluent import PDFluentLoader

loader = PDFluentLoader("report.pdf")
for doc in loader.lazy_load():
    print(doc.metadata["kind"], doc.metadata["page"], doc.metadata["bbox"])

Markdown mode

One document per page, as markdown. Pass quality="balanced" for the layout-model tier (see below).

from langchain_pdfluent import PDFluentLoader

pages = PDFluentLoader("report.pdf", mode="markdown").load()
print(len(pages), "pages")
print(pages[0].page_content[:200])

Document mode

One document for the whole selection: the markdown of every selected page, joined by a blank line. metadata["pages"] lists the pages it covers.

from langchain_pdfluent import PDFluentLoader

whole = PDFluentLoader("report.pdf", mode="document", pages=[0, 2]).load()
print(whole[0].metadata["pages"])

Quality and pages

quality is "fast" (default) or "balanced", the layout-model tier of pdfluent 1.2. The balanced tier assembles markdown, so it goes with mode="markdown" or mode="document"; with mode="blocks" the engine refuses it and says so. It needs the model weights, installed once with the pdfluent command-line tool:

pdfluent models install layout tables
from langchain_pdfluent import PDFluentLoader

PDFluentLoader("report.pdf", mode="markdown", quality="balanced").load()

pages=[0, 3] loads exactly those pages (0-based); first_page and page_count load a window.

Options

Argument Default What it does
mode "blocks" "blocks", "markdown" (one document per page) or "document" (one document).
quality "fast" "fast" or "balanced" (markdown and document modes).
model_dir None Where the balanced tier finds its weights; None uses PDFLUENT_MODEL_DIR or the per-user model directory.
table_model_dir None Directory of the table-structure model; opts the balanced tier's tables into it.
include_furniture False Keep the running heads and page numbers a document repeats on every page.
first_page, page_count 0, None Load a window of pages.
pages None Load exactly these 0-based pages instead of the window.
hierarchical, max_chars False, 2000 Add section_path and split long tables by rows.

Metadata

Key Value
source the path the PDF was loaded from
page 0-based page index (blocks and markdown modes)
pages the 0-based pages a document covers (document mode)
kind paragraph, heading, list_item, table, header, footer; page in markdown mode; document in document mode
bbox [x0, y0, x1, y1] in points, origin at the bottom left of the page, y up (blocks mode)
confidence the learned model's probability for kind, only where a model decided it
section the last heading above the chunk
section_path the enclosing headings (hierarchical=True)
level a heading's level, 1 to 3
continues_previous True on the second half of a paragraph a page break cut in two
toc_items the outline entries pointing at the page, as [level, title, page] triples (markdown and document modes)
tables one {"bbox", "rows", "columns"} per table on the page (markdown mode)

bbox, toc_items and tables are lists. A vector store that only accepts scalar metadata, such as Chroma, needs filter_complex_metadata from langchain_community over the documents first.

Benchmarks

Extraction quality is measured in the public pdfluent-bench repository (link follows when it is public).

Licence

AGPL-3.0 or a commercial licence, at your option; see LICENSE and LICENSE-COMMERCIAL. The commercial licence is sold yearly and self-service at https://pdfluent.com/sdk/pricing.

Metadata

Release files for langchain-pdfluent 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for langchain-pdfluent 0.2.0
File Size Uploaded Provenance
langchain_pdfluent-0.2.0.tar.gz 25.9 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for langchain-pdfluent 0.2.0
File Interpreter ABI Platform
langchain_pdfluent-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 48.0 kB

Release files / langchain_pdfluent-0.2.0.tar.gz

Download URL langchain_pdfluent-0.2.0.tar.gz
Size 25.9 kB
Tags Source
SHA-256 checksum
How to use checksums
fca622d751d5210dd363a50aeb3b1ca6b0dc29e9bec0f4cb2b7478fbe9546bc8
BLAKE2b-256 checksum
How to use checksums
079ed96d8893169463d37dc34bb321472191d1be6420f4a1abf997b211f9344d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.10

Release files / langchain_pdfluent-0.2.0-py3-none-any.whl

Download URL langchain_pdfluent-0.2.0-py3-none-any.whl
Size 22.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
acd030d665416d21a8b90f48ca42eaeda183c02a541ecffdc349ed892ec3c955
BLAKE2b-256 checksum
How to use checksums
140182df2fc27714051e9ab1a7a59e4cb8e52b2e57b2517af037ea2c3726da3a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.10

Security for langchain-pdfluent 0.2.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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A 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.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page