Camshaft workflows in Python
The same as the TypeScript SDK (sdk/typescript), over the same protocol (docs/remote-protocol.md): write a workflow as a function, serve it over HTTP, and the Camshaft engine runs it durably. Standard library only.
import os
from camshaft import wsgi_app
def refund(ctx, order):
amount = ctx.step("look up", lambda: look_up(order)) # runs once, recorded
if not ctx.wait_signal("approval", "approve"): # waits for a person, durably
return "declined"
ctx.sleep("cool off", 60_000) # a minute, durably
return ctx.step("refund", lambda: pay(order, amount)) # once, even if this server restarts
app = wsgi_app({"refund": refund}, secret=os.environ["CAMSHAFT_SECRET"])
Serve app with any WSGI server, and configure it in the engine: CAMSHAFT_REMOTE='{"refund": {"url": "https://…", "secret": "…"}}'. Also ctx.wait_signal(name, signal, timeout_ms=…) (returns None past the deadline) and ctx.child(name, workflow, input) (another workflow in any language; its failure raises StepFailed). Updates and queries: u = ctx.wait_update(name, "add") takes the next update ({"id", "value"}) sent with POST /runs/{id}/updates/add, ctx.answer(name, u, value=…) (or error=…) answers its waiting sender, and ctx.publish(name, "total", 42) publishes a value read with GET /runs/{id}/published. ctx.tag(name, ["stage=shipped"]) tags the run to find it by (GET /runs?tag=); a key=value tag replaces its key.
The rules are the protocol's: each name once per run, stable across code changes (a change that replays differently is a new version); code outside steps runs on every call, so no side effects there; a step that raises is retried by the engine, and out of attempts step raises StepFailed.
Status: a first version (2026-11-30), not published as a package. Tests: python3 -m unittest discover -s tests, and the engine's crates/api/tests/remote.rs::python_workflows runs the same workflows as the TypeScript SDK's.
A client of the HTTP API: camshaft.client
The other direction: call Camshaft from Python (docs/openapi.json), standard library only (urllib, Python 3.9+), mirroring sdk/go. It lives in this package, as camshaft.client, since it is the same standard-library-only code and one import camshaft for both; it shares nothing but the name.
from camshaft.client import Client, NodChallenge, Conflict, RateLimited
c = Client("https://camshaft.example", lambda: current_token()) # a string, or a function asked before each call
c.save_flow("refunds", {"input": "string", "steps": [...], "output": ...})
st = c.start_run("order-9", flow="refunds", input="9", priority=10) # st.created, st.debounced (st.id is the
run = c.get_run(st.id) # collapsing run's when debounced)
for e in c.watch_run(st.id): ... # status, live, then end: through waits
for r in c.each_run(flow="refunds", status="failed", limit=50): ... # cursor paging; list_runs gives one page
c.retry_run(r["id"]); c.signal_run(r["id"], "go", True); c.cancel_run(r["id"], "reason")
c.approve(run_id, "agent step", "call_2") # a person's own token only: others get Forbidden
c.send_event("refunds", "paid", {"customer": "acme"}, id="e1")
c.set_schedule("nightly", flow="refunds", cron="0 2 * * *", tz="Europe/Berlin"); c.list_schedules()
c.get_pacing("refunds"); c.get_concurrency("refunds", key="acme")
try:
c.delete_flow("refunds")
except NodChallenge as e: # a person's nod: ask e.issuer for e.authorization_details (CIBA), then
c.delete_flow("refunds", approval=approval_token)
Errors: every 4xx and 5xx is an ApiError (status, message, method, path) with subclasses BadRequest, Unauthorized, Forbidden, NotFound, Conflict, RateLimited (retry_after seconds, limit), ServerError and ServiceUnavailable; NodChallenge is a Forbidden carrying issuer and authorization_details. With a callable token source, a 401 asks it again and repeats the call once. approve and decline signal approve.<step>.<call> (true or false) with the step's %, . and / escaped; the service refuses an agent, a machine or an acting token, and that 403 is raised with its reason. Reads are dicts (typed with TypedDict), unknown fields kept.
Tests: python3 -m unittest discover -s tests (an http.server stand-in). tests/test_integration.py starts the real binary (cargo build -p camshaft-api --bin camshaft) over a throwaway PostgreSQL made with initdb when CAMSHAFT_BIN and KIT_PG_BIN (PostgreSQL's bin) are set, and skips otherwise. Publishing to PyPI is a person's step; not published.