Python SDK

Complete guide to installing and using the XASE Python SDK.

Requirements

  • Python 3.8+
  • pip or poetry

Installation

pip install xase

Verify Installation

verify.pypython
import xase
print(xase.__version__)
# Output: 1.0.0

Configuration

Basic Setup

basic.pypython
import xase

# Option 1: Pass API key directly
client = xase.Client(api_key="xase_pk_...")

# Option 2: Use environment variable (recommended)
# Set XASE_API_KEY in your environment
client = xase.Client()

Environment Variables

.envbash
# .env file
XASE_API_KEY=xase_pk_...
XASE_BASE_URL=https://api.xase.ai  # Optional, for self-hosted
XASE_TIMEOUT=30  # Optional, request timeout in seconds

Advanced Configuration

advanced.pypython
client = xase.Client(
    api_key="xase_pk_...",
    base_url="https://api.xase.ai",
    timeout=30,
    max_retries=3,
    debug=False
)

Usage

Create a Record

create_record.pypython
record = client.records.create(
    model_id="credit-model-v2",
    input={
        "customer_id": "cust_123",
        "income": 85000,
        "debt_ratio": 0.32,
        "credit_score": 720
    },
    output={
        "decision": "APPROVED",
        "credit_limit": 25000,
        "interest_rate": 12.5
    },
    confidence=0.94,
    idempotency_key="req_unique_123"
)

print(record.id)  # rec_8a7f3b2c...

Record an Intervention

intervene.pypython
intervention = client.records.intervene(
    record_id="rec_8a7f3b2c",
    actor_email="joao.silva@company.com",
    action="OVERRIDE",
    new_outcome={
      "decision": "APPROVED",
      "credit_limit": 30000
    },
    reason="Customer provided additional collateral",
    evidence_urls=[
      "https://storage.company.com/docs/collateral_123.pdf"
    ]
)

print(intervention.id)

Export Evidence Bundle

export.pypython
export = client.exports.create(
    record_id="rec_8a7f3b2c",
    include_related=True,
    format="zip"
)

print(export.id)
export.download("./evidence_bundle.zip")

Async Support

async.pypython
import asyncio
import xase

async def main():
    client = xase.AsyncClient(api_key="xase_pk_...")
    record = await client.records.create(
        model_id="credit-model-v2",
        input={"customer_id": "123"},
        output={"decision": "APPROVED"}
    )
    print(record.id)

asyncio.run(main())

Error Handling

errors.pypython
import xase
from xase.exceptions import (
    XaseError, AuthenticationError, RateLimitError, ValidationError, NotFoundError
)

client = xase.Client()

try:
    record = client.records.create(...)
except AuthenticationError:
    print("Invalid API key")
except RateLimitError as e:
    print(f"Rate limited. Retry after {e.retry_after} seconds")
except ValidationError as e:
    print(f"Invalid request: {e.errors}")
except NotFoundError:
    print("Record not found")
except XaseError as e:
    print(f"XASE error: {e.message}")