Skip to main content

Installation

pip install parsefy
  • parsefy: Parsefy SDK for document extraction (includes Pydantic)

Setup

Set your API key as an environment variable:
export PARSEFY_API_KEY=pk_your_api_key

Extract your first document

from parsefy import Parsefy
from pydantic import BaseModel, Field

client = Parsefy()

class Invoice(BaseModel):
    invoice_number: str = Field(description="The invoice number")
    date: str = Field(description="Invoice date")
    total: float = Field(description="Total amount")
    vendor: str = Field(description="Vendor name")

result = client.extract(file="invoice.pdf", schema=Invoice)

if result.error is None:
    print(f"Invoice #{result.data.invoice_number}")
    print(f"Total: ${result.data.total}")

Async usage

import asyncio
from parsefy import Parsefy
from pydantic import BaseModel, Field

class Invoice(BaseModel):
    invoice_number: str = Field(description="The invoice number")
    total: float = Field(description="Total amount")

async def main():
    async with Parsefy() as client:
        result = await client.extract_async(
            file="invoice.pdf",
            schema=Invoice
        )
        if result.error is None:
            print(result.data)

asyncio.run(main())

Next steps