Skip to main content

Official Python SDK for Kita Document Processing API

Project description

Kita Python SDK

The official Python SDK for the Kita Document Processing API.

Installation

pip install kita-sdk

Or install from source:

cd sdk/python
pip install -e .

Quick Start

from kita import KitaClient

# Initialize client with your API key
client = KitaClient(api_key="kita_prod_...")

# Process a single document
result = client.process("statement.pdf", "bank_statement")

# Access parsed data
print(result.metadata)
print(result.transactions)

Configuration

API Key

Get your API key from https://api.usekita.com/api-keys.html

You can provide the API key in three ways:

# 1. Pass directly to client
client = KitaClient(api_key="kita_prod_...")

# 2. Set environment variable
# export KITA_API_KEY=kita_prod_...
client = KitaClient()

# 3. Use .env file (with python-dotenv)
from dotenv import load_dotenv
load_dotenv()
client = KitaClient()

Base URL

The SDK defaults to production (https://api.usekita.com). For local development:

# Override with parameter
client = KitaClient(api_key="...", base_url="http://localhost:8080")

# Or set environment variable
# export KITA_API_URL=http://localhost:8080

Usage

Process Single Document

from kita import KitaClient

client = KitaClient(api_key="kita_prod_...")

# Process and wait for result
result = client.process("document.pdf", "bank_statement")

# Access the data
print(result.metadata)           # Account info, dates, etc.
print(result.transactions)       # List of transactions
print(result.signals)            # Financial signals
print(result.raw)                # Full raw response

Document Types

Supported document types (case-insensitive):

Type Description
bank_statement Bank account statements
passbook Savings passbooks
payslip Salary/pay stubs
bill Utility bills
audited_financial_statement Annual reports, AFS
other_document Other document types
# All these work
result = client.process("doc.pdf", "bank_statement")
result = client.process("doc.pdf", "BANK_STATEMENT")
result = client.process("doc.pdf", "Bank Statement")

Accessing Full Processed Data

The complete processed data including transaction tables, metrics, and fraud detection is in result.raw['result']:

result = client.process("statement.pdf", "bank_statement")

# Full API response
full_json = result.raw

# Processed data with tables, metrics, fraud detection
processed = result.raw['result']

# Transaction tables (rows of transaction data)
tables = processed['tables']
transactions = tables[0]['data']  # List of transaction dicts
for tx in transactions[:5]:
    print(f"{tx.get('Date and Time')} | {tx.get('Description')} | {tx.get('Credit') or tx.get('Debit')}")

# Financial metrics (aggregated totals)
metrics = processed['metrics']
print(f"Inflow: {metrics['total_inflow']}")
print(f"Outflow: {metrics['total_outflow']}")
print(f"Transactions: {metrics['transaction_count']}")

# Category breakdown
categories = processed['category_metrics']
# {'financial': {'count': 14, 'total': 15000}, 'food': {'count': 2, 'total': 500}, ...}

# Fraud detection
fraud = processed['fraud_check']
print(f"Suspicious: {fraud['is_suspicious']}")

# Save to file
import json
with open('result.json', 'w') as f:
    json.dump(full_json, f, indent=2)

Async Processing

# Don't wait for completion
result = client.process("large_doc.pdf", "bank_statement", wait=False)
print(result.raw)  # Contains documentId

# Check status later
doc = client.get_document(document_id)
print(doc.status)  # pending, processing, completed, failed

Batch Processing

Process all documents in a folder:

batch = client.batch_process("/path/to/folder", "payslip")

# Wait for all to complete
batch.wait()

# Get results
for result in batch.results():
    print(result.metadata)
    print(result.transactions)

# Check progress
print(batch.progress)  # {'total': 10, 'completed': 8, 'failed': 1, 'pending': 1}

Options:

batch = client.batch_process(
    "/folder",
    "bank_statement",
    extensions=['.pdf', '.png', '.jpg'],  # File types to process
    recursive=True,                        # Search subdirectories
    wait=True                              # Wait for completion
)

Error Handling

from kita import (
    KitaClient,
    KitaError,
    KitaAPIError,
    KitaAuthenticationError,
    KitaRateLimitError
)

client = KitaClient(api_key="kita_prod_...")

try:
    result = client.process("document.pdf", "payslip")
except KitaAuthenticationError:
    print("Invalid API key")
except KitaRateLimitError as e:
    print(f"Rate limited. Retry after {e.retry_after} seconds")
except KitaAPIError as e:
    print(f"API Error {e.status_code}: {e.message}")
except KitaError as e:
    print(f"SDK Error: {e}")

List Documents

docs = client.list_documents(
    limit=50,
    offset=0,
    status='completed',
    document_type='bank_statement'
)
print(docs['documents'])

Convenience Function

For quick one-off processing:

from kita import process

# Uses KITA_API_KEY environment variable
result = process("document.pdf", "bank_statement")

API Reference

KitaClient

client = KitaClient(
    api_key: str = None,      # API key (or set KITA_API_KEY env var)
    base_url: str = None,     # API URL (default: https://api.usekita.com)
    timeout: int = 60         # Request timeout in seconds
)

Methods

process(file_path, document_type, ...)

Process a single document.

result = client.process(
    file_path: str,           # Path to document
    document_type: str,       # Type of document
    wait: bool = True,        # Wait for completion
    poll_interval: int = 2,   # Seconds between status checks
    timeout: int = 600,       # Max wait time in seconds
    password: str = None      # PDF password if encrypted
)

Returns: DocumentResult

batch_process(folder_path, document_type, ...)

Process multiple documents from a folder.

batch = client.batch_process(
    folder_path: str,         # Path to folder
    document_type: str,       # Type of documents
    wait: bool = False,       # Wait for completion
    extensions: list = None,  # File extensions (default: ['.pdf', '.png', '.jpg', '.jpeg'])
    recursive: bool = False   # Search subdirectories
)

Returns: Batch

get_document(document_id)

Get a processed document by ID.

Returns: DocumentResult

list_documents(limit, offset, status, document_type)

List processed documents.

Returns: dict with documents list

DocumentResult

result.status          # 'completed', 'failed', etc.
result.document_type   # 'bank_statement', etc.
result.metadata        # Dict with account info, dates, etc.
result.transactions    # List of transactions
result.signals         # Financial signals
result.raw             # Full raw response dict
result.to_dict()       # Convert to dictionary

Batch

batch.id               # Batch ID
batch.status()         # Get current status
batch.wait()           # Wait for completion
batch.results()        # Iterator of DocumentResult objects
batch.completed        # Boolean - is batch done?
batch.progress         # Dict with total/completed/failed/pending counts

Environment Variables

Variable Description Default
KITA_API_KEY API key (required)
KITA_API_URL API base URL https://api.usekita.com

Development

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

# Run tests
pytest

# Format code
black kita/

License

MIT License

Support

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

kita-1.1.0.tar.gz (13.2 kB view details)

Uploaded Source

Built Distribution

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

kita-1.1.0-py3-none-any.whl (10.6 kB view details)

Uploaded Python 3

File details

Details for the file kita-1.1.0.tar.gz.

File metadata

  • Download URL: kita-1.1.0.tar.gz
  • Upload date:
  • Size: 13.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.2

File hashes

Hashes for kita-1.1.0.tar.gz
Algorithm Hash digest
SHA256 7c5eedea54f89d7df872afbcd45f7a9536be139e84613af7015da28b297feb9e
MD5 8d7d77ab5e3d85b03e2be9553f1461e8
BLAKE2b-256 a0f751ec9c7f5fa6c8893bcb60a776ed96a145505fe032ec372162000ca06a04

See more details on using hashes here.

File details

Details for the file kita-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: kita-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 10.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.2

File hashes

Hashes for kita-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 623f1e9a3e8a92d7d71f326aafbc50bb8a244531677df8da4ae356c11a7ed9f5
MD5 4311f660af424d1896736f7bf347318e
BLAKE2b-256 9e0b20046d0a2c690fb1f7271b403d21e05bcec6eddaaccee9b2498204694a96

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