Python client for the khive cognitive infrastructure API
Project description
khive
Python client for the khive cognitive infrastructure API.
Preview release — 4 services: memory, communication, work, graph.
- Sync and async — both
KhiveandAsyncKhiveclients - Fully typed — Pydantic response models, complete type annotations
- Agent integration — tool schemas for OpenAI, Anthropic, and MCP
- Retry with backoff — exponential backoff with jitter, respects
Retry-After
Installation
pip install khive
Quick Start
from khive import Khive
client = Khive(api_key="your-api-key")
# Store a memory
client.memory.remember(content="Quarterly review on March 15th")
# Recall memories by semantic search
results = client.memory.recall(query="quarterly review")
# Create a task
client.work.assign(title="Prepare slides", priority="p1")
# Send a message
client.communication.send(content="Slides ready", to="team")
# Knowledge graph
client.graph.create(type="person", name="Alice", role="engineer")
client.graph.link(source="node_1", target="node_2", relation="works_with")
Authentication
export KHIVE_API_KEY="your-api-key"
Or pass directly:
client = Khive(api_key="your-api-key")
Services
Memory (11 operations)
client.memory.recall(query="meeting notes", limit=5)
client.memory.remember(content="Sprint planning Monday 10am", tags=["recurring"])
client.memory.update(id="mem_123", importance=0.9)
client.memory.forget(id="mem_123")
client.memory.list(memory_type="episodic")
client.memory.feedback(memory_ids=["mem_123"], signal="positive")
client.memory.stats()
# Observational notes
from khive.types import NoteTarget
client.memory.note_create(
targets=[NoteTarget(kind="memory", id="mem_123")],
content="Frequently recalled in planning contexts",
)
Communication (18 operations)
client.communication.send(content="Status update", to="lambda:leo")
client.communication.list(status="unread")
client.communication.search(query="deployment")
client.communication.mark_read(message_id="msg_123")
client.communication.thread(thread_id="thread_123")
client.communication.discuss(discuss_action="start", topic="Architecture review")
client.communication.overview()
Work (25 operations)
client.work.next(limit=5)
client.work.assign(title="Fix login bug", priority="p1", energy="high")
client.work.complete(id="task_123")
client.work.schedule_add(title="Team standup", start="2026-05-01T10:00:00")
client.work.schedule_today()
client.work.areas()
client.work.project_create(area_id="area_123", name="Q1 Goals")
client.work.queue_decision(
title="Choose database",
options=["PostgreSQL", "SQLite", "DuckDB"],
)
Graph (7 operations)
client.graph.create(type="person", name="Alice", role="engineer")
client.graph.link(source="node_1", target="node_2", relation="works_with")
client.graph.search(query="engineers")
client.graph.neighbors(id="node_1", direction="outbound")
client.graph.get(id="node_1")
client.graph.unlink(source="node_1", target="node_2")
client.graph.delete(id="node_1")
Agent Integration
Generate tool schemas from the SDK's type system — no manual schema maintenance.
OpenAI
from khive import Khive
client = Khive()
tools = client.tools.to_openai_tools()
# Use with openai.chat.completions.create(tools=tools, ...)
# Then execute: client.tools.execute(tool_call.function.name, args)
Anthropic
tools = client.tools.to_anthropic_tools()
# Use with anthropic messages.create(tools=tools, ...)
# Then execute: client.tools.execute(block.name, block.input)
MCP
tools = client.tools.to_mcp_tools()
Schema-Only (no client needed)
from khive import to_openai_tools, list_tools
names = list_tools() # All tool names
memory_tools = to_openai_tools(services=["memory"])
Async
import asyncio
from khive import AsyncKhive
async def main():
async with AsyncKhive() as client:
result = await client.memory.recall(query="recent decisions")
await client.communication.send(content="Update", to="team")
asyncio.run(main())
Error Handling
from khive import Khive
from khive._errors import AuthenticationError, RateLimitError, NotFoundError
client = Khive()
try:
client.memory.recall(query="test")
except AuthenticationError:
print("Invalid API key")
except RateLimitError as e:
print(f"Rate limited, retry after {e.retry_after}s")
except NotFoundError:
print("Resource not found")
Configuration
client = Khive(
api_key="your-api-key", # or KHIVE_API_KEY env var
base_url="https://custom.api", # or KHIVE_BASE_URL env var
timeout=30.0, # request timeout (seconds)
max_retries=3, # retries for transient errors
default_headers={"X-Custom": "v"}, # additional headers
)
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
khive-1.0.0rc1.tar.gz
(65.2 kB
view details)
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
khive-1.0.0rc1-py3-none-any.whl
(25.0 kB
view details)
File details
Details for the file khive-1.0.0rc1.tar.gz.
File metadata
- Download URL: khive-1.0.0rc1.tar.gz
- Upload date:
- Size: 65.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bda27e3075e40463b6107e87220c36200ffa8842d34379895ccb1dfc74ba53f0
|
|
| MD5 |
d99de1e22f4a42ddaa8f66eaef016ca0
|
|
| BLAKE2b-256 |
aa9559a101dbdc5c6bb507bc82fce75b0aec07b9ae80e5b8dc01a753f5eba0b2
|
File details
Details for the file khive-1.0.0rc1-py3-none-any.whl.
File metadata
- Download URL: khive-1.0.0rc1-py3-none-any.whl
- Upload date:
- Size: 25.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d9dcb7c8165a606e918738ffbbf5c2dff0dc47ce4cfc95129b4efa41f8832b9d
|
|
| MD5 |
ba7843d5381a1b1aa1c8dc6caea57060
|
|
| BLAKE2b-256 |
2beb2c15b166f8aeb363e3ef8aee5d96431bf68dd2b2dd0590639ba6bcef81fa
|