Skip to content

Commit 6a543b4

Browse files
jordanrburgerclaude
andcommitted
Simplify Python Client page: trim features, reorder use cases
Remove verbose usage examples (reference client README instead), simplify feature list, move Data Apps above CLI use case, and clarify Python/JS Data Apps availability. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 7058252 commit 6a543b4

1 file changed

Lines changed: 26 additions & 139 deletions

File tree

kai/python-client.md

Lines changed: 26 additions & 139 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,10 @@ The [Kai Python Client](https://github.com/keboola/kai-client) is an official Py
1111
## Features
1212

1313
- **Command-line interface** for quick interactions without writing code
14-
- **Async/await support** using `httpx`
15-
- **Server-Sent Events (SSE) streaming** for real-time chat responses
16-
- **Type-safe models** with Pydantic v2
17-
- **Comprehensive error handling** with custom exception classes
18-
- **Session management** for chat conversations
19-
- **Full API coverage** including chat, history, and voting endpoints
14+
- **Real-time streaming** — see responses as they arrive
15+
- **Conversation management** — maintain context across multiple messages
16+
- **Tool approval flows** — review and approve Kai actions programmatically
17+
- **Full API coverage** — chat, history, and feedback
2018

2119
## Installation
2220

@@ -95,120 +93,44 @@ In interactive mode, type your messages and press Enter. Type `exit`, `quit`, or
9593

9694
**Tool approval:** When Kai calls a write tool (e.g., `update_descriptions`, `run_job`, `create_config`), the CLI pauses and asks you to approve or deny. Use `--auto-approve` to skip this prompt.
9795

98-
## Usage Examples
96+
For more usage examples (non-streaming chat, conversations, tool calls, tool approval, error handling), see the [client README](https://github.com/keboola/kai-client#readme).
9997

100-
### Simple Chat (Non-Streaming)
98+
## Use Cases
10199

102-
```python
103-
async with KaiClient(
104-
storage_api_token="your-master-token",
105-
storage_api_url="https://connection.keboola.com"
106-
) as client:
107-
chat_id, response = await client.chat("What is 2 + 2?")
108-
print(response)
109-
```
100+
### Integrating Kai into Data Apps
110101

111-
### Continuing a Conversation
102+
The Kai Python Client can be embedded into Keboola [Data Apps](/data-apps/) to provide AI-powered chat interfaces for your end users.
112103

113-
```python
114-
async with KaiClient(
115-
storage_api_token="your-master-token",
116-
storage_api_url="https://connection.keboola.com"
117-
) as client:
118-
chat_id = client.new_chat_id()
119-
120-
# First message
121-
async for event in client.send_message(chat_id, "Hello!"):
122-
if event.type == "text":
123-
print(event.text, end="")
124-
print()
125-
126-
# Continue the conversation (reuse same chat_id)
127-
async for event in client.send_message(chat_id, "What did I just say?"):
128-
if event.type == "text":
129-
print(event.text, end="")
130-
print()
131-
```
104+
#### Python/JS Data Apps
132105

133-
### Handling Tool Calls
106+
You can integrate Kai into [Python/JS Data Apps](/data-apps/python-js/) today using the Kai Python Client directly. A dedicated plugin with ready-made patterns will be available soon to simplify the setup.
134107

135-
```python
136-
async with KaiClient(
137-
storage_api_token="your-master-token",
138-
storage_api_url="https://connection.keboola.com"
139-
) as client:
140-
chat_id = client.new_chat_id()
141-
142-
async for event in client.send_message(chat_id, "List my Keboola tables"):
143-
match event.type:
144-
case "text":
145-
print(event.text, end="")
146-
case "tool-call":
147-
if event.state == "input-available":
148-
print(f"\n[Calling {event.tool_name} with {event.input}]")
149-
elif event.state == "output-available":
150-
print(f"\n[{event.tool_name} returned: {event.output}]")
151-
case "finish":
152-
print(f"\n[Done: {event.finish_reason}]")
153-
```
154-
155-
### Tool Approval for Write Operations
108+
#### Streamlit Data Apps
156109

157-
Some tools require explicit approval before execution. The server sends a `tool-approval-request` event with an `approval_id` that you use to approve or reject.
110+
The [kai-streamlit plugin](https://github.com/keboola/kai-client/tree/main/plugins/kai-streamlit) provides patterns and working code for building [Streamlit Data Apps](/data-apps/streamlit/) with an integrated Kai chat interface. It handles the async bridge between Streamlit's synchronous model and the KaiClient's async API, streaming responses into Streamlit containers, tool approval flows with interactive Approve/Deny buttons, and session state management across Streamlit reruns.
158111

159-
```python
160-
from kai_client import KaiClient
112+
To get started, install the dependencies:
161113

162-
async with KaiClient(
163-
storage_api_token="your-master-token",
164-
storage_api_url="https://connection.keboola.com"
165-
) as client:
166-
chat_id = client.new_chat_id()
167-
pending_approval_id = None
168-
169-
async for event in client.send_message(chat_id, "Create a new bucket"):
170-
if event.type == "tool-approval-request":
171-
pending_approval_id = event.approval_id
172-
173-
# Approve the pending tool
174-
if pending_approval_id:
175-
async for event in client.approve_tool(
176-
chat_id=chat_id,
177-
approval_id=pending_approval_id,
178-
):
179-
if event.type == "text":
180-
print(event.text, end="")
114+
```bash
115+
pip install kai-client streamlit
181116
```
182117

183-
### Error Handling
118+
Then use the `run_async` bridge pattern to call KaiClient from Streamlit:
184119

185120
```python
186-
from kai_client import (
187-
KaiClient,
188-
KaiError,
189-
KaiAuthenticationError,
190-
KaiRateLimitError,
191-
KaiNotFoundError,
192-
)
193-
194-
async with KaiClient(
195-
storage_api_token="your-master-token",
196-
storage_api_url="https://connection.keboola.com"
197-
) as client:
121+
import asyncio
122+
from kai_client import KaiClient
123+
124+
def run_async(coro):
125+
"""Run an async coroutine from sync Streamlit code."""
126+
loop = asyncio.new_event_loop()
198127
try:
199-
async for event in client.send_message("chat-id", "Hello"):
200-
print(event)
201-
except KaiAuthenticationError:
202-
print("Authentication failed")
203-
except KaiRateLimitError:
204-
print("Rate limited, try again later")
205-
except KaiNotFoundError:
206-
print("Chat not found")
207-
except KaiError as e:
208-
print(f"API error: {e.code} - {e.message}")
128+
return loop.run_until_complete(coro)
129+
finally:
130+
loop.close()
209131
```
210132

211-
## Use Cases
133+
See the [plugin repository](https://github.com/keboola/kai-client/tree/main/plugins/kai-streamlit) for a complete working example with streaming, tool approval, and suggested action buttons.
212134

213135
### Kai via CLI with Claude Code
214136

@@ -234,41 +156,6 @@ ln -s "$(pwd)/kai-client/plugins/kai-cli" ~/.claude/plugins/kai-cli
234156

235157
Once installed, ask Claude to "use kai" or "help me with kai cli" to activate the skill. Claude can then run `kai chat`, `kai history`, `kai ping`, and other CLI commands on your behalf.
236158

237-
### Integrating Kai into Data Apps
238-
239-
The Kai Python Client can be embedded into Keboola [Data Apps](/data-apps/) to provide AI-powered chat interfaces for your end users.
240-
241-
#### Streamlit Data Apps
242-
243-
The [kai-streamlit plugin](https://github.com/keboola/kai-client/tree/main/plugins/kai-streamlit) provides patterns and working code for building [Streamlit Data Apps](/data-apps/streamlit/) with an integrated Kai chat interface. It handles the async bridge between Streamlit's synchronous model and the KaiClient's async API, streaming responses into Streamlit containers, tool approval flows with interactive Approve/Deny buttons, and session state management across Streamlit reruns.
244-
245-
To get started, install the dependencies:
246-
247-
```bash
248-
pip install kai-client streamlit
249-
```
250-
251-
Then use the `run_async` bridge pattern to call KaiClient from Streamlit:
252-
253-
```python
254-
import asyncio
255-
from kai_client import KaiClient
256-
257-
def run_async(coro):
258-
"""Run an async coroutine from sync Streamlit code."""
259-
loop = asyncio.new_event_loop()
260-
try:
261-
return loop.run_until_complete(coro)
262-
finally:
263-
loop.close()
264-
```
265-
266-
See the [plugin repository](https://github.com/keboola/kai-client/tree/main/plugins/kai-streamlit) for a complete working example with streaming, tool approval, and suggested action buttons.
267-
268-
#### Python/JS Data Apps
269-
270-
Support for integrating Kai into [Python/JS Data Apps](/data-apps/python-js/) is coming soon. A dedicated plugin will be available to simplify embedding Kai chat into custom Python and JavaScript-based data applications.
271-
272159
## Resources
273160

274161
- [GitHub Repository](https://github.com/keboola/kai-client)

0 commit comments

Comments
 (0)