zhuye (Python SDK)
让 Python 项目直接驱动 Zhuye Agent 的轻量 SDK。底层通过 spawn zhuye serve 子进程、走 JSONL stdio 协议,零运行时依赖(仅 stdlib)。
安装
pip install zhuye
安装即用:PyPI 提供平台 wheel(macOS arm64 / x86_64,Linux x86_64 /
aarch64 glibc,Windows x86_64),内嵌对应平台的 zhuye 二进制,SDK
优先解析它 —— 无需自装二进制、无需配环境变量。
二进制解析优先级:显式 options.bin → ZHUYE_BIN → wheel 内嵌
二进制 → PATH 上的 zhuye。当前平台不在支持矩阵(如 musl/Alpine)
时回退 PATH:从 GitHub Releases
下载,或从本仓库 make build 产出 target/release/zhuye 后以
ZHUYE_BIN 指向。
用法
from zhuye import ZhuyeAgent, ToolOutput, ContentBlock
agent = ZhuyeAgent.spawn()
# 注册客户端自定义工具(LLM 调用时由本地函数返回结果)
def get_weather(args):
return ToolOutput(
content=[ContentBlock(type="text", text=f"{args['city']} 今天晴 26℃")],
is_error=False,
metadata={},
elapsed_ms=0,
)
agent.register_tool(
name="get_weather",
description="查询城市天气",
parameters={
"type": "object",
"properties": {"city": {"type": "string"}},
"required": ["city"],
},
handler=get_weather,
)
# 高层:聚合 delta,返回最终文本
print(agent.prompt("北京天气如何?"))
# 低层:遍历 turn 事件
for ev in agent.submit("第二轮"):
msg = ev["msg"]
if msg["type"] == "agent_message_delta":
print(msg["delta"], end="", flush=True)
if msg["type"] == "turn_complete":
break
agent.close()
全局事件
next_global_event(timeout_secs=5) 读取 id="" 的会话事件,与 submit() 的
按 submission 路由的事件迭代器独立。超时抛 queue.Empty,进程 stdout
关闭后返回 None;未知变体原样返回。
handshake = agent.next_global_event(timeout_secs=5)
环境变量
| 变量 | 作用 |
|---|---|
ZHUYE_BIN |
zhuye 二进制路径(最高优先级覆盖;缺省用 wheel 内嵌二进制)。 |
ZHUYE_MODEL |
模型 spec(mock/mock-1 用于离线 SDK 集成测试)。 |
ZHUYE_REMOTE_TOOL_TIMEOUT_SECS |
远程工具等待客户端回执的上限,默认 120s。 |
测试
python3 -m pip install pytest
python3 -m pytest -ra
mock serve 进程跑在 Node 上(Node ≥ 18),不依赖真 zhuye 二进制 —— 测试完全离线,也不需要网络/API key。仓库内开发直接以源码树运行(python -m pytest 会把本目录加入 sys.path),无需构建安装;打包后端为 maturin(平台 wheel 由 CI 产出并内嵌二进制,见 docs/release.md),本地构建需 Rust 工具链。
端到端测试(对真 zhuye serve 子进程的集成)在仓库 CI 里跑;在仓库根配置好 ZHUYE_BIN 后执行 ./tests/run_all.sh sdk-python。
协议
SDK 与 zhuye serve 之间的 wire 协议见 ../PROTOCOL.md(同仓库 sdks/PROTOCOL.md)。Rust 核心新增协议变体时,SDK 自动降为 UnknownEventMsg,不会中断下游。
Metadata
Release files for zhuye 0.1.5
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 |
|---|---|---|---|---|
| zhuye-0.1.5.tar.gz | 13.5 kB | With provenance | Details for zhuye-0.1.5.tar.gz |
Built distributions (wheels)
| File | Actions Reset | |||
|---|---|---|---|---|
| zhuye-0.1.5-py3-none-win_amd64.whl | Python 3 | none | Windows x86-64 | Details for zhuye-0.1.5-py3-none-win_amd64.whl |
| zhuye-0.1.5-py3-none-manylinux_2_34_x86_64.whl | Python 3 | none | Linux glibc 2.34+ x86-64 | Details for zhuye-0.1.5-py3-none-manylinux_2_34_x86_64.whl |
| zhuye-0.1.5-py3-none-manylinux_2_34_aarch64.whl | Python 3 | none | Linux glibc 2.34+ ARM64 | Details for zhuye-0.1.5-py3-none-manylinux_2_34_aarch64.whl |
| zhuye-0.1.5-py3-none-macosx_11_0_arm64.whl | Python 3 | none | macOS 11.0+ ARM64 | Details for zhuye-0.1.5-py3-none-macosx_11_0_arm64.whl |
| zhuye-0.1.5-py3-none-macosx_10_12_x86_64.whl | Python 3 | none | macOS 10.12+ x86-64 | Details for zhuye-0.1.5-py3-none-macosx_10_12_x86_64.whl |
Total release size: 66.4 MB
Release files / zhuye-0.1.5.tar.gz
| Download URL | zhuye-0.1.5.tar.gz |
|---|---|
| Size | 13.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6983f15c9ad18b74191f29d2b8d4d73db89aea9435aa1f30eeb0ba75dbf1b6ee
|
|
BLAKE2b-256 checksum How to use checksums |
d3a6701870c8d609879eccb72bd4c5df0c520ab10077197607a5bc6e82736ed7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 29, 2026.
Transparency logRelease files / zhuye-0.1.5-py3-none-win_amd64.whl
| Download URL | zhuye-0.1.5-py3-none-win_amd64.whl |
|---|---|
| Size | 13.4 MB |
| Tags | Python 3 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
6b3fb61456d1a821ae18a4b0db98aca4586fdc486b2eae199ecd9695f3fed543
|
|
BLAKE2b-256 checksum How to use checksums |
e6088283bcdf8e351698946381ed5884f37be7f4a624f344f51b060a32107572
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 29, 2026.
Transparency logRelease files / zhuye-0.1.5-py3-none-manylinux_2_34_x86_64.whl
| Download URL | zhuye-0.1.5-py3-none-manylinux_2_34_x86_64.whl |
|---|---|
| Size | 14.3 MB |
| Tags | Linux glibc 2.34+ x86-64 Python 3 |
|
SHA-256 checksum How to use checksums |
583a63644d397acaadd15475112490ec3703b7b78c24ea1710f86c3ee928b4da
|
|
BLAKE2b-256 checksum How to use checksums |
5b401b191b8414c43e787df8a906d3087206182e6e914743d45c44f64f9c8b76
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 29, 2026.
Transparency logRelease files / zhuye-0.1.5-py3-none-manylinux_2_34_aarch64.whl
| Download URL | zhuye-0.1.5-py3-none-manylinux_2_34_aarch64.whl |
|---|---|
| Size | 13.4 MB |
| Tags | Linux glibc 2.34+ ARM64 Python 3 |
|
SHA-256 checksum How to use checksums |
d2de8abb6a4a13936234ac5c915bd3862f75a30ad85e326596cac33ad5bde1c8
|
|
BLAKE2b-256 checksum How to use checksums |
5f0262b32b3c1aa4dbcaebe2784b65e65b77bbcffcdef8a69c1ebc7813c1fbf7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 29, 2026.
Transparency logRelease files / zhuye-0.1.5-py3-none-macosx_11_0_arm64.whl
| Download URL | zhuye-0.1.5-py3-none-macosx_11_0_arm64.whl |
|---|---|
| Size | 12.4 MB |
| Tags | Python 3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
733a74eecc5c388d46d13496747039f0c2a41c1069573906dc9c6f86e30b0cb9
|
|
BLAKE2b-256 checksum How to use checksums |
42eb66754fe95c920ec47e8985e3da8d1ac80574450ff9f1d2b4caac101d8b7c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 29, 2026.
Transparency logRelease files / zhuye-0.1.5-py3-none-macosx_10_12_x86_64.whl
| Download URL | zhuye-0.1.5-py3-none-macosx_10_12_x86_64.whl |
|---|---|
| Size | 13.0 MB |
| Tags | Python 3 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
8a3aa66035df9fa7a0152c6a7769dda417214bfa7fb286cf95e92df982c6f6ad
|
|
BLAKE2b-256 checksum How to use checksums |
c1f21a587a7593a923b794c6dc1eee183eb98ebf947b0628be6fa26590e964f2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 29, 2026.
Transparency logSecurity for zhuye 0.1.5
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.
Full provenance
All 6 files in this release have been uploaded with provenance metadata.
Attestation for zhuye-0.1.5.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 29, 2026.
Transparency logA 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.