Skip to main content

LangChain document loader for Xberg — extract 88+ file formats into Documents with async, batching, chunking, and rich metadata

Project description

Xberg

langchain-xberg

A LangChain document loader backed by Xberg. XbergLoader extracts text and metadata from 88+ formats — running OCR where needed — and returns LangChain Document objects. Extraction is async at the core; multiple sources go through Xberg's extract_batch in a single native call, so concurrency happens Rust-side.

Install

pip install langchain-xberg

Requires Python 3.10+.

Load

Pass a path, a list of paths, a directory, or raw bytes. One source becomes one Document.

from langchain_xberg import XbergLoader

# Single file
docs = XbergLoader(file_path="report.pdf").load()
print(docs[0].page_content)           # extracted markdown
print(docs[0].metadata["title"])      # source, mime_type, title, authors, detected_languages, page_count, ...

# Multiple files — one batched extraction
docs = XbergLoader(file_path=["report.pdf", "notes.docx"]).load()

# A directory with a glob
docs = XbergLoader(file_path="./corpus/", glob="**/*.pdf").load()

# Raw bytes (mime_type required)
docs = XbergLoader(data=raw_bytes, mime_type="application/pdf").load()

Chunk for retrieval

Enable Xberg's native chunking to emit one Document per chunk, sized for embedding. Each chunk carries chunk_index, total_chunks, heading_path, page, and token_count in its metadata.

from langchain_xberg import XbergLoader
from xberg import ChunkingConfig, ExtractionConfig

config = ExtractionConfig(chunking=ChunkingConfig(max_characters=1000, overlap=200))
docs = XbergLoader(file_path="report.pdf", config=config).load()  # one Document per chunk

To split by page instead, pass pages=PageConfig(extract_pages=True); each Document then gets a 0-indexed page.

Configure extraction

Pass any Xberg ExtractionConfig to control OCR, output format, and batch concurrency.

from xberg import ExtractionConfig, OcrConfig

config = ExtractionConfig(
    output_format="markdown",
    ocr=OcrConfig(backend="tesseract"),
    force_ocr=True,
    max_concurrent_extractions=8,
)
docs = XbergLoader(file_path="./corpus/", config=config).load()

Async

Inside an event loop, use the async API — await loader.aload() or async for doc in loader.alazy_load(). These use Xberg's native async extraction end to end. The synchronous load / lazy_load bridge to it and must not run inside a running loop.

loader = XbergLoader(file_path="report.pdf")
docs = await loader.aload()

Errors

A per-input failure raises xberg.XbergError with the offending source and message. In batch mode the failure comes from ExtractionResult.errors; a single load surfaces the raised exception directly.

For the full API, see the Xberg documentation.

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_xberg-1.0.0rc41.tar.gz (11.5 kB view details)

Uploaded Source

Built Distribution

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

langchain_xberg-1.0.0rc41-py3-none-any.whl (8.8 kB view details)

Uploaded Python 3

File details

Details for the file langchain_xberg-1.0.0rc41.tar.gz.

File metadata

  • Download URL: langchain_xberg-1.0.0rc41.tar.gz
  • Upload date:
  • Size: 11.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.32 {"installer":{"name":"uv","version":"0.11.32","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for langchain_xberg-1.0.0rc41.tar.gz
Algorithm Hash digest
SHA256 df6bed8318251e2a9124c2f4471863d82ed6c0ce8a6e236b6aeeb1d399fa49a2
MD5 d1983c5754e80b63a5cba1612be75a13
BLAKE2b-256 cdd2a4fc824523b6239b3595d60bebab26ace5907b1313a648da964ba77839cc

See more details on using hashes here.

File details

Details for the file langchain_xberg-1.0.0rc41-py3-none-any.whl.

File metadata

  • Download URL: langchain_xberg-1.0.0rc41-py3-none-any.whl
  • Upload date:
  • Size: 8.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.32 {"installer":{"name":"uv","version":"0.11.32","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for langchain_xberg-1.0.0rc41-py3-none-any.whl
Algorithm Hash digest
SHA256 cf766cc457541a780141410ac65fd7c192b44a034d312086f27d3f4936ec9469
MD5 0d0c74b826f034f9f776fe0f1691a9aa
BLAKE2b-256 5c3f930ef215a07d92e02d7d671e541e3b2cbee4d24a81721bc0b0fff6f19c73

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