Official Python SDK for Kraken document processing API
Project description
Kraken SDK for Python
Official Python SDK for the public Kraken API exposed through PCS/Stratios.
Requirements
- Python 3.9 or higher
httpxfor HTTP requestspydanticfor 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 .
Public architecture
The supported public flow is:
- client application → PCS/Stratios
- PCS verifies the API key and injects signed platform context
- PCS proxies the request to Kraken
By default, the SDK therefore prefixes requests with /services/kraken.
Quick Start
from kraken_sdk import KrakenClient
from kraken_sdk.types import ExtractionTaskRequest
client = KrakenClient(
api_key="your-api-key",
base_url="https://pcs.example.com",
)
source = client.sources.upload("invoice.pdf")
# Read service metadata through PCS
info = client.info.info()
print(info.service, info.version)
source = client.sources.upload("path/to/document.pdf")
print(f"Uploaded: {source.id}")
job = client.jobs.create_single(
ExtractionTaskRequest(
task_type="extraction",
source_id=source.id,
ai_provider="openai",
provider_model="gpt-4o",
)
)
result = client.jobs.wait(job.job_id)
tasks = client.jobs.tasks(job.job_id)
print(result.status)
print(tasks.tasks[0].status)
Async Support
The SDK provides full async support:
import asyncio
from kraken_sdk import AsyncKrakenClient
from kraken_sdk.types import ExtractionTaskRequest
async def main():
async with AsyncKrakenClient(
api_key="your-api-key",
base_url="https://pcs.example.com",
) as client:
source = await client.sources.upload("document.pdf")
job = await client.jobs.create_single(
ExtractionTaskRequest(
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())
Direct internal access
Direct Kraken URLs should stay limited to internal tooling and trusted service-to-service use. If you really need it, disable PCS path prefixing explicitly:
client = KrakenClient(
api_key="internal-key",
base_url="https://kraken.internal.example.com",
use_pcs_proxy=False,
)
Structured Annotation
Extract structured data using custom schemas:
from kraken_sdk import KrakenClient
from kraken_sdk.types import AnnotationTaskRequest
client = KrakenClient(
api_key="your-api-key",
base_url="https://pcs.example.com",
)
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(
AnnotationTaskRequest(
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:
from kraken_sdk.types import ExtractionTaskConfig
job = client.jobs.create_bulk(
task_config=ExtractionTaskConfig(
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 KrakenAuthError, KrakenError, KrakenNotFoundError
try:
result = client.jobs.get("invalid-id")
except KrakenNotFoundError:
print("Job not found")
except KrakenAuthError:
print("Invalid API key")
except KrakenError as e:
print(f"API error: {e}")
API Reference
KrakenClient
| Resource | Methods |
|---|---|
client.info |
info(), health(), tasks() |
client.jobs |
create(), create_single(), create_bulk(), list(), get(), tasks(), wait() |
client.sources |
upload() |
client.benchmarks |
create(), list(), get(), report(), create_expected_result(), upload_expected_result(), get_expected_result(), list_expected_results() |
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
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 kraken_captia-0.1.5.tar.gz.
File metadata
- Download URL: kraken_captia-0.1.5.tar.gz
- Upload date:
- Size: 40.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dfbbee3522e68f0ca13dfd4199b50fcb58859dbca7b95cbab2bbb695d43f57c1
|
|
| MD5 |
a014d12c8048963fc69bb79bd2c0b980
|
|
| BLAKE2b-256 |
e57b28833fdd029bd08b3dc9b019e5282dcd038fb8cd7e24dc0cbcb5c74f9de5
|
Provenance
The following attestation bundles were made for kraken_captia-0.1.5.tar.gz:
Publisher:
publish.yml on Capt-IA/Kraken-SDK
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
kraken_captia-0.1.5.tar.gz -
Subject digest:
dfbbee3522e68f0ca13dfd4199b50fcb58859dbca7b95cbab2bbb695d43f57c1 - Sigstore transparency entry: 1790160600
- Sigstore integration time:
-
Permalink:
Capt-IA/Kraken-SDK@d624077203d4cfffef17948dfa9ac4edbad34432 -
Branch / Tag:
refs/tags/v0.1.5 - Owner: https://github.com/Capt-IA
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@d624077203d4cfffef17948dfa9ac4edbad34432 -
Trigger Event:
release
-
Statement type:
File details
Details for the file kraken_captia-0.1.5-py3-none-any.whl.
File metadata
- Download URL: kraken_captia-0.1.5-py3-none-any.whl
- Upload date:
- Size: 26.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
014566f342b80433902829a23225724c418206a5bf353ef29258e498ac3f7bf8
|
|
| MD5 |
2748b903bdef0633bd21f30105556db8
|
|
| BLAKE2b-256 |
cc526028c5071b815d436b70d446f1b405f3906861238327f6bc9c99793c629a
|
Provenance
The following attestation bundles were made for kraken_captia-0.1.5-py3-none-any.whl:
Publisher:
publish.yml on Capt-IA/Kraken-SDK
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
kraken_captia-0.1.5-py3-none-any.whl -
Subject digest:
014566f342b80433902829a23225724c418206a5bf353ef29258e498ac3f7bf8 - Sigstore transparency entry: 1790160768
- Sigstore integration time:
-
Permalink:
Capt-IA/Kraken-SDK@d624077203d4cfffef17948dfa9ac4edbad34432 -
Branch / Tag:
refs/tags/v0.1.5 - Owner: https://github.com/Capt-IA
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@d624077203d4cfffef17948dfa9ac4edbad34432 -
Trigger Event:
release
-
Statement type: