Apps are the user representation of an actively running Modal process.
You can obtain an
App from the
Stub.run() context manager. While the app
is running, you can get its
client, and other useful properties
from this object.
import modal stub = modal.Stub() stub.my_secret_object = modal.Secret.from_name("my-secret") if __name__ == "__main__": with stub.run() as app: print(app.client) print(app.app_id) print(app.my_secret_object)
def client(self) -> _Client:
A reference to the running App’s server client.
def app_id(self) -> str:
A unique identifier for this running App.
Tell the server the client has disconnected for this app. Terminates all running tasks for ephemeral apps.
Tell the server to stop this app, terminating all running tasks.
def init_container(client: _Client, app_id: str, stub_name: str = "") -> "_App":
Used by the container to bootstrap the app and all its objects. Not intended to be called by Modal users.
def create_one_object(self, provider: _Provider) -> _Handle:
def deploy(self, name: str, namespace, object_entity: str) -> str:
A reference to the running
modal.App, accessible from within a running Modal function.
Useful for accessing object handles for any Modal objects declared on the stub, e.g:
stub = modal.Stub() stub.data = modal.Dict() def store_something(key, value): data: modal.DictHandle = modal.container_app.data data.put(key, value)
def is_local() -> bool:
Returns if we are currently on the machine launching/deploying a Modal app
True when executed locally on the user’s machine.
False when executed from a Modal container in the cloud.