spinestudio 官方 Python 客户端 SDK:聊天(同步 + SSE 流式)/ KB / 会话 / 触发器
Project description
spinestudio-sdk
spinestudio 官方 Python 客户端。零第三方依赖(stdlib urllib),可独立 pip install。
pip install spinestudio-sdk
用法
from spinestudio_sdk import SpinestudioClient
client = SpinestudioClient("https://api.example.com", "sk-...")
# 同步聊天(消费整条 SSE 流并聚合)
result = client.chat("<workspace_id>", "本季度营收多少?")
print(result.answer)
for s in result.sources: # 反捏造溯源如实透传;查无实据则 sources 为空
print(s["doc"], s.get("locator"))
# 流式聊天(按序拿 token → sources → done 事件)
for event in client.stream_chat("<workspace_id>", "本季度营收多少?"):
if event.type == "token":
print(event.data["text"], end="", flush=True)
# 知识库文档
client.list_documents("<workspace_id>")
client.create_document("<workspace_id>", "标题", [{
"metric": "REVENUE", "entity": "ACME_CN", "period_type": "FY",
"period": "2024", "value": 1320, "unit": "USD_M",
}])
client.get_document("<workspace_id>", "<doc_id>")
client.delete_document("<workspace_id>", "<doc_id>")
# 会话
client.list_conversations("<workspace_id>")
client.get_conversation("<workspace_id>", "<conversation_id>")
# 触发器
client.fire_trigger("<workspace_id>", "<trigger_id>")
client.webhook_trigger("<workspace_id>", "<trigger_id>", payload={"event": "push"})
凭据说明
api_key 是任意 Bearer 凭据:
- Service API-Key(
sk-…)——workspace 作用域、read/write两档 scope,至多等价 member; 适合程序化聊天 / KB 读 / 触发器 webhook(需write)。 - 用户 JWT——会话「列表 / 新建 / 删除」是用户作用域端点,需用户 JWT(服务 key 会得 401)。
错误语义
非 2xx 抛异常,携带 .status 与 .message:AuthenticationError(401) / PermissionDeniedError(403) /
NotFoundError(404) / APIError(其它),均继承 SpinestudioError。
开发
cd sdks/python
uv venv .venv
VIRTUAL_ENV="$(pwd)/.venv" uv pip install -e ".[dev]"
.venv/bin/python -m pytest -q # 全离线,注入假传输,绝不触网
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
spinestudio_sdk-0.1.0.tar.gz
(9.4 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
File details
Details for the file spinestudio_sdk-0.1.0.tar.gz.
File metadata
- Download URL: spinestudio_sdk-0.1.0.tar.gz
- Upload date:
- Size: 9.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b13fa34818b68b945c83ef402bec671f54aac65e274784e20fb100e8dadf8422
|
|
| MD5 |
b8cff9eac77a978c2c31b87508cd19ae
|
|
| BLAKE2b-256 |
dc1fb980a2d3199e33819184e2340b488ed5db18f25deb901cd6b7e0ee4ead4a
|
File details
Details for the file spinestudio_sdk-0.1.0-py3-none-any.whl.
File metadata
- Download URL: spinestudio_sdk-0.1.0-py3-none-any.whl
- Upload date:
- Size: 9.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
67761ce2fff07a602006a4148661ea2304278fca8027e3be564f36678dba83b7
|
|
| MD5 |
d1d5bc86bb65d23dbfb84a3bcbf5e606
|
|
| BLAKE2b-256 |
d2fbaa84513e4ae8bf962a0fe2cd3d28dab7b8ef055a9491ba195d53b11c63e0
|