class documentation

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
urlServer URL (e.g. http://localhost:8001). If not set, falls back to RESONATE_URL env, then RESONATE_HOST/RESONATE_PORT.
authBasic auth credentials as (username, password). Falls back to RESONATE_USERNAME/RESONATE_PASSWORD env vars.
tokenBearer token for authentication. Falls back to RESONATE_TOKEN env var. Takes priority over basic auth.
groupWorker group name. Defaults to "default".
pidProcess identifier. Auto-generated if not provided.
ttlTime-to-live in seconds for claimed tasks. Defaults to 10.
log_levelLogging verbosity. Defaults to logging.INFO.
workersNumber of worker threads for function execution.
storeAdvanced — provide a custom store implementation.
message_sourceAdvanced — provide a custom message source.
dependenciesOptional dependency injection container.
registryOptional function registry.
Method __init__ Undocumented
Method begin_rpc Begin remote execution of a registered function through Resonate.
Method begin_run 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_dependency 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_level Undocumented
Instance Variable _message_source 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
def __init__(self, *, url: 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

@overload
def begin_rpc(self, id: str, func: Callable[Concatenate[Context, P], Generator[Any, Any, R] | R], *args: P.args, **kwargs: P.kwargs) -> Handle[R]:
@overload
def begin_rpc(self, id: str, func: str, *args: Any, **kwargs: Any) -> Handle[Any]:

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:strUnique identifier for this remote invocation. Used to deduplicate and resume durable results.
func:Callable[Concatenate[Context, P], Generator[Any, Any, R] | R] | strThe function to execute remotely, either as a callable or the registered name of the function.
*args:P.argsPositional arguments to pass to the function.
**kwargs:P.kwargsKeyword 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.
@overload
def begin_run(self, id: str, func: Callable[Concatenate[Context, P], Generator[Any, Any, R] | R], *args: P.args, **kwargs: P.kwargs) -> Handle[R]:
@overload
def begin_run(self, id: str, func: str, *args: Any, **kwargs: Any) -> Handle[Any]:

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:strUnique identifier for this function invocation. Used to deduplicate and resume durable results.
func:Callable[Concatenate[Context, P], Generator[Any, Any, R] | R] | strThe function to execute, either as a callable or the registered name of the function.
*args:P.argsPositional arguments to pass to the function.
**kwargs:P.kwargsKeyword 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.
def get(self, id: str) -> Handle[Any]:

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 id must 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:strUnique 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.
def options(self, *, encoder: 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.
@overload
def register(self, func: Callable[Concatenate[Context, P], R], /, *, name: str | None = None, version: int = 1) -> Function[P, R]:
@overload
def register(self, *, name: 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] | NoneThe function to register, or None when used as a decorator.
name:str | NoneOptional explicit name for the registered function. Defaults to the function's own name.
version:intVersion 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.
@overload
def rpc(self, id: str, func: Callable[Concatenate[Context, P], Generator[Any, Any, R] | R], *args: P.args, **kwargs: P.kwargs) -> R:
@overload
def rpc(self, id: 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:strUnique identifier for this function invocation. Used to deduplicate and resume durable remote results.
func:Callable[Concatenate[Context, P], Generator[Any, Any, R] | R] | strThe function to execute remotely, either as a callable or the registered name of the function.
*args:P.argsPositional arguments to pass to the function.
**kwargs:P.kwargsKeyword arguments to pass to the function.
Returns
RThe result of the remote function execution.
@overload
def run(self, id: str, func: Callable[Concatenate[Context, P], Generator[Any, Any, R] | R], *args: P.args, **kwargs: P.kwargs) -> R:
@overload
def run(self, id: 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:strUnique identifier for this function invocation. Used to deduplicate and resume durable results.
func:Callable[Concatenate[Context, P], Generator[Any, Any, R] | R] | strThe function to execute, either as a callable or the registered name of the function.
*args:P.argsPositional arguments to pass to the function.
**kwargs:P.kwargsKeyword arguments to pass to the function.
Returns
RThe result of the executed function.
def set_dependency(self, name: str, obj: Any):

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:strThe name under which the dependency is registered. This name is used to retrieve the dependency within a function's Context.
obj:AnyThe dependency instance to register.
Returns
None
def start(self):

Explicitly start Resonate threads.

This happens automatically when calling .run() or .rpc(), but is generally recommended for all workers that have functions registered with Resonate.

def stop(self):

Stop resonate.

@property
promises: PromiseStore =

Promises low level client.

@property
schedules: ScheduleStore =

Schedules low level client.

_bridge =

Undocumented

_dependencies =

Undocumented

_group =

Undocumented

_log_level =

Undocumented

_message_source =

Undocumented

_opts =

Undocumented

_pid =

Undocumented

_registry =

Undocumented

_started: bool =

Undocumented

_store =

Undocumented

_ttl =

Undocumented

_workers =

Undocumented