What a Task is#

A Task is a Python callable declared with @app.task(). It can run locally during development or remotely as one Invocation. Use a Task for finite work that starts, returns a result or failure, and reaches a terminal state. Use a Live App when the program needs a persistent HTTP Endpoint.

The runnable quickstart declares an App, Task and entrypoint in hello_task.py. The CLI runs the entrypoint with yak run hello_task.py.

Choose how to invoke it#

The Task exposes three common remote call shapes:

python
# Synchronous caller; returns the Task result.
result = square.remote(21)

# Async caller; returns the Task result.
result = await square.remote.aio(21)

# Submit first; returns an Invocation for later observation or control.
invocation = await square.remote_async(21)
result = await invocation.result()

Use Task.local(...) for a local call to the original Python callable. A local call does not create a remote Invocation. See the generated Task reference and Invocation reference for exact signatures.

Observe and control an Invocation#

Invocation.result() waits for completion and returns the Task result. await invocation.status() reads current server state without waiting. await invocation.cancel() requests cancellation. After terminal settlement, invocation.usage may hold the backend’s usage projection; it can remain None before usage has arrived.

An Invocation represents one accepted remote submission. Retain its handle when the caller needs to do other work before awaiting the result, expose status to a higher-level workflow, or request cancellation.

Set Task resources#

Declare CPU in physical core units and memory in MiB. A single number sets a request; a (request, limit) tuple sets both the requested amount and a hard execution limit:

python
@app.task(cpu=0.5, memory=(512, 1024))
def transform(value: str) -> str:
    ...

CPU values use 0.001-core precision. The current SDK accepts requests from 0.125 through 256 cores. Memory values are integer MiB; limits must be at least the request and may not exceed 1,048,576 MiB. Omitted resource values are resolved by the service. A request helps Yak select capacity; an explicit limit bounds the Task. Observed terminal usage is a separate projection; see Resource Usage .