Define a function
Save this asreports.py:
Call it
From the CLI, JSON arguments become Python values:async_remote() is the async form, and a plain
summarize_sales(...) call runs locally.
Where a call goes covers previews and
deployments.
Process a batch
.map() submits one call per input and yields results in input order. Each
tuple holds one call’s arguments:
None. When every item must succeed before you use the
batch, spawn_map() returns each outcome to check:
.map() over 1,000 texts now runs on up to 20 containers at once.
max_pending_tasks goes up because .map() submits every input at once. See
Scaling and the
Parquet example.
Submit work in the background
.spawn() returns a FunctionCall right away, and .get() waits for the
value. uv run lazycloud task result <task-id> collects it from anywhere else,
and a pending FunctionCall passed to another function arrives as its result.
Tasks and logs covers looking calls up by ID.
Arguments and results
Calls from the Python SDK carry any serializable Python value, including NumPy arrays, dataclasses, custom class instances, tuples, and bytes:lazycloud run --json, and
exported clients
need JSON, which Pydantic models and dataclasses convert to. Arguments and
results cap at 16 MiB each, so larger output goes in a
volume or an artifact.
Function options
Retries and timeouts
timeout_seconds caps one attempt, and retries, 3 by default, adds attempts
after a failure. One call can therefore run four times, so writes should be
safe to repeat, for example keyed on the input, or retries=0. A RetryPolicy
adds backoff:
Lifecycle hooks
on_start runs once before a container accepts calls, which suits loading a
model or opening a client:
on_running, on_success, on_error, on_retry,
on_failure, and on_finish. lazycloud.current_task_id() returns the
current call’s ID inside the function or a hook.
Stop and clean up
lazycloud task cancel cancels a pending call and task stop a running one. A
deployed function stays callable until stopped:
stop keeps the definition for deployment start.
--prune removes a function deleted from
the code.
