Skip to content

Batch Extraction Examples

These examples are derived directly from alef’s cross-language fixture corpus and are kept in sync with the generated snippet tree automatically — no per-language import list to maintain.

Extract multiple in-memory documents in one batch.

Python
import asyncio
from pathlib import Path
from xberg import extract_batch
async def main() -> None:
inputs = [{"bytes": [72, 101, 108, 108, 111, 44, 32, 119, 111, 114, 108, 100, 33], "kind": "bytes", "mime_type": "text/plain"}, {"bytes": "html/html.html", "kind": "bytes", "mime_type": "text/html"}]
result = await extract_batch(inputs)
print(result.results)
asyncio.run(main())

Batch-extract with an unsupported MIME type

Section titled “Batch-extract with an unsupported MIME type”

extract_batch with unsupported bytes MIME type

Python
import asyncio
from xberg import extract_batch
async def main() -> None:
inputs = [{"bytes": [100, 97, 116, 97], "kind": "bytes", "mime_type": "application/x-unknown"}]
result = await extract_batch(inputs)
print(result)
asyncio.run(main())

Each input can override the batch’s use_layout_for_markdown setting. An omitted option inherits the batch setting, and explicit false disables it for that input. In REST /extract requests and MCP extract_batch calls, set the option alongside uri in each input object. In the CLI, set it alongside other per-file overrides in the --file-configs JSON map.

Swift takes the inputs as a JSON array:

import Xberg
let inputs = """
[
{"input":{"kind":"uri","uri":"invoice.pdf"},"use_layout_for_markdown":true},
{"input":{"kind":"uri","uri":"notes.pdf"},"use_layout_for_markdown":false}
]
"""
let result = try await extractBatchWithInputOptionsJson(inputs, "{}")