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 |
| Monitor connection state |
| Bind a trigger with optional metadata |
| 导出项 | 用途 |
|---|---|
| 连接至引擎,返回客户端 |
| 连接配置 |
| 注册异步函数处理器 |
| 将触发器绑定至函数 |
| 同步调用函数 |
| 异步调用函数 |
| 在处理器内访问日志和追踪上下文 |
| 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 - For discovery reads and topology subscriptions, call the built-in engine functions with /
trigger()and bindtrigger_async()withengine::functions-available. Seeregister_trigger()./docs/how-to/discover-workers-functions-triggers
- 返回同步客户端;处理器为异步类型
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 - 如需进行发现读取和拓扑订阅,可通过 /
trigger()调用内置引擎函数,并使用trigger_async()绑定register_trigger()。详见engine::functions-available。/docs/how-to/discover-workers-functions-triggers
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 HTTP middleware patterns, see
iii-http-middleware - For Node.js SDK, see
iii-node-sdk - For Rust SDK, see
iii-rust-sdk - For browser-side usage, see
iii-browser-sdk
- 如需使用模式和工作示例,请查看
iii-functions-and-triggers - 如需HTTP中间件模式,请查看
iii-http-middleware - 如需Node.js SDK,请查看
iii-node-sdk - 如需Rust SDK,请查看
iii-rust-sdk - 如需浏览器端使用方式,请查看
iii-browser-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技能更合适时,不得使用此技能。
- 在应用此技能中的示例前,务必验证环境和安全约束。