Skip to main content

Python client SDK for Clox Document Processing API

Project description

Clox Client SDK

PyPI version Python 3.10+ License: MIT

Official Python client SDK for the Clox Document Processing API.

Features

  • 🔐 Simple API key authentication
  • 📄 Document processing (PDF, images)
  • 📦 Batch operations
  • 📊 Dashboard statistics
  • 🔄 Automatic retries and error handling
  • 🎯 Type hints and comprehensive documentation
  • ⚡ Async-ready with requests session

Installation

pip install clox-client

Quick Start

from clox_client import Clox

# Initialize with your API key
client = Clox(
    api_url="https://api.clox.ai",
    api_key="your_api_key"
)

# Process a document
result = client.process_document("invoice.pdf")
print(f"Document ID: {result['document_id']}")
print(f"Is Fraud: {result.get('is_fraud')}")

Configuration

Using API Key Directly

from clox_client import Clox

client = Clox(
    api_url="https://api.clox.ai",
    api_key="clox_your_api_key_here"
)

Using Environment Variables (Recommended)

export CLOX_API_URL="https://api.clox.ai"
export CLOX_API_KEY="clox_your_api_key_here"
from clox_client import Clox

# Client reads from environment automatically
client = Clox()
result = client.process_document("invoice.pdf")

Usage Examples

Process a Single Document

# Process PDF
result = client.process_document("invoice.pdf")

# Process image
result = client.process_document("receipt.jpg")

# Process file-like object
with open("document.pdf", "rb") as f:
    result = client.process_document(f, filename="document.pdf")

# Access results
print(f"Document ID: {result['document_id']}")
print(f"Is Fraud: {result.get('is_fraud')}")

Batch Processing

# Process multiple documents in a single request
batch_result = client.process_documents(files=["doc1.pdf", "doc2.jpg"])  # returns { batch_id, ... }
batch_id = batch_result["batch_id"]

# Get batch details
details = client.get_batch_details(batch_id)
print(f"Batch ID: {batch_id}")
print(f"Num Documents: {len(details.get('documents', []))}")

# List recent batch requests
batch_requests = client.get_batch_requests(page=1, limit=10)
print(batch_requests.get("batches"))

Get Dashboard Statistics

stats = client.get_dashboard_stats()
print(f"Total Documents: {stats['total_documents']}")
print(f"Documents Today: {stats['documents_today']}")

List Documents

# List all documents
docs = client.list_documents(page=1, limit=20)

# Filter by batch_id
docs_in_batch = client.list_documents(page=1, limit=20, batch_id="your_batch_id")

Health Check

health = client.health_check()
print(f"API Status: {health['status']}")

API Methods

Method Description
process_document(file) Process a single document (path or file-like)
process_documents(files) Process multiple documents in one request
get_document(document_id) Download the original/processed document bytes
get_annotated_document(document_id) Download annotated document bytes
list_documents(page=1, limit=10, batch_id=None) List documents with pagination
get_batch_requests(page=1, limit=10) List recent batch requests
get_batch_details(batch_id) Get detailed batch info
create_user(user_data) Create a new user
list_users() List all users
update_user(user_id, user_data) Update user
delete_user(user_id) Delete user
get_dashboard_stats() Get statistics
health_check() Check API health

Error Handling

from clox_client import Clox, CloxException, CloxAuthenticationError, CloxAPIError

try:
    client = Clox(api_key="your_api_key")
    result = client.process_document("invoice.pdf")

except CloxAuthenticationError as e:
    print(f"Authentication failed: {e}")

except CloxAPIError as e:
    print(f"API error: {e}")

except CloxException as e:
    print(f"Client error: {e}")

Advanced Usage

Context Manager

with Clox(api_key="your_api_key") as client:
    result = client.process_document("invoice.pdf")
    print(result)
# Session automatically closed

Custom Timeout and Retries

client = Clox(
    api_key="your_api_key",
    timeout=60,  # 60 seconds timeout
    max_retries=5  # Retry up to 5 times
)

Process Multiple Files in Parallel

from concurrent.futures import ThreadPoolExecutor

files = ["doc1.pdf", "doc2.pdf", "doc3.pdf"]

def process_file(file_path):
    return client.process_document(file_path)

with ThreadPoolExecutor(max_workers=5) as executor:
    results = list(executor.map(process_file, files))

Requirements

  • Python 3.10 or higher
  • requests library (installed automatically)

Get Your API Key

To use the Clox Client SDK, you need an API key:

  1. Sign up at https://clox.ai
  2. Go to your dashboard
  3. Generate an API key
  4. Copy your key (starts with clox_)

Security

  • ✅ Always use environment variables for API keys
  • ✅ Never commit API keys to version control
  • ✅ Rotate keys regularly
  • ✅ Use different keys for dev/staging/production

Support

License

This project is licensed under the MIT License - see the LICENSE file for details.

Links


Made with ❤️ by the Clox Team

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

clox_client-1.0.0.tar.gz (10.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

clox_client-1.0.0-py3-none-any.whl (8.5 kB view details)

Uploaded Python 3

File details

Details for the file clox_client-1.0.0.tar.gz.

File metadata

  • Download URL: clox_client-1.0.0.tar.gz
  • Upload date:
  • Size: 10.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for clox_client-1.0.0.tar.gz
Algorithm Hash digest
SHA256 fdf95b0f36714684f5fd32989d41c504ae00c044d8159e1ec522ff46c0e08f82
MD5 96d197e3669ef1e71bb67a60d4024266
BLAKE2b-256 dd6138788f50cf13e137eedfd9157303e0175502a133ae5cdf061542c2095bd6

See more details on using hashes here.

File details

Details for the file clox_client-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: clox_client-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 8.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for clox_client-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d732f606521723619646c58fde9736ae05a76fa4e5585b0bfb1879711be2c585
MD5 4d682e7e3f016339832d3170b4eb38cd
BLAKE2b-256 e1a423f3f6f32ea31ae4faeb0c756689fd5890b5ea8a9e589d2049afc8bd6575

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page