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)
sourceis a file path, apathlib.Path, anhttp(s)://URL, or rawbytes.modelis any pydantic-ai model string ("anthropic:claude-sonnet-5","google-gla:gemini-2.5-pro","ollama:llama3", ...) or a configured pydantic-aiModel.instructionsare optional extra guidance for the model.media_typeis inferred for you. openextract checks the file extension, then the URL'sContent-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)
| File | Size | Uploaded | |
|---|---|---|---|
| openextract-1.0.0.tar.gz | 167.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| 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 logRelease 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