Skip to main content

Official Python SDK for Kraken document processing API

Project description

Kraken SDK for Python

Official Python SDK for the Kraken document processing API.

Requirements

  • Python 3.9 or higher
  • httpx for HTTP requests
  • pydantic for data validation

Installation

pip install kraken-sdk

Or install from source:

git clone https://github.com/Capt-IA/Kraken-SDK.git
cd Kraken-SDK/kraken-sdk-python
pip install -e .

Quick Start

from kraken_sdk import KrakenClient

# Initialize the client
client = KrakenClient(
    api_key="your-api-key",
    base_url="https://api.kraken.example.com"  # Optional
)

# Check service health
health = client.info.health()
print(health.status)

# Upload a document
source = client.sources.upload("path/to/document.pdf")
print(f"Uploaded: {source.id}")

# Create an extraction job
job = client.jobs.create_single(
    task_type="extraction",
    source_id=source.id,
    ai_provider="openai",
    provider_model="gpt-4o"
)

# Wait for completion and get results
result = client.jobs.wait(job.job_id)
tasks = client.jobs.tasks(job.job_id)
print(tasks.tasks[0].result.content)

Async Support

The SDK provides full async support:

import asyncio
from kraken_sdk import AsyncKrakenClient

async def main():
    async with AsyncKrakenClient(api_key="your-api-key") as client:
        source = await client.sources.upload("document.pdf")
        job = await client.jobs.create_single(
            task_type="extraction",
            source_id=source.id,
            ai_provider="openai",
            provider_model="gpt-4o"
        )
        result = await client.jobs.wait(job.job_id)
        print(result)

asyncio.run(main())

Structured Annotation

Extract structured data using custom schemas:

from kraken_sdk import KrakenClient

client = KrakenClient(api_key="your-api-key")

annotation_schema = {
    "Invoice": {
        "general_prompt": "Invoice information",
        "is_list": False,
        "is_optional": False,
        "table_fields": [
            {"class_name": "invoice_number", "type": "str", "prompt": "The invoice number"},
            {"class_name": "total_amount", "type": "str", "prompt": "The total amount"},
            {"class_name": "date", "type": "str", "prompt": "The invoice date"}
        ]
    }
}

job = client.jobs.create_single(
    task_type="annotation",
    source_id=source.id,
    ai_provider="openai",
    provider_model="gpt-4o",
    annotation_config={
        "annotation_schema": annotation_schema,
        "output_format": "json"
    }
)

result = client.jobs.wait(job.job_id)

Bulk Processing

Process multiple documents with the same configuration:

job = client.jobs.create_bulk(
    task_config={
        "task_type": "extraction",
        "ai_provider": "openai",
        "provider_model": "gpt-4o"
    },
    source_ids=["source-1", "source-2", "source-3"]
)

Error Handling

from kraken_sdk.exceptions import (
    KrakenError,
    KrakenAuthenticationError,
    KrakenValidationError,
    KrakenNotFoundError
)

try:
    result = client.jobs.get("invalid-id")
except KrakenNotFoundError:
    print("Job not found")
except KrakenAuthenticationError:
    print("Invalid API key")
except KrakenError as e:
    print(f"API error: {e}")

API Reference

KrakenClient

Resource Methods
client.info health(), get(), tasks()
client.auth me(), users(), generate_api_key()
client.jobs create(), create_single(), create_bulk(), list(), get(), tasks(), wait()
client.sources upload()
client.provider_api_keys create(), list(), get(), update(), delete()
client.benchmarks create(), list(), get(), report()

Development

# Install dev dependencies
pip install -e ".[dev]"

# Run tests
pytest

# Lint
ruff check src/

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

kraken_captia-0.1.3.tar.gz (38.5 kB view details)

Uploaded Source

Built Distribution

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

kraken_captia-0.1.3-py3-none-any.whl (25.1 kB view details)

Uploaded Python 3

File details

Details for the file kraken_captia-0.1.3.tar.gz.

File metadata

  • Download URL: kraken_captia-0.1.3.tar.gz
  • Upload date:
  • Size: 38.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for kraken_captia-0.1.3.tar.gz
Algorithm Hash digest
SHA256 4b460a9c9b2db6f0d6d2ef1de1d3448f09794952df2cde3742845978295371e8
MD5 699b23aa62d616b656619103f4c7bb27
BLAKE2b-256 838b3fed224417dae2ad584e8033cee6a5e57730df59c6e81d59ea548b2bf5a8

See more details on using hashes here.

Provenance

The following attestation bundles were made for kraken_captia-0.1.3.tar.gz:

Publisher: publish.yml on Capt-IA/Kraken-SDK

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file kraken_captia-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: kraken_captia-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 25.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for kraken_captia-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 e3c029ecf64522ee83e5c5c55ea005cfdfce4595c3450ca7abeb750777a42537
MD5 a8f465e6a7c9ad6e8f5a2cd759c1653b
BLAKE2b-256 bd645ed11df18f4d5659c8057cdf1b2bad5a5fd5bdd53fb663b01b6e476bb211

See more details on using hashes here.

Provenance

The following attestation bundles were made for kraken_captia-0.1.3-py3-none-any.whl:

Publisher: publish.yml on Capt-IA/Kraken-SDK

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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