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 # 全离线,注入假传输,绝不触网
Metadata
Release files for spinestudio-sdk 0.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| spinestudio_sdk-0.2.1.tar.gz | 9.5 kB | Without provenance | Details for spinestudio_sdk-0.2.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| spinestudio_sdk-0.2.1-py3-none-any.whl | Python 3 | none | any | Details for spinestudio_sdk-0.2.1-py3-none-any.whl |
Total release size: 18.5 kB
Release files / spinestudio_sdk-0.2.1.tar.gz
| Download URL | spinestudio_sdk-0.2.1.tar.gz |
|---|---|
| Size | 9.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1948ca21d32a29c417fb353908e1b04d5369f59f1a94680eb39047e5f4d0623a
|
|
BLAKE2b-256 checksum How to use checksums |
5e3918157acd09c098381e328b3d252d773fcd0421d26cf3b229d4f84c5e4a3e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.9
|
Release files / spinestudio_sdk-0.2.1-py3-none-any.whl
| Download URL | spinestudio_sdk-0.2.1-py3-none-any.whl |
|---|---|
| Size | 9.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
977ed4cf2c70c0b9b8bff1e4717cda166077f61f492aa50a9d736087a54cd703
|
|
BLAKE2b-256 checksum How to use checksums |
a139373d83dae070542027656c80c7ceb730ed0742d128e80c24526fba519609
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.9
|
Security for spinestudio-sdk 0.2.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.