Skip to main content

Official SDKs

We maintain official SDKs for the most popular languages.

JavaScript / TypeScript

Installation

npm install parsefy zod

Requirements

  • Node.js 18+
  • Zod 3.x

Quick example

import { Parsefy } from 'parsefy';
import * as z from 'zod';

const client = new Parsefy();

const schema = z.object({
  // REQUIRED - triggers fallback if below confidence threshold
  invoice_number: z.string().describe('The invoice number'),
  total: z.number().describe('Total amount including tax'),

  // OPTIONAL - won't trigger fallback if missing
  vendor: z.string().optional().describe('Vendor name'),
  due_date: z.string().optional().describe('Payment due date'),
});

const { object, metadata, verification, error } = await client.extract({
  file: './invoice.pdf',
  schema,
  confidenceThreshold: 0.85,
  enableVerification: true, // Enable math verification
});

if (!error && object) {
  console.log(object.invoice_number); // Fully typed!
  
  // Access field-level confidence from _meta
  console.log(`Overall confidence: ${object._meta.confidence_score}`);
  object._meta.field_confidence.forEach((fc) => {
    console.log(`${fc.field}: ${fc.score} (${fc.reason}) - "${fc.text}"`);
  });

  // Check verification results
  if (verification) {
    console.log(`Verification: ${verification.status}`);
  }
}
All fields are required by default. Mark fields as .optional() if they might be missing in >20% of your documents to avoid triggering the expensive fallback model.

Python

Installation

pip install parsefy

Requirements

  • Python 3.10+
  • Pydantic 2.0+

Quick example

from parsefy import Parsefy
from pydantic import BaseModel, Field

client = Parsefy()

class Invoice(BaseModel):
    # REQUIRED - triggers fallback if below confidence threshold
    invoice_number: str = Field(description="The invoice number")
    total: float = Field(description="Total amount including tax")

    # OPTIONAL - won't trigger fallback if missing
    vendor: str | None = Field(default=None, description="Vendor name")
    due_date: str | None = Field(default=None, description="Payment due date")

result = client.extract(
    file="invoice.pdf",
    schema=Invoice,
    confidence_threshold=0.85,
    enable_verification=True  # Enable math verification
)

if result.error is None:
    print(result.data.invoice_number)  # Fully typed!
    
    # Access field-level confidence from meta
    if result.meta:
        print(f"Overall confidence: {result.meta.confidence_score}")
        for fc in result.meta.field_confidence:
            print(f"{fc.field}: {fc.score} ({fc.reason}) - '{fc.text}'")
    
    # Check verification results
    if result.verification:
        print(f"Verification: {result.verification.status}")
All fields are required by default. Mark fields as str | None = Field(default=None, ...) if they might be missing in >20% of your documents to avoid triggering the expensive fallback model.

Community SDKs

We welcome community contributions! If you’ve built an SDK for another language, let us know.

Building your own SDK

The Parsefy API is a simple REST API. Key endpoints:
MethodEndpointDescription
POST/v1/extractExtract data from documents
GET/healthHealth check
See the API Reference for full documentation.

SDK requirements

If you’re building an SDK, we recommend:
  • Authentication: Support PARSEFY_API_KEY environment variable
  • File handling: Accept file paths, bytes, and file objects
  • Type safety: Use native schema libraries (Zod, Pydantic, etc.)
  • Confidence threshold: Support confidence_threshold parameter (default: 0.85)
  • Math verification: Support enable_verification parameter (default: false)
  • Field confidence: Parse _meta.field_confidence array from object response
  • Verification: Parse verification object from response when enabled
  • Error handling: Distinguish HTTP errors from extraction errors
  • Retries: Implement exponential backoff for rate limits

Support

Need help with an SDK?