Skip to main content

An integration package connecting PyMuPDF4LLM to LangChain

Project description

langchain-pymupdf4llm

An independent LangChain integration package connecting PyMuPDF4LLM to LangChain as a document loader.

LangChain v1.0+ PyMuPDF4LLM Python 3.10+ License: AGPL-3.0-only

Introduction

langchain-pymupdf4llm integrates PyMuPDF4LLM with LangChain as a document loader. It extracts PDF content into Markdown for LLM and retrieval-augmented generation workflows.

Licensing

This package depends directly on pymupdf4llm / pymupdf, which are published by Artifex under AGPL/commercial terms. Because this integration wraps that stack directly, this repository is distributed under AGPL-3.0-only.

If you distribute software or provide a network service that uses this package, you must evaluate your own AGPL compliance obligations. If you cannot comply with the AGPL, obtain an appropriate commercial license for the PyMuPDF stack from Artifex instead of relying on this package under the AGPL.

langchain-core remains MIT-licensed and is compatible with this package's AGPL license. See NOTICE for third-party attribution details.

Features

PyMuPDF4LLM provides Markdown extraction for standard text, tables, headers, lists, code blocks, multi-column pages, images, and vector graphics.

This integration adds LangChain loader and parser APIs, including optional image description replacement when an image parser is provided.

Requirements

  • Python 3.10 or higher
  • LangChain Core v1.0.0 or higher
  • PyMuPDF4LLM v1.27.2.1 up to, but not including, v1.28.0

Installation

Install the package using pip:

pip install -U langchain-pymupdf4llm

Before installing, make sure the AGPL/commercial licensing model of the PyMuPDF stack works for your use case.

For optional image parsing capabilities, you may also want to install:

pip install langchain-community

Licensing Correction For Existing Users

Earlier releases of this package were incorrectly labeled as MIT. The package has always depended on the AGPL/commercial PyMuPDF stack, so existing users should re-evaluate whether their usage and redistribution model is compatible with that dependency chain.

Future corrective releases should:

  1. Keep the AGPL package metadata and repository license files aligned.
  2. Clearly disclose the licensing correction in release notes.
  3. Deprecate or supersede the incorrectly labeled release on package indexes where possible.

Usage

from langchain_pymupdf4llm import PyMuPDF4LLMLoader

loader = PyMuPDF4LLMLoader(
    file_path="/path/to/input.pdf",
    mode="single",
    pages_delimiter="\n\f",
    use_layout=False,
    table_strategy="lines",
)

docs = loader.load()
print(docs[0].page_content[:100])
print(docs[0].metadata)

Use lazy_load() to stream documents:

for doc in loader.lazy_load():
    print(doc.metadata)

Use the parser with LangChain blob loaders:

from langchain_community.document_loaders import FileSystemBlobLoader
from langchain_community.document_loaders.generic import GenericLoader
from langchain_pymupdf4llm import PyMuPDF4LLMParser

loader = GenericLoader(
    blob_loader=FileSystemBlobLoader(path="path/to/docs/", glob="*.pdf"),
    blob_parser=PyMuPDF4LLMParser(),
)

Development

Open the workspace in the devcontainer, then install dependencies manually:

uv sync --group dev --group test --group lint --group typing

Install lightweight pre-commit hooks for formatting and hygiene checks:

uv run pre-commit install

Common commands are available as Cursor/VS Code tasks:

  • uv sync
  • test
  • coverage
  • lint
  • format
  • typecheck
  • jupyter

JupyterLab is configured as a foreground task on port 8888. It does not start automatically when the container starts.

Run checks locally:

uv run --group test python -m pytest
uv run pytest --cov=src/langchain_pymupdf4llm --cov-report=term-missing --cov-fail-under=90
uv run black --check .
uv run ruff check .
uv run mypy .
uv run pre-commit run --all-files

The default pytest run disables sockets and skips tests marked network. To run network tests explicitly:

uv run --group test python -m pytest --force-enable-socket -m network

Creating Test Documents

To recreate the example PDF documents from LaTeX with deterministic PDF metadata:

cd ./tests/examples
SOURCE_DATE_EPOCH=1704067200 FORCE_SOURCE_DATE=1 pdflatex -interaction=nonstopmode sample_1.tex

Jupyter Notebooks

Start JupyterLab from the devcontainer:

uv run jupyter lab --ip 0.0.0.0 --port 8888 --no-browser

Contribute

Issues and pull requests are welcome on the GitHub repository.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

langchain_pymupdf4llm-1.27.2.tar.gz (326.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

langchain_pymupdf4llm-1.27.2-py3-none-any.whl (33.2 kB view details)

Uploaded Python 3

File details

Details for the file langchain_pymupdf4llm-1.27.2.tar.gz.

File metadata

  • Download URL: langchain_pymupdf4llm-1.27.2.tar.gz
  • Upload date:
  • Size: 326.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for langchain_pymupdf4llm-1.27.2.tar.gz
Algorithm Hash digest
SHA256 4b34d4541c097d06334b119b955070234875b0fdd744f8041dfe051f95d3ac30
MD5 491864e63d4db77d5d533f3ff57a2da8
BLAKE2b-256 45f3a29a315e77f2113fed286c389fb606e2e8ddf869d42b6c7b18488d15f8a1

See more details on using hashes here.

File details

Details for the file langchain_pymupdf4llm-1.27.2-py3-none-any.whl.

File metadata

File hashes

Hashes for langchain_pymupdf4llm-1.27.2-py3-none-any.whl
Algorithm Hash digest
SHA256 99956dda489b6440869220fa9028eddf18c41a81782b852d7a704229c3ae03a0
MD5 7dd638dcccb85a76198acbcf6e944005
BLAKE2b-256 863a64d3cdf829a98c6e23f43d59bfca804783dcd6c43f0809d8a8b9d313e7b6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page