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, ExtractInput, ExtractionConfig
async def main() -> None:
inputs = [ExtractInput(bytes=[72, 101, 108, 108, 111, 44, 32, 119, 111, 114, 108, 100, 33], kind="bytes", mime_type="text/plain"), ExtractInput(bytes=Path("test_documents/html/html.html").read_bytes(), kind="bytes", mime_type="text/html")]
_ = await extract_batch(inputs, None)
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, ExtractInput, ExtractionConfig
async def main() -> None:
inputs = [ExtractInput(bytes=[100, 97, 116, 97], kind="bytes", mime_type="application/x-unknown")]
_ = await extract_batch(inputs, None)
asyncio.run(main())