Configure apps

[[AppEnvironment]]s allows you to configure the environment in which your app runs, including the container image, compute resources, secrets, domains, scaling behavior, and more.

Similar to [[TaskEnvironment]], configuration can be set when creating the [[AppEnvironment]] object. Unlike tasks, apps are long-running services, so they have additional configuration options specific to web services:

  • port: What port the app listens on
  • command and args: How to start the app
  • scaling: Autoscaling configuration for handling variable load
  • domain: Custom domains and subdomains for your app
  • requires_auth: Whether the app requires authentication to access
  • depends_on: Other app or task environments that the app depends on

Hello World example

Here’s a complete example of deploying a simple Streamlit “hello world” app with a custom subdomain:

hello-world-app.py
"""A basic "Hello World" app example with custom subdomain."""

import flyte
import flyte.app

image = flyte.Image.from_debian_base(python_version=(3, 12)).with_pip_packages("streamlit==1.41.1")

app_env = flyte.app.AppEnvironment(
    name="hello-world-app",
    image=image,
    args=["streamlit", "hello", "--server.port", "8080"],
    port=8080,
    resources=flyte.Resources(cpu="1", memory="1Gi"),
    requires_auth=False,
    domain=flyte.app.Domain(subdomain="hello"),
)

if __name__ == "__main__":
    flyte.init_from_config()
    
    # Deploy the app
    app = flyte.serve(app_env)
    print(f"App served at: {app.url}")


This example demonstrates:

  • Creating a custom Docker image with Streamlit
  • Setting the args to run the Streamlit hello app
  • Configuring the port
  • Setting resource limits
  • Disabling authentication (for public access)
  • Using a custom subdomain

Once deployed, your app will be accessible at the generated URL or your custom subdomain.

Differences from TaskEnvironment

While AppEnvironment inherits from Environment (the same base class as TaskEnvironment), it has several app-specific parameters:

Parameter AppEnvironment TaskEnvironment Description
type Type of app (e.g., “FastAPI”, “Streamlit”)
port Port the app listens on
args Arguments to pass to the app
command Command to run the app
requires_auth Whether app requires authentication
scaling Autoscaling configuration
domain Custom domain/subdomain
links Links to include in the App UI page
include Files to include in app
inputs Inputs to pass to app
cluster_pool Cluster pool for deployment

Parameters like image, resources, secrets, env_vars, and depends_on are shared between both environment types. See the task configuration docs for details on these shared parameters.

Configuration topics

Learn more about configuring apps: