iii-python-sdk

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Python SDK

Python SDK

The async Python SDK for connecting workers to the iii engine.
用于将worker连接至iii引擎的异步Python SDK。

Documentation

文档

Install

安装

pip install iii-sdk
pip install iii-sdk

Key Exports

核心导出项

ExportPurpose
register_worker(address, options?)
Connect to the engine, returns the client
InitOptions(worker_name, otel?)
Connection configuration
register_function(id, handler)
Register an async function handler
register_trigger(type, function_id, config)
Bind a trigger to a function
trigger(request)
Invoke a function synchronously
trigger_async(request)
Invoke a function asynchronously
get_context()
Access logger and trace context inside handlers
ApiRequest
/
ApiResponse
HTTP request/response types (pydantic)
IStream
Interface for custom stream implementations
on_functions_available(callback)
Listen for function discovery
on_connection_state_change(callback)
Monitor connection state
导出项用途
register_worker(address, options?)
连接至引擎,返回客户端
InitOptions(worker_name, otel?)
连接配置
register_function(id, handler)
注册异步函数处理器
register_trigger(type, function_id, config)
将触发器绑定至函数
trigger(request)
同步调用函数
trigger_async(request)
异步调用函数
get_context()
在处理器内访问日志和追踪上下文
ApiRequest
/
ApiResponse
HTTP请求/响应类型(基于pydantic)
IStream
自定义流实现的接口
on_functions_available(callback)
监听函数发现事件
on_connection_state_change(callback)
监控连接状态

Key Notes

核心注意事项

  • register_worker()
    returns a synchronous client; handlers are async
  • ApiResponse
    uses camelCase
    statusCode
    (pydantic alias), not
    status_code
  • End workers with
    while True: await asyncio.sleep(60)
    to keep the event loop alive
  • Use
    asyncio.to_thread()
    for CPU-heavy sync work inside handlers
  • The SDK implements both
    trigger_async(request)
    and a synchronous
    trigger(request)
    . Use
    trigger_async
    inside async handlers, and
    trigger
    in synchronous scripts or threads where blocking behavior is desired.
  • register_worker()
    返回同步客户端;处理器为异步类型
  • ApiResponse
    使用驼峰式
    statusCode
    (pydantic别名),而非
    status_code
  • 需通过
    while True: await asyncio.sleep(60)
    维持事件循环运行,以保持worker在线
  • 处理器内的CPU密集型同步任务请使用
    asyncio.to_thread()
    处理
  • SDK同时实现了
    trigger_async(request)
    和同步版
    trigger(request)
    。异步处理器内请使用
    trigger_async
    ,在同步脚本或线程中若需阻塞行为则使用
    trigger

Examples

示例

python
undefined
python
undefined

Async 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"} })
undefined
result = iii.trigger({ "function_id": "greet", "payload": {"name": "World"} })
undefined

Pattern 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
    iii-python-sdk
    in the iii engine.
  • 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技能更适合时,不得使用本技能。
  • 在应用本技能中的示例前,请务必验证环境和安全约束。