modal.Cls
Cls adds method pooling and lifecycle hook behavior to modal.Function.
Generally, you will not construct a Cls directly.
Instead, use the @app.cls() decorator on the App object.
hydrate
Synchronize the local object with its identity on the Modal server.
It is rarely necessary to call this method explicitly, as most operations will lazily hydrate when needed. The main use case is when you need to access object metadata, such as its ID.
Added in v0.72.39: This method replaces the deprecated .resolve() method.
from_name
Reference a Cls from a deployed App by its name.
This is a lazy method that defers hydrating the local object with metadata from Modal servers until the first time it is actually used.
with_options
Override the static Function configuration at runtime.
This method will return a new instance of the cls that will autoscale independently of the
original instance. Note that options cannot be “unset” with this method (i.e., if a GPU
is configured in the @app.cls() decorator, passing gpu=None here will not create a
CPU-only instance).
Usage:
You can use this method after looking up the Cls from a deployed App or if you have a direct reference to a Cls from another Function or local entrypoint on its App:
The method can be called multiple times to “stack” updates:
Note that container arguments (i.e. volumes and secrets) passed in subsequent calls
will not be merged.
with_concurrency
Create an instance of the Cls with input concurrency enabled or overridden with new values.
Usage:
with_batching
Create an instance of the Cls with dynamic batching enabled or overridden with new values.
Usage: