modal.Cls
class Cls(modal.object.Object)
def __init__(self, *args, **kwargs):
from_id
@classmethod
def from_id(cls: Type[O], object_id: str, client: Optional[_Client] = None) -> O:
Retrieve an object from its unique ID (accessed through obj.object_id
).
persist
def persist(
self, label: str, namespace=api_pb2.DEPLOYMENT_NAMESPACE_WORKSPACE, environment_name: Optional[str] = None
):
Object.persist
is deprecated for generic objects. See NetworkFileSystem.persisted
or Dict.persisted
.
from_name
@classmethod
def from_name(
cls: Type[O],
app_name: str,
tag: Optional[str] = None,
namespace=api_pb2.DEPLOYMENT_NAMESPACE_WORKSPACE,
environment_name: Optional[str] = None,
) -> O:
Retrieve an object with a given name and tag.
Useful for referencing secrets, as well as calling a function from a different app. Use this when attaching the object to a stub or function.
Examples
# Retrieve a secret
stub.my_secret = Secret.from_name("my-secret")
# Retrieve a function from a different app
stub.other_function = Function.from_name("other-app", "function")
# Retrieve a persisted Volume, Queue, or Dict
stub.my_volume = Volume.from_name("my-volume")
stub.my_queue = Queue.from_name("my-queue")
stub.my_dict = Dict.from_name("my-dict")
lookup
@classmethod
def lookup(
cls: Type[O],
app_name: str,
tag: Optional[str] = None,
namespace=api_pb2.DEPLOYMENT_NAMESPACE_WORKSPACE,
client: Optional[_Client] = None,
environment_name: Optional[str] = None,
) -> O:
Lookup an object with a given name and tag.
This is a general-purpose method for objects like functions, network file systems, and secrets. It gives a reference to the object in a running app.
Examples
# Lookup a secret
my_secret = Secret.lookup("my-secret")
# Lookup a function from a different app
other_function = Function.lookup("other-app", "function")
# Lookup a persisted Volume, Queue, or Dict
my_volume = Volume.lookup("my-volume")
my_queue = Queue.lookup("my-queue")
my_dict = Dict.lookup("my-dict")
from_local
@staticmethod
def from_local(user_cls, base_functions: Dict[str, _Function]) -> "_Cls":
get_user_cls
def get_user_cls(self):
# Used by the container entrypoint
get_base_function
def get_base_function(self, k: str) -> _Function:
remote
def remote(self, *args, **kwargs) -> _Obj: