Official Python SDK for the KairosAI Identity platform
Project description
kairosai-identity
Official Python SDK for the KairosAI Identity platform — AI agent identity, permissioning, and tamper-evident audit.
Installation
pip install kairosai-identity
Quick start
from kairosai_identity import KairosIdentity
kairos = KairosIdentity(api_key="ki_your_api_key_here")
Get your API key from the KairosAI Identity dashboard.
Usage
Register an agent
agent = kairos.agents.register(
name="My Email Agent",
description="Reads and summarizes emails",
capabilities=["read:email", "browse:web"],
signing_key_pub="""-----BEGIN PUBLIC KEY-----
MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE...
-----END PUBLIC KEY-----""",
)
print(agent.did) # did:kairos:abc123xyz
print(agent.token) # eyJhbGc... — save this in your env vars!
Important: Store
agent.tokenin your agent's environment variables (e.g.AGENT_TOKEN). It won't be shown again.
Verify an agent
result = kairos.verify(
token=agent_jwt, # from os.environ["AGENT_TOKEN"]
target_resource="email-service",
scopes_requested=["read:email"],
)
if not result.allowed:
print(result.decision) # 'DENIED' | 'REVOKED' | 'EXPIRED'
print(result.reason) # 'Agent lacks required scopes: read:email'
raise PermissionError("Agent not authorized")
print(result.agent.did) # did:kairos:abc123xyz
print(result.agent.active_scopes) # ['read:email', 'browse:web']
verify_or_raise — one-liner gate
# Raises KairosVerificationError if not allowed
agent = kairos.verify_or_raise(
token=agent_jwt,
scopes_requested=["read:email"],
)
# Safe to proceed — agent is verified
print(agent.active_scopes)
Revoke an agent
kairos.agents.revoke(
"did:kairos:abc123xyz",
reason="compromised",
notes="Private key was exposed in a log file",
)
# All future verify() calls for this agent return allowed=False
Manage scopes
# Grant new scopes
kairos.agents.update_scopes(
"did:kairos:abc123xyz",
grant=[
{"scope": "write:calendar"},
{"scope": "read:files", "expires_at": "2025-12-31T00:00:00Z"},
],
)
# Revoke specific scopes
kairos.agents.update_scopes(
"did:kairos:abc123xyz",
revoke=["browse:web"],
)
Fetch audit log
log = kairos.agents.audit_log(
"did:kairos:abc123xyz",
decision="DENIED",
limit=50,
)
print(log.pagination.total) # Total matching events
for entry in log.entries:
print(entry.event_type) # 'AGENT_DENIED'
print(entry.reason) # 'Agent lacks required scopes'
print(entry.entry_hash) # SHA-256 hash chain entry
Batch verify
results = kairos.batch_verify([
{"token": jwt1, "scopes_requested": ["read:email"]},
{"token": jwt2, "scopes_requested": ["browse:web"]},
])
print(results.summary.allowed) # 1
print(results.summary.denied) # 1
for result in results.results:
print(result.allowed, result.decision)
Async usage
Full async support via AsyncKairosIdentity — uses httpx.AsyncClient under the hood.
import asyncio
from kairosai_identity import AsyncKairosIdentity
async def main():
async with AsyncKairosIdentity(api_key="ki_...") as kairos:
result = await kairos.verify(token=agent_jwt)
if not result.allowed:
raise PermissionError("Agent not authorized")
agent = result.agent
print(agent.did)
asyncio.run(main())
FastAPI integration
from fastapi import FastAPI, Header, HTTPException, Depends
from kairosai_identity import AsyncKairosIdentity, KairosVerificationError
import os
app = FastAPI()
kairos = AsyncKairosIdentity(api_key=os.environ["KAIROS_API_KEY"])
async def require_agent(x_agent_token: str = Header(...)):
try:
return await kairos.verify_or_raise(
token=x_agent_token,
scopes_requested=["read:data"],
)
except KairosVerificationError as e:
raise HTTPException(status_code=403, detail=str(e))
@app.get("/api/data")
async def get_data(agent=Depends(require_agent)):
return {"data": "...", "verified_agent": agent.did}
Error handling
from kairosai_identity import (
KairosIdentity,
KairosError,
KairosAuthError,
KairosNotFoundError,
KairosVerificationError,
KairosTimeoutError,
)
try:
result = kairos.verify(token=agent_jwt)
except KairosAuthError:
print("Invalid API key")
except KairosTimeoutError:
print("Request timed out")
except KairosError as e:
print(f"Error {e.code} ({e.status}): {e}")
Configuration
kairos = KairosIdentity(
api_key="ki_...",
# Point to your own instance (default: https://identity.kairosaistudio.com)
base_url="https://identity.yourdomain.com",
# Request timeout in seconds (default: 10.0)
timeout=5.0,
)
Requirements
- Python 3.9+
httpx>= 0.24.0
License
MIT © KairosAI
Project details
Release history Release notifications | RSS feed
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 kairosai_identity-0.1.0.tar.gz.
File metadata
- Download URL: kairosai_identity-0.1.0.tar.gz
- Upload date:
- Size: 11.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
729c6ba7543a8668b46fabeb88f1cbacdfdbc7b98d50501ba9801d0b234bbf58
|
|
| MD5 |
a047edb18eee90f0ff68e28fd9b905a4
|
|
| BLAKE2b-256 |
8a48267d5dd18cad390909fefa8c4cbc04cd1bce4350659ac82f73d6d4512e58
|
File details
Details for the file kairosai_identity-0.1.0-py3-none-any.whl.
File metadata
- Download URL: kairosai_identity-0.1.0-py3-none-any.whl
- Upload date:
- Size: 10.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c663088b35de5929930d01112d3d3f8ac5cdf3f4827d749398e33825aced4f20
|
|
| MD5 |
ddb301673ad592a6a9142ce171b5de48
|
|
| BLAKE2b-256 |
9d5619e5e662bc5fa9feeb3f8c3b6d0475b0cf0a3ba60ca85ebddd9347d20267
|