Skip to main content

openextract

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

PyPI version Python versions License: MIT CI

Website · PyPI · Changelog

One function: give it a Pydantic schema, a model, and a file. You get back a validated instance.

from pydantic import BaseModel
from openextract import extract


class Invoice(BaseModel):
    vendor: str
    total: float
    currency: str


invoice = extract(Invoice, "openai:gpt-5", "invoice.pdf")
print(invoice.total)

Install

pip install 'openextract[all]'   # or just your provider: [openai], [anthropic], [google], ...

Requires Python 3.12+. Set the API key your provider expects, such as OPENAI_API_KEY.

Usage

extract(schema, model, source, instructions=None, *, media_type=None)
await extract_async(schema, model, source, instructions=None, *, media_type=None)
  • source is a file path, a pathlib.Path, an http(s):// URL, or raw bytes.
  • model is any pydantic-ai model string ("anthropic:claude-sonnet-5", "google-gla:gemini-2.5-pro", "ollama:llama3", ...) or a configured pydantic-ai Model.
  • instructions are optional extra guidance for the model.
  • media_type is inferred for you. openextract checks the file extension, then the URL's Content-Type, then the file's leading bytes (PDF, PNG, JPEG, GIF, WebP, MP3, WAV, FLAC, OGG, MP4, UTF-8 text). Pass it only to override the result.
extract(Invoice, "anthropic:claude-sonnet-5", "https://example.com/invoice.pdf")
extract(Invoice, "openai:gpt-5", scanned_page_bytes, "Amounts are in EUR.")

Errors

Every error subclasses ExtractionError and keeps the original exception as __cause__.

Exception Raised when
ModelError The provider returns an error.
SchemaValidationError The model's output doesn't match the schema.
ProviderNotInstalledError The provider's SDK isn't installed.
ExtractionError A URL can't be fetched.

If openextract can't infer the media type, it raises a ValueError and asks you to pass media_type.

License

MIT

Metadata

Release files for openextract 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for openextract 1.0.0
File Size Uploaded
openextract-1.0.0.tar.gz 167.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for openextract 1.0.0
File Interpreter ABI Platform
openextract-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 174.6 kB

Release files / openextract-1.0.0.tar.gz

Download URL openextract-1.0.0.tar.gz
Size 167.9 kB
Tags Source
SHA-256 checksum
How to use checksums
ece22b7a768ddccba79962b63cb7568905701ee2697b1b526e83257c9abbe077
BLAKE2b-256 checksum
How to use checksums
30078c22ba36a07d2f6319e6e510ea81697cfb710f2bf98e1bb0879efb5a3af9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 22, 2026.

Transparency log

Release files / openextract-1.0.0-py3-none-any.whl

Download URL openextract-1.0.0-py3-none-any.whl
Size 6.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8de5a9750e8d18abc4f8a40e4c850088ffeb75257016d687ac3a94652c4acf1e
BLAKE2b-256 checksum
How to use checksums
cf3c8018ee76fd31baf945a37dc0f0409018d9b44ed75178767e1916cdb49afc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 22, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

0.15.0

2 release files

0.14.0

2 release files

0.13.1

2 release files

0.11.0

2 release files

0.9.0

2 release files

0.8.0

2 release files

0.7.0

2 release files

0.6.0

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page