modal.app

modal.app.App

class App(object)

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 app_id, 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)

client

@property
def client(self) -> _Client:

A reference to the running App’s server client.

app_id

@property
def app_id(self) -> str:

A unique identifier for this running App.

disconnect

def disconnect(self):

Tell the server the client has disconnected for this app. Terminates all running tasks for ephemeral apps.

stop

def stop(self):

Tell the server to stop this app, terminating all running tasks.

log_url

def log_url(self):

track_function_invocation

def track_function_invocation(self):

function_invocations

@property
def function_invocations(self):

init_container

@staticmethod
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.

create_one_object

def create_one_object(self, provider: _Provider) -> _Handle:

deploy

def deploy(self, name: str, namespace, object_entity: str) -> str:

modal.app.container_app

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()

@stub.function()
def store_something(key, value):
    data: modal.DictHandle = modal.container_app.data
    data.put(key, value)

modal.app.is_local

def is_local() -> bool:

Returns if we are currently on the machine launching/deploying a Modal app

Returns True when executed locally on the user’s machine. Returns False when executed from a Modal container in the cloud.