iii-python-sdk
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChinesePython SDK
Python SDK
The async Python SDK for connecting workers to the iii engine.
用于将worker连接至iii引擎的异步Python SDK。
Documentation
文档
Full API reference: https://iii.dev/docs/api-reference/sdk-python
Install
安装
pip install iii-sdkpip install iii-sdkKey Exports
核心导出项
| Export | Purpose |
|---|---|
| Connect to the engine, returns the client |
| Connection configuration |
| Register an async function handler |
| Bind a trigger to a function |
| Invoke a function synchronously |
| Invoke a function asynchronously |
| Access logger and trace context inside handlers |
| HTTP request/response types (pydantic) |
| Interface for custom stream implementations |
| Listen for function discovery |
| Monitor connection state |
| 导出项 | 用途 |
|---|---|
| 连接至引擎,返回客户端 |
| 连接配置 |
| 注册异步函数处理器 |
| 将触发器绑定至函数 |
| 同步调用函数 |
| 异步调用函数 |
| 在处理器内访问日志和追踪上下文 |
| HTTP请求/响应类型(基于pydantic) |
| 自定义流实现的接口 |
| 监听函数发现事件 |
| 监控连接状态 |
Key Notes
核心注意事项
- returns a synchronous client; handlers are async
register_worker() - uses camelCase
ApiResponse(pydantic alias), notstatusCodestatus_code - End workers with to keep the event loop alive
while True: await asyncio.sleep(60) - Use for CPU-heavy sync work inside handlers
asyncio.to_thread() - The SDK implements both and a synchronous
trigger_async(request). Usetrigger(request)inside async handlers, andtrigger_asyncin synchronous scripts or threads where blocking behavior is desired.trigger
- 返回同步客户端;处理器为异步类型
register_worker() - 使用驼峰式
ApiResponse(pydantic别名),而非statusCodestatus_code - 需通过维持事件循环运行,以保持worker在线
while True: await asyncio.sleep(60) - 处理器内的CPU密集型同步任务请使用处理
asyncio.to_thread() - SDK同时实现了和同步版
trigger_async(request)。异步处理器内请使用trigger(request),在同步脚本或线程中若需阻塞行为则使用trigger_async。trigger
Examples
示例
python
undefinedpython
undefinedAsync invocation (non-blocking, typical inside handlers)
异步调用(非阻塞,处理器内常用方式)
result = await iii.trigger_async({
"function_id": "greet",
"payload": {"name": "World"}
})
result = await iii.trigger_async({
"function_id": "greet",
"payload": {"name": "World"}
})
Sync invocation (blocks the current thread, useful in sync contexts)
同步调用(阻塞当前线程,适合同步场景)
result = iii.trigger({
"function_id": "greet",
"payload": {"name": "World"}
})
undefinedresult = iii.trigger({
"function_id": "greet",
"payload": {"name": "World"}
})
undefinedPattern Boundaries
模式边界
- For usage patterns and working examples, see
iii-functions-and-triggers - For Node.js SDK, see
iii-node-sdk - For Rust SDK, see
iii-rust-sdk
- 有关使用模式和完整示例,请查看
iii-functions-and-triggers - Node.js版SDK请查看
iii-node-sdk - Rust版SDK请查看
iii-rust-sdk
When to Use
使用场景
- Use this skill when the task is primarily about in the iii engine.
iii-python-sdk - Triggers when the request directly asks for this pattern or an equivalent implementation.
- 当任务主要涉及iii引擎中的时,使用本技能。
iii-python-sdk - 当请求直接询问此模式或等效实现时触发。
Boundaries
边界限制
- Never use this skill as a generic fallback for unrelated tasks.
- You must not apply this skill when a more specific iii skill is a better fit.
- Always verify environment and safety constraints before applying examples from this skill.
- 切勿将本技能作为无关任务的通用备选方案。
- 当有更特定的iii技能更适合时,不得使用本技能。
- 在应用本技能中的示例前,请务必验证环境和安全约束。