Back to Iii

iii

sdk/README.md

0.13.06.3 KB
Original Source

iii

iii is a single engine that replaces your API framework, task queue, cron scheduler, pub/sub, state store, and observability pipeline with three primitives: Function, Trigger, and Worker. You write functions, declare what triggers them, connect a worker, and the engine handles routing, retries, and observability.

See the engine README for architecture details and the documentation for full guides.

SDKs

PackageLanguageInstallDocs
iii-sdkNode.js / TypeScriptnpm install iii-sdkREADME
iii-sdkPythonpip install iii-sdkREADME
iii-sdkRustAdd to Cargo.tomlREADME

Hello World

Node.js

javascript
import { registerWorker } from 'iii-sdk';

const iii = registerWorker('ws://localhost:49134');

iii.registerFunction({ id: 'greet' }, async (input) => {
  return { message: `Hello, ${input.name}!` };
});

iii.registerTrigger({
  type: 'http',
  function_id: 'greet',
  config: { api_path: '/greet', http_method: 'POST' },
});

const result = await iii.trigger({ function_id: 'greet', payload: { name: 'world' } });

Python

python
from iii import register_worker

iii = register_worker("ws://localhost:49134")

def greet(data):
    return {"message": f"Hello, {data['name']}!"}

iii.register_function({"id": "greet"}, greet)

iii.register_trigger({
    "type": "http",
    "function_id": "greet",
    "config": {"api_path": "/greet", "http_method": "POST"}
})

result = iii.trigger({"function_id": "greet", "payload": {"name": "world"}})

Rust

rust
use iii_sdk::{register_worker, InitOptions, TriggerRequest, RegisterFunctionMessage, RegisterTriggerInput};
use serde_json::json;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let iii = register_worker("ws://127.0.0.1:49134", InitOptions::default())?;

    iii.register_function(RegisterFunctionMessage { id: "greet".into(), description: None, request_format: None, response_format: None, metadata: None, invocation: None }, |input| async move {
        let name = input.get("name").and_then(|v| v.as_str()).unwrap_or("world");
        Ok(json!({ "message": format!("Hello, {name}!") }))
    });

    iii.register_trigger(RegisterTriggerInput { trigger_type: "http".into(), function_id: "greet".into(), config: json!({
        "api_path": "/greet",
        "http_method": "POST"
    }) })?;

    let result: serde_json::Value = iii
        .trigger(TriggerRequest::new("greet", json!({ "name": "world" })))
        .await?;

    Ok(())
}

API

OperationNode.jsPythonRustDescription
InitializeregisterWorker(url)register_worker(url, options?)register_worker(url, options)Create an SDK instance and auto-connect
Register functioniii.registerFunction({ id }, handler)iii.register_function(id, handler)iii.register_function(id, |input| ...)Register a function that can be invoked by name
Register triggeriii.registerTrigger({ type, function_id, config })iii.register_trigger({"type": ..., "function_id": ..., "config": ...})iii.register_trigger(type, fn_id, config)?Bind a trigger (HTTP, cron, queue, etc.) to a function
Invoke (await)await iii.trigger({ function_id, payload })await iii.trigger({"function_id": id, "payload": data})iii.trigger(TriggerRequest::new(id, data)).await?Invoke a function and wait for the result
Invoke (fire-and-forget)iii.trigger({ function_id, payload, action: TriggerAction.Void() })SameSameInvoke without waiting

registerWorker() / register_worker() creates an SDK instance and auto-connects to the engine. It handles WebSocket communication, automatic reconnection, and OpenTelemetry instrumentation. All three SDKs expose the same API surface — register functions and triggers, then invoke them.

call, callVoid, triggerVoid (and Python/Rust equivalents) have been removed. Use trigger() for all invocations. For fire-and-forget, use trigger({ function_id, payload, action: TriggerAction.Void() }).

For language-specific details (modules, streams, OpenTelemetry), see the per-SDK READMEs linked in the table above.

Development

Prerequisites

  • Node.js 20+ and pnpm (for Node.js SDK)
  • Python 3.10+ and uv (for Python SDK)
  • Rust 1.85+ and Cargo (for Rust SDK)
  • iii engine running on ws://localhost:49134

Building

bash
cd packages/node && pnpm install && pnpm build
cd packages/python/iii && python -m build
cd packages/rust/iii && cargo build --release

Testing

bash
cd packages/node && pnpm test
cd packages/python/iii && pytest
cd packages/rust/iii && cargo test

Examples

See the Quickstart guide for step-by-step tutorials.

Resources

License

Apache 2.0