Python SDK for connecting to the Finn (finn-ai) agent over WebSocket.
Project description
finn-sdk (Python)
Python SDK for the Finn (finn-ai) agent over WebSocket. The async counterpart of
the Node/TypeScript @riseanalytics/finn-sdk —
same connection, events, and error codes.
Install
pip install finn-sdk
Requires Python 3.9+.
Usage
import asyncio
from finn_sdk import FinnClient
async def main():
finn = FinnClient(url="https://finn.example.com", api_key="your-key")
await finn.connect()
# Stream tokens as they arrive
turn = await finn.send_message(
"What were Q3 deposits?",
system_prompt="You are a terse analyst.",
)
async for chunk in turn:
print(chunk.text, end="", flush=True)
result = await turn.completed # TurnResult(conversation_id, message_id, token_usage, ...)
# Continue the same conversation
follow = await finn.send_message("And Q4?", conversation_id=result.conversation_id)
await follow.completed
await finn.disconnect()
asyncio.run(main())
Or use the client as an async context manager (auto connect/disconnect):
async with FinnClient(url=url, api_key=key) as finn:
answer = await finn.ask("How many active members do I have?")
print(answer.text)
Notes
- Auth: pass
api_key(static) orget_api_key(sync or async callable, for rotation). Sent as the Socket.IO handshake token. - System prompt:
system_prompt(client default or per-call override) applies only when a conversation is first created; it is ignored on continuation turns. - Not streaming?
await finn.ask(text)returns anAskResult(the turn result plus the fulltext).await finn.ask_json(text)parses the answer as JSON — prompt for JSON yourself; it raisesFinnError(code="invalid_json")if it can't parse, with the raw answer onerror.details["raw"]. - Interrupt:
turn.interrupt()stops generation; the turn settles withinterrupted=True. - Errors: failures raise a
FinnErrorwhosecodeis one ofunauthorized,rate_limited,timeout,conversation_read_only,stream_error,disconnected,invalid_json. - Events:
finn.on("connected" | "disconnect" | "reconnect" | "rateLimit" | "unauthorized", cb). - Naming: methods and fields use Python
snake_case(send_message,conversation_id,token_usage) — the TypeScript SDK usescamelCase.
Develop
pip install -e ".[test]"
pytest
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 finn_sdk-0.1.0.tar.gz.
File metadata
- Download URL: finn_sdk-0.1.0.tar.gz
- Upload date:
- Size: 10.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c7fb0b8434008f0bdea47506f9358abfe1191885c17d2b125dcd232eba3d833b
|
|
| MD5 |
2e52d82df7c732c7ce3c07eacad1c29b
|
|
| BLAKE2b-256 |
9f8b27b6445de154d9312cb4a891e5d064af03aabd1a8c7d94054f03a7e9bf97
|
File details
Details for the file finn_sdk-0.1.0-py3-none-any.whl.
File metadata
- Download URL: finn_sdk-0.1.0-py3-none-any.whl
- Upload date:
- Size: 10.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f919241da856da6e883bc74d07145077649a423689f7e73287f187dc99358bbb
|
|
| MD5 |
2eeb707f8cc0d13ca80abafd48cc3b5f
|
|
| BLAKE2b-256 |
033906730ece9bab4b7528f6456aadd6f7f76982d86eca21784b31358f94ab66
|