Skip to content

Mellow-Artificial-Intelligence/open-xtract

Repository files navigation

Open Xtract

PyPI version PyPI downloads Python 3.12+ CI License: MIT Pydantic v2 pydantic-ai

Extract structured data from documents, images, audio, and video using LLMs.

Installation

uv add open-xtract

Usage

from 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)

Logging

To enable logfire instrumentation for tracing:

from open_xtract import configure_logging

configure_logging()

Error Handling

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}")

Supported Media Types

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

Contributing

See CONTRIBUTING.md for development setup and guidelines.