Resonate client.
Creates a Resonate client that auto-detects local vs remote mode.
When no url is provided (and no RESONATE_URL or RESONATE_HOST environment variable is set), the client runs in local mode with in-memory state — no external dependencies required.
When a url is provided (or resolved from environment variables), the client runs in remote mode, connecting to a Resonate Server for distributed durable execution.
Examples
Local mode (in-memory, no server needed):
resonate = Resonate()
Remote mode via explicit URL:
resonate = Resonate(url="http://localhost:8001")
Remote mode via environment variables:
# export RESONATE_URL=http://my-server:8001 resonate = Resonate()
Remote mode with token auth:
resonate = Resonate(url="http://localhost:8001", token="my-secret")
Remote mode with basic auth:
resonate = Resonate(url="http://localhost:8001", auth=("user", "pass"))
| Parameters | |
| url | Server URL (e.g. http://localhost:8001). If not set, falls back to RESONATE_URL env, then RESONATE_HOST/RESONATE_PORT. |
| auth | Basic auth credentials as (username, password). Falls back to RESONATE_USERNAME/RESONATE_PASSWORD env vars. |
| token | Bearer token for authentication. Falls back to RESONATE_TOKEN env var. Takes priority over basic auth. |
| group | Worker group name. Defaults to "default". |
| pid | Process identifier. Auto-generated if not provided. |
| ttl | Time-to-live in seconds for claimed tasks. Defaults to 10. |
| log | Logging verbosity. Defaults to logging.INFO. |
| workers | Number of worker threads for function execution. |
| store | Advanced — provide a custom store implementation. |
| message | Advanced — provide a custom message source. |
| dependencies | Optional dependency injection container. |
| registry | Optional function registry. |
| Method | __init__ |
Undocumented |
| Method | begin |
Begin remote execution of a registered function through Resonate. |
| Method | begin |
Begin execution of a registered function through Resonate. |
| Method | get |
Retrieve or subscribe to an existing execution by ID. |
| Method | options |
Configure options for the function. |
| Method | register |
Register a function with Resonate for execution and version control. |
| Method | rpc |
Execute a registered function remotely through Resonate and waits for its result. |
| Method | run |
Run a registered function through Resonate and waits for its result. |
| Method | set |
Register a named dependency for use within function execution contexts. |
| Method | start |
Explicitly start Resonate threads. |
| Method | stop |
Stop resonate. |
| Property | promises |
Promises low level client. |
| Property | schedules |
Schedules low level client. |
| Instance Variable | _bridge |
Undocumented |
| Instance Variable | _dependencies |
Undocumented |
| Instance Variable | _group |
Undocumented |
| Instance Variable | _log |
Undocumented |
| Instance Variable | _message |
Undocumented |
| Instance Variable | _opts |
Undocumented |
| Instance Variable | _pid |
Undocumented |
| Instance Variable | _registry |
Undocumented |
| Instance Variable | _started |
Undocumented |
| Instance Variable | _store |
Undocumented |
| Instance Variable | _ttl |
Undocumented |
| Instance Variable | _workers |
Undocumented |
str | None = None, auth: tuple[ str, str] | None = None, token: str | None = None, group: str = 'default', pid: str | None = None, ttl: int = 10, log_level: int | Literal[ 'DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'] = logging.INFO, workers: int | None = None, store: Store | None = None, message_source: MessageSource | None = None, dependencies: Dependencies | None = None, registry: Registry | None = None):
¶
Undocumented
Begin remote execution of a registered function through Resonate.
This method initiates a remote execution on a Resonate worker and returns a
Handle that can be used to track progress, await completion, or retrieve
the result later. If a durable promise with the same id already exists,
Resonate will reuse the existing execution state or subscribe to its result
instead of starting a new one. This ensures consistent, idempotent, and
fault-tolerant behavior in distributed environments.
Resonate guarantees that duplicate remote executions for the same id are prevented.
Notes
- The target function must be registered with Resonate.
- All function arguments and keyword arguments must be serializable.
- This operation is non-blocking and returns immediately with a handle.
Example
Starting a remote run asynchronously:
handle = resonate.begin_rpc("job-987", process_data, records)
# Do other work...
result = handle.result()
Using a registered function name:
handle = resonate.begin_rpc("job-987", "aggregate_metrics", dataset)
Non-blocking awaiting:
result = await resonate.begin_rpc("job-987", "aggregate_metrics", dataset)
| Parameters | |
id:str | Unique identifier for this remote invocation. Used to deduplicate and resume durable results. |
func:Callable[Concatenate[Context, P], Generator[Any, Any, R] | R] | str | The function to execute remotely, either as a callable or the registered name of the function. |
*args:P.args | Positional arguments to pass to the function. |
**kwargs:P.kwargs | Keyword arguments to pass to the function. |
| Returns | |
Handle[R] | A handle object representing the remote execution, which can be used to monitor, await, or retrieve results. |
Begin execution of a registered function through Resonate.
This method starts the execution of a registered function and returns a
Handle that can be used to track progress, await completion, or retrieve
results later. If a durable promise with the same id already exists,
Resonate will reuse the existing execution state or subscribe to its result
rather than starting a new run. This ensures idempotent and fault-tolerant
execution across distributed systems.
Resonate guarantees that duplicate executions for the same id are prevented.
Notes
- The target function must be registered with Resonate.
- All function arguments and keyword arguments must be serializable.
- This operation is non-blocking; it returns immediately with a handle.
Example
Starting a function run asynchronously:
handle = resonate.begin_run("job-123", process_data, records)
# Do other work...
result = handle.result()
Using a registered function name:
handle = resonate.begin_run("job-123", "aggregate_metrics", dataset)
Non-blocking awaiting:
result = await resonate.begin_run("job-123", "aggregate_metrics", dataset)
| Parameters | |
id:str | Unique identifier for this function invocation. Used to deduplicate and resume durable results. |
func:Callable[Concatenate[Context, P], Generator[Any, Any, R] | R] | str | The function to execute, either as a callable or the registered name of the function. |
*args:P.args | Positional arguments to pass to the function. |
**kwargs:P.kwargs | Keyword arguments to pass to the function. |
| Returns | |
Handle[R] | A handle object that can be used to monitor, await, or retrieve the function's result. |
Retrieve or subscribe to an existing execution by ID.
This method attaches to an existing durable promise identified by id.
If the associated execution is still in progress, it returns a Handle
that can be used to await or observe its completion. If the execution has
already completed, the handle is resolved immediately with the stored result.
Notes
- A durable promise with the given
idmust already exist. - This operation is non-blocking; awaiting the handle will block only if the execution is still running.
Example
Attaching to an existing execution:
handle = resonate.get("job-42")
result = handle.result()
Non-blocking awaiting:
handle = resonate.get("job-42")
result = await handle
| Parameters | |
id:str | Unique identifier of the target execution or durable promise. |
| Returns | |
Handle[Any] | A handle representing the existing execution, which can be used to await or retrieve the result. |
Encoder[ Any, str | None] | None = None, idempotency_key: str | Callable[ [ str], str] | None = None, retry_policy: RetryPolicy | Callable[ [ Callable], RetryPolicy] | None = None, tags: dict[ str, str] | None = None, target: str | None = None, timeout: float | None = None, version: int | None = None) -> Resonate:
¶
Configure options for the function.
- encoder: Configure your own data encoder.
- idempotency_key: Define the idempotency key invocation or a function that
- receives the promise id and creates an idempotency key.
- retry_policy: Define the retry policy: exponential | constant | linear | never
- tags: Add custom tags to the durable promise representing the invocation.
- target: Target to distribute the invocation.
- timeout: Number of seconds before the invocation timesout.
- version: Version of the function to invoke.
Callable[ Concatenate[ Context, P], R], /, *, name: str | None = None, version: int = 1) -> Function[ P, R]:str | None = None, version: int = 1) -> Callable[ [ Callable[ Concatenate[ Context, P], R]], Function[ P, R]]:Register a function with Resonate for execution and version control.
This method makes a function available for top-level execution under a specific name and version. It can be used either directly by passing the target function, or as a decorator for more concise registration.
When used as a decorator without arguments, the function is registered
automatically using its own name and the default version. Providing explicit
name or version values allows precise control over function identification
and versioning for repeatable, distributed invocation.
Example
Registering a function directly:
def greet(ctx: Context, name: str) -> str:
return f"Hello, {name}!"
resonate.register(greet, name="greet_user", version=2)
Using as a decorator:
@resonate.register(name="process_data", version=2)
def process(ctx: Context, data: dict) -> dict:
...
| Parameters | |
*args:Callable[Concatenate[Context, P], R] | None | The function to register,
or None when used as a decorator. |
name:str | None | Optional explicit name for the registered function. Defaults to the function's own name. |
version:int | Version number for the registered function. Defaults to 1. |
| Returns | |
Function[P, R] | Callable[[Callable[Concatenate[Context, P], R]], Function[P, R]] | If called directly, returns a Function wrapper for the registered
function. If used as a decorator, returns a decorator that registers
the target function upon definition. |
str, func: Callable[ Concatenate[ Context, P], Generator[ Any, Any, R] | R], *args: P.args, **kwargs: P.kwargs) -> R:str, func: str, *args: Any, **kwargs: Any) -> Any:Execute a registered function remotely through Resonate and waits for its result.
This method invokes a registered function on a remote Resonate worker and
blocks until the result is available. If a durable promise with the same id
already exists, Resonate will reuse the existing execution or subscribe to its
completion instead of executing it again, ensuring idempotent and consistent
remote execution.
Resonate guarantees that duplicate remote executions for the same id are prevented.
Notes
- The target function must be registered with Resonate.
- All function arguments and keyword arguments must be serializable.
- This is a blocking remote operation that waits for completion.
Example
Running a function remotely by reference:
result = resonate.rpc("remote-task-7", my_function, data)
Running a registered function by name:
result = resonate.rpc("remote-task-7", "process_order", order_id)
| Parameters | |
id:str | Unique identifier for this function invocation. Used to deduplicate and resume durable remote results. |
func:Callable[Concatenate[Context, P], Generator[Any, Any, R] | R] | str | The function to execute remotely, either as a callable or the registered name of the function. |
*args:P.args | Positional arguments to pass to the function. |
**kwargs:P.kwargs | Keyword arguments to pass to the function. |
| Returns | |
R | The result of the remote function execution. |
str, func: Callable[ Concatenate[ Context, P], Generator[ Any, Any, R] | R], *args: P.args, **kwargs: P.kwargs) -> R:str, func: str, *args: Any, **kwargs: Any) -> Any:Run a registered function through Resonate and waits for its result.
This method executes a registered function by its identifier or reference
and returns the computed result. If a durable promise with the same id
already exists, Resonate will reuse the existing result or subscribe to its
completion rather than executing the function again. This ensures
idempotent and deterministic behavior across distributed executions.
Resonate guarantees that duplicate executions for the same id are prevented.
Notes
- The target function must be registered with Resonate.
- All function arguments and keyword arguments must be serializable.
- This is a blocking operation that waits for completion.
Example
Running a function directly:
result = resonate.run("task-42", my_function, 10, flag=True)
Running by registered name:
result = resonate.run("task-42", "process_data", records)
| Parameters | |
id:str | Unique identifier for this function invocation. Used to deduplicate and resume durable results. |
func:Callable[Concatenate[Context, P], Generator[Any, Any, R] | R] | str | The function to execute, either as a callable or the registered name of the function. |
*args:P.args | Positional arguments to pass to the function. |
**kwargs:P.kwargs | Keyword arguments to pass to the function. |
| Returns | |
R | The result of the executed function. |
Register a named dependency for use within function execution contexts.
Registers a dependency object that will be made available to all registered functions through their Context. Dependencies are typically shared resources such as database clients, configuration objects, or service interfaces that functions can access during execution.
Example
Registering and using a dependency:
client.set_dependency("db", DatabaseClient())
@client.register()
def fetch_user(ctx: Context, user_id: str):
db = ctx.dependencies["db"]
return db.get_user(user_id)
| Parameters | |
name:str | The name under which the dependency is registered. This name is used to retrieve the dependency within a function's Context. |
obj:Any | The dependency instance to register. |
| Returns | |
| None |