Skip to main content
Apps are the top-level organizational unit in Modal. They contain Functions, Classes, and other resources.

Referencing apps

FromName

References an App by its name, optionally creating it if it doesn’t exist.
app, err := mc.Apps.FromName(ctx, "my-app", &modal.AppFromNameParams{
    CreateIfMissing: true,
})
if err != nil {
    // Handle error
}
ctx
context.Context
required
Context for the operation
name
string
required
The name of the App
params
*AppFromNameParams
Optional parameters
Environment
string
Environment name (e.g., “main”, “dev”). Defaults to client’s environment.
CreateIfMissing
bool
If true, creates the App if it doesn’t exist. Defaults to false.
Returns:
  • *App - The App instance
  • error - NotFoundError if the App doesn’t exist and CreateIfMissing is false

App type

The App type represents a deployed Modal App.
AppID
string
The unique identifier for the App
Name
string
The name of the App

Example usage

package main

import (
    "context"
    "fmt"

    "github.com/modal-labs/modal-client/go"
)

func main() {
    ctx := context.Background()
    mc, _ := modal.NewClient()
    defer mc.Close()

    // Reference an existing App
    app, err := mc.Apps.FromName(ctx, "my-app", nil)
    if err != nil {
        fmt.Printf("App not found: %v\n", err)
        return
    }

    fmt.Printf("App ID: %s\n", app.AppID)
    fmt.Printf("App Name: %s\n", app.Name)

    // Create an App if it doesn't exist
    app2, _ := mc.Apps.FromName(ctx, "new-app", &modal.AppFromNameParams{
        CreateIfMissing: true,
    })
    fmt.Printf("Created/Retrieved App: %s\n", app2.AppID)
}

Build docs developers (and LLMs) love