class Resonate:
Constructors: Resonate.local(dependencies, group, log_level, pid, ...), Resonate.remote(auth, dependencies, group, host, ...), Resonate(dependencies, group, log_level, message_source, ...)
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 |
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 |
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 | None | Optional dependency injection container. |
group:str | Worker group name. Defaults to default. |
logint | Literal["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"] | Logging verbosity level. Defaults to logging.INFO. |
pid:str | None | Optional process identifier for the worker. |
registry:Registry | None | Optional registry to manage in-memory objects. |
ttl:int | Time-to-live (in seconds) for claimed tasks. Defaults to 10. |
workers:int | None | Optional number of worker threads or processes for function execution. |
| Returns | |
Resonate | A Resonate Client instance. |
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] | None | Optional authentication credentials for
connecting to the remote store. Expected format is (username, password). |
dependencies:Dependencies | None | Optional dependency injection container. |
group:str | Client group name. Defaults to "default". |
host:str | None | Host address of the remote store service. |
logint | Literal["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"] | Logging verbosity level. Defaults to logging.INFO. |
messagestr | None | Port used for message source communication. |
pid:str | None | Optional process identifier for the client. |
registry:Registry | None | Optional registry to manage remote object mappings. |
storestr | None | Port used for the remote store service. |
ttl:int | Time-to-live (in seconds) for claimed tasks. Defaults to 10. |
workers:int | None | Optional number of worker threads or processes for function execution. |
| Returns | |
Resonate | A Resonate Client instance |
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.
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 |