iii project init quickstart --template quickstartcd quickstart
This creates the two workers that you’ll run: a Python worker that adds two numbers and stores the
sum in state, and a TypeScript worker that exposes an http endpoint and calls the Python worker
through the iii engine.
The engine is now listening on ws://localhost:49134. Keep this terminal open and open a second
terminal in the quickstart directory for the remaining commands.
Workers only need a WebSocket connection to the iii engine. They can run locally, in the cloud,
replicated in kubernetes, or anywhere else.
iii worker add ./workers/math-worker
You should see:
✓ Worker math-worker added to config.yamlPath /Users/tony/iii/projects/testing/quickstart/workers/math-worker✓ Using cached deps (use --force to reinstall)✓ math-worker started (pid: 12345)✓ Worker auto-started
This worker registered the function math::add with the engine. You could call this function right
now using the command below.
iii trigger math::add a=2 b=3
However this is not much different than running an equivalent script on its own. The utility of iii
comes from being able to place any functionality into a worker and then compose that worker with
other workers through the engine, regardless of where each one runs or what language it’s written
in.
Workers need a moment to install their runtime dependencies after being added. If you see
"message": "Function math::add not found", wait a few seconds and try again.
✓ Worker caller-worker added to config.yamlPath /Users/tony/iii/projects/testing/quickstart/workers/caller-worker✓ Using cached deps (use --force to reinstall)✓ caller-worker started (pid: 23456)✓ Worker auto-started
This worker registered the function math::add_two_numbers with the engine.
The iii worker add command incrementally adds workers from the registry to your running system.
Start by adding the state worker, which gives every function access to a persistent key-value store.From the folder containing iii’s config.yaml run:
iii worker add iii-state
Now open workers/math-worker/math_worker.py in your code editor and uncomment the state block so
the handler looks like this:
def add_handler(payload: dict) -> dict: a = payload.get("a", 0) b = payload.get("b", 0) logger.info(f"math::add called in Python with a={a}, b={b}") result = {"c": a + b} running_total = worker.trigger( { "function_id": "state::get", "payload": {"scope": "math", "key": "running_total"}, } ) new_total = (running_total or 0) + result["c"] worker.trigger( { "function_id": "state::set", "payload": {"scope": "math", "key": "running_total", "value": new_total}, } ) result["running_total"] = new_total return result
Save the file and call the function a few times:
iii trigger math::add a=2 b=3
{ "c": 5, "running_total": 5 }
iii trigger math::add a=10 b=20
{ "c": 30, "running_total": 35 }
The running total persists across every call, including calls that arrive through
math::add_two_numbers.
For a walkthrough of how the engine, workers, functions, and triggers in this scaffold fit together,
see Understanding iii. It uses this project as the worked example.
Open the iii Console with iii console in a new terminal: an interactive UI for workers,
functions, triggers, logs, traces, and state. See the full Console
documentation for details.
You scaffolded a project, started two workers in different languages, called functions across them,
added persistent state, and exposed everything over HTTP, all by incrementally adding workers to a
running system.
Use iii
Learn how to use iii in production.
Understanding iii
Understand functions, triggers, and workers from a conceptual point of view.