Skip to main content

Fillbert Client

Python client library for the Fillbert document processing service.

Installation

# Basic installation
pip install fillbert-client

# With FastAPI webhook support
pip install fillbert-client[fastapi]

Basic Usage

import asyncio
from fillbert_client import FillbertClient

async def main():
    # Initialize client
    client = FillbertClient(
        base_url="https://bol-ocr.example.com",
        api_key="your-api-key"
    )

    try:
        # Process document with optional webhook
        job = await client.process_document(
            image_path="path/to/document.pdf",
            callback_url="https://your-app.com/webhooks/bol-complete",
            webhook_secret="your-webhook-secret"
        )

        print(f"Job submitted: {job.request_id}")

        # Option 1: Poll for completion
        result = await client.wait_for_completion(job.request_id)
        print(f"Processing completed: {result.extracted_data}")

        # Option 2: Check status manually
        status = await client.get_job_status(job.request_id)
        if status.status == "completed":
            result = await client.get_result(job.request_id)
            print(f"document Number: {result.extracted_data.bol_number}")
            print(f"Carrier: {result.extracted_data.carrier}")

    finally:
        await client.close()

# Run async function
asyncio.run(main())

Webhook Integration (FastAPI)

If you're using FastAPI, you can automatically handle webhooks:

from fastapi import FastAPI
from fillbert_client import create_simple_webhook_router, JobStatusEnum

app = FastAPI()

def handle_completion(payload):
    print(f"document {payload.request_id} completed!")
    print(f"Extracted data: {payload.extracted_data}")
    # Store in database, send notifications, etc.

def handle_failure(payload):
    print(f"document {payload.request_id} failed: {payload.error_message}")
    # Handle error, retry, notify user, etc.

# Create webhook router
webhook_router = create_simple_webhook_router(
    secret="your-webhook-secret",
    on_completion=handle_completion,
    on_failure=handle_failure,
)

# Mount webhook endpoints at /webhooks/bol-complete
app.include_router(webhook_router)

# Your webhook URL will be: https://your-app.com/webhooks/bol-complete

Advanced Webhook Handling

For more control over webhook handling:

from fastapi import FastAPI
from fillbert_client import create_webhook_router, JobStatusEnum

def handle_processing(payload):
    print(f"document {payload.request_id} is now processing...")

def handle_completion(payload):
    print(f"document {payload.request_id} completed!")

def handle_failure(payload):
    print(f"document {payload.request_id} failed!")

app = FastAPI()

webhook_router = create_webhook_router(
    secret="your-webhook-secret",
    path_prefix="/api/webhooks",  # Custom prefix
    endpoint_name="bol-events",   # Custom endpoint name
    handlers={
        JobStatusEnum.PROCESSING: handle_processing,
        JobStatusEnum.COMPLETED: handle_completion,
        JobStatusEnum.FAILED: handle_failure,
    }
)

app.include_router(webhook_router)
# Webhook URL: https://your-app.com/api/webhooks/bol-events

Error Handling

from fillbert_client import FillbertClient
import httpx

async def process_with_error_handling():
    client = FillbertClient(base_url="...", api_key="...")

    try:
        job = await client.process_document("document.pdf")
        result = await client.wait_for_completion(
            job.request_id,
            timeout=300  # 5 minutes
        )
        return result

    except httpx.HTTPStatusError as e:
        if e.response.status_code == 403:
            print("Callback URL not authorized for this client")
        elif e.response.status_code == 400:
            print("Invalid request - check file format and parameters")
        else:
            print(f"HTTP error: {e}")

    except TimeoutError:
        print("document processing timed out")

    except RuntimeError as e:
        print(f"Processing failed: {e}")

    finally:
        await client.close()

Development

This package is part of the document OCR Service monorepo.

# Install dev dependencies
uv sync --dev

# Run tests
uv run pytest

# Run tests with auto-watcher
uv run ptw

# Run quality checks
uv run ruff check .
uv run mypy .

Metadata

Release files for fillbert-client 0.1.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 fillbert-client 0.1.0
File Size Uploaded
fillbert_client-0.1.0.tar.gz 67.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for fillbert-client 0.1.0
File Interpreter ABI Platform
fillbert_client-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 74.8 kB

Release files / fillbert_client-0.1.0.tar.gz

Download URL fillbert_client-0.1.0.tar.gz
Size 67.4 kB
Tags Source
SHA-256 checksum
How to use checksums
dde80143985c4221fa1316b1b85aa19fa91d520037b94f6b309abc7c6d06c490
BLAKE2b-256 checksum
How to use checksums
cedca59418ebd5550abd41e969124d026d863e52c507e1e542fde9388725647d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.13

Release files / fillbert_client-0.1.0-py3-none-any.whl

Download URL fillbert_client-0.1.0-py3-none-any.whl
Size 7.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8d25cf829714a2ceb2ae4ba1480e2de7e36cc78ae7df97279ff575cf527146aa
BLAKE2b-256 checksum
How to use checksums
5ae2dd64a31df96106cd5553510df60ae72d29331a22d27a0e83abb5cc076234
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.13

Release history Release notifications | RSS feed

This release

0.1.0 This release

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