Installation
Install the iii SDK via pip:Quick Start
Here’s a simple example that creates a function and exposes it via HTTP: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.- HTTP
- Queue
- Cron
- Stream
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)
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)
register_function(function_id: str, handler: Callable)
Register a function with the engine.
Parameters:
function_id: Unique function identifierhandler: 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 invokeconfig: 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 invokedata: Input data dictionary
Best Practices
Use async/await consistently
Use async/await consistently
The SDK is async-first. Always use
async def for function handlers and await for operations.Handle connection lifecycle
Handle connection lifecycle
Always call
await iii.connect() before registering triggers and await iii.disconnect() when shutting down.Use structured logging
Use structured logging
Use Python’s logging module for better observability.
Type hints for clarity
Type hints for clarity
Use type hints to make your code more maintainable and catch errors early.
Graceful shutdown
Graceful shutdown
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