Skip to main content

Installation

Install the iii SDK via pip:

Quick Start

Here’s a simple example that creates a function and exposes it via HTTP:
Your function is now live at http://localhost:3111/add.

Connection

Initialize the SDK

Create an iii client instance:

Connect to the Engine

Establish a WebSocket connection:

Environment Variables

Configure the connection URL using environment variables:

Registering Functions

Basic Function Registration

Register an async function with the engine:

Function with Type Hints

Use Python type hints for better code clarity:

Synchronous vs Asynchronous

While the SDK is async-based, you can wrap synchronous code:

Error Handling

Handle errors in your functions:

Registering Triggers

Triggers must be registered after connecting to the engine.
Expose functions as HTTP endpoints:
Configuration options:
  • api_path: The URL path (e.g., ‘add’ → /add)
  • http_method: HTTP method (GET, POST, PUT, DELETE, PATCH)
Dynamic routes:

Invoking Functions

Invoke functions directly from your code:

Fire-and-Forget Invocations

Invoke without waiting for a response:

Complete Example

Here’s a comprehensive example with multiple functions and triggers:

API Reference

III(url: str)

Create an iii SDK instance. Parameters:
  • url: WebSocket URL of the iii engine (default: ws://localhost:49134)
Returns: SDK instance

register_function(function_id: str, handler: Callable)

Register a function with the engine. Parameters:
  • function_id: Unique function identifier
  • handler: Async function that receives data dict and returns result dict

register_trigger(type: str, function_id: str, config: dict)

Register a trigger for a function. Parameters:
  • type: Trigger type (http, queue, cron, stream)
  • function_id: ID of the function to invoke
  • config: Trigger-specific configuration dict

async connect()

Connect to the iii engine.

async disconnect()

Disconnect from the iii engine.

async invoke(function_id: str, data: dict)

Invoke a function and wait for the result. Parameters:
  • function_id: ID of the function to invoke
  • data: Input data dictionary
Returns: Function result

Best Practices

The SDK is async-first. Always use async def for function handlers and await for operations.
Always call await iii.connect() before registering triggers and await iii.disconnect() when shutting down.
Use Python’s logging module for better observability.
Use type hints to make your code more maintainable and catch errors early.
Handle KeyboardInterrupt and other signals to disconnect cleanly.

Next Steps

Node.js SDK

Learn about the Node.js SDK

Rust SDK

Learn about the Rust SDK

HTTP Module

Deep dive into HTTP triggers

Queue Module

Learn about queue-based triggers