Extract structured data from documents, images, audio, and video using LLMs.
uv add open-xtractfrom pydantic import BaseModel
from open_xtract import extract
class PdfInfo(BaseModel):
summary: str
language: str
result = extract(
schema=PdfInfo,
model="google-gla:gemini-3-flash-preview",
url="https://example.com/document.pdf",
instructions="return a 2 sentence summary and the primary language of the document",
)
print(result)To enable logfire instrumentation for tracing:
from open_xtract import configure_logging
configure_logging()from open_xtract import (
extract,
ExtractionError,
ModelError,
SchemaValidationError,
UrlFetchError,
)
try:
result = extract(...)
except UrlFetchError as e:
print(f"Failed to fetch URL: {e}")
except SchemaValidationError as e:
print(f"Output didn't match schema: {e}")
except ModelError as e:
print(f"Model API error: {e}")
except ExtractionError as e:
print(f"Extraction failed: {e}")| Type | Extensions |
|---|---|
| Documents | .pdf, .doc, .docx, .txt, .html, .csv, .xls, .xlsx |
| Images | .jpg, .jpeg, .png, .gif, .webp, .bmp, .svg |
| Audio | .mp3, .wav, .ogg, .flac, .aac, .m4a |
| Video | .mp4, .mov, .avi, .mkv, .webm, .wmv |
See CONTRIBUTING.md for development setup and guidelines.