Python client for Fillbert document processing service
Project description
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 .
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fillbert_client-0.1.0.tar.gz.
File metadata
- Download URL: fillbert_client-0.1.0.tar.gz
- Upload date:
- Size: 67.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dde80143985c4221fa1316b1b85aa19fa91d520037b94f6b309abc7c6d06c490
|
|
| MD5 |
c216d1a89e69e3ad5510f9f3aefc1898
|
|
| BLAKE2b-256 |
cedca59418ebd5550abd41e969124d026d863e52c507e1e542fde9388725647d
|
File details
Details for the file fillbert_client-0.1.0-py3-none-any.whl.
File metadata
- Download URL: fillbert_client-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8d25cf829714a2ceb2ae4ba1480e2de7e36cc78ae7df97279ff575cf527146aa
|
|
| MD5 |
d6a3b90b683e2dc8634661c79e660629
|
|
| BLAKE2b-256 |
5ae2dd64a31df96106cd5553510df60ae72d29331a22d27a0e83abb5cc076234
|