class documentation

Resonate client.

Class Method local Initialize a Resonate client instance for local development.
Class Method remote Initialize a Resonate client with remote configuration.
Method __init__ Create a Resonate client.
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
@classmethod
def local(cls, dependencies: Dependencies | None = None, group: str = 'default', log_level: int | Literal['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'] = logging.INFO, pid: str | None = None, registry: Registry | None = None, ttl: int = 10, workers: int | None = None) -> Resonate:

Initialize a Resonate client instance for local development.

Initializes and returns a Resonate Client with zero dependencies. There is no external persistence — all state is stored in local memory, so there is no need to connect to a network. This client enables rapid API testing and experimentation before connecting to a Resonate Server.

Example

Creating a local client and running a registered function:

resonate = Resonate.local(ttl=30, log_level="DEBUG")
resonate.register(foo)
resonate.run("foo.1", foo, ...)
Parameters
dependencies:Dependencies | NoneOptional dependency injection container.
group:strWorker group name. Defaults to default.
log_level:int | Literal["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"]Logging verbosity level. Defaults to logging.INFO.
pid:str | NoneOptional process identifier for the worker.
registry:Registry | NoneOptional registry to manage in-memory objects.
ttl:intTime-to-live (in seconds) for claimed tasks. Defaults to 10.
workers:int | NoneOptional number of worker threads or processes for function execution.
Returns
ResonateA Resonate Client instance.
@classmethod
def remote(cls, auth: tuple[str, str] | None = None, dependencies: Dependencies | None = None, group: str = 'default', host: str | None = None, log_level: int | Literal['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'] = logging.INFO, message_source_port: str | None = None, pid: str | None = None, registry: Registry | None = None, store_port: str | None = None, ttl: int = 10, workers: int | None = None) -> Resonate:

Initialize a Resonate client with remote configuration.

This method initializes and returns a Resonate Client that has dependencies on a Resonate Server and/or additional message sources. These dependencies enable distributed durable workers to work together via durable RPCs. The default remote configuration expects to connect to a Resonate Server on your localhost network as both a promise store and message source.

Example

Creating a remote client and running a registered function:

resonate = Resonate.local(ttl=30, log_level="DEBUG")
resonate.register(foo)
resonate.run("foo.1", foo, ...)
Parameters
auth:tuple[str, str] | NoneOptional authentication credentials for connecting to the remote store. Expected format is (username, password).
dependencies:Dependencies | NoneOptional dependency injection container.
group:strClient group name. Defaults to "default".
host:str | NoneHost address of the remote store service.
log_level:int | Literal["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"]Logging verbosity level. Defaults to logging.INFO.
message_source_port:str | NonePort used for message source communication.
pid:str | NoneOptional process identifier for the client.
registry:Registry | NoneOptional registry to manage remote object mappings.
store_port:str | NonePort used for the remote store service.
ttl:intTime-to-live (in seconds) for claimed tasks. Defaults to 10.
workers:int | NoneOptional number of worker threads or processes for function execution.
Returns
ResonateA Resonate Client instance
def __init__(self, *, dependencies: Dependencies | None = None, group: str = 'default', log_level: int | Literal['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'] = logging.NOTSET, message_source: MessageSource | None = None, pid: str | None = None, registry: Registry | None = None, store: Store | None = None, ttl: int = 10, workers: int | None = None):

Create a Resonate client.

@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