# Configure apps

> **📝 Note**
>
> An LLM-optimized bundle of this entire section is available at [`section.md`](https://www.union.ai/docs/v2/union/user-guide/configure-apps/section.md).
> This single file contains all pages in this section, optimized for AI coding agent context.

`[[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.

There are two ways to build apps in Flyte:
1. Defining `AppEnvironment(.., args=[...])` to run the app with the underlying `fserve` command.
2. Defining `@app_env.server` to run the app with a custom server function.

### Using fserve args

```
# /// script
# requires-python = "==3.13"
# dependencies = [
#    "flyte>=2.0.0b52",
# ]
# ///

import flyte
import flyte.app

# {{docs-fragment image}}
image = flyte.Image.from_debian_base(python_version=(3, 12)).with_pip_packages("streamlit==1.41.1")
# {{/docs-fragment image}}

# {{docs-fragment app-env}}
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"),
)
# {{/docs-fragment app-env}}

# {{docs-fragment deploy}}
if __name__ == "__main__":
    flyte.init_from_config()

    # Deploy the app
    app = flyte.serve(app_env)
    print(f"App served at: {app.url}")
# {{/docs-fragment deploy}}
```

*Source: https://github.com/unionai/unionai-examples/blob/main/v2/user-guide/configure-apps/hello-world-app.py*

This example demonstrates:

- Creating a custom Docker image with Streamlit
- Setting the `args` to run the Streamlit hello app, which uses the underlying `fserve` command to run the app.
- Configuring the port
- Setting resource limits
- Disabling authentication (for public access)
- Using a custom subdomain

### Using @app_env.server

```
# /// script
# requires-python = "==3.13"
# dependencies = [
#    "flyte>=2.0.0b52",
# ]
# ///

import flyte
import flyte.app

# {{docs-fragment image}}
image = flyte.Image.from_debian_base(python_version=(3, 12)).with_pip_packages("streamlit==1.41.1")
# {{/docs-fragment image}}

# {{docs-fragment app-env}}
app_env = flyte.app.AppEnvironment(
    name="hello-world-app-server",
    image=image,
    port=8080,
    resources=flyte.Resources(cpu="1", memory="1Gi"),
    requires_auth=False,
    domain=flyte.app.Domain(subdomain="hello-server"),
)

@app_env.server
def server():
    import subprocess
    subprocess.run(["streamlit", "hello", "--server.port", "8080"], check=False)
# {{/docs-fragment app-env}}

# {{docs-fragment deploy}}
if __name__ == "__main__":
    flyte.init_from_config()

    # Deploy the app
    app = flyte.serve(app_env)
    print(f"App served at: {app.url}")
# {{/docs-fragment deploy}}
```

*Source: https://github.com/unionai/unionai-examples/blob/main/v2/user-guide/configure-apps/hello-world-app-server.py*

This example demonstrates:

- Creating a custom Docker image with Streamlit
- Using the `@app_env.server` decorator to define a server function that runs 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 |
| `parameters` | ✅ | ❌ | Parameters 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](https://www.union.ai/docs/v2/union/user-guide/task-configuration/_index) docs for details on these shared parameters.

## Configuration topics

Learn more about configuring apps:

- [**Environment settings**](https://www.union.ai/docs/v2/union/user-guide/configure-apps/app-environment-settings/page.md): Images, resources, secrets, and app-specific settings like `type`, `port`, `args`, `requires_auth`
- [**App startup**](https://www.union.ai/docs/v2/union/user-guide/configure-apps/app-environment-settings/page.md#app-startup): Understanding the difference between `args` and `command`
- [**Including additional files**](https://www.union.ai/docs/v2/union/user-guide/configure-apps/including-additional-files/page.md): How to include additional files needed by your app
- [**App parameters**](https://www.union.ai/docs/v2/union/user-guide/configure-apps/passing-parameters/page.md): Pass parameters to your app at deployment time
- [**Autoscaling apps**](https://www.union.ai/docs/v2/union/user-guide/configure-apps/app-environment-settings/page.md#scaling): Configure scaling up and down based on traffic with idle TTL
- [**App depending on other environments**](https://www.union.ai/docs/v2/union/user-guide/configure-apps/apps-depending-on-environments/page.md): Use `depends_on` to deploy dependent apps together

## Subpages

- [App environments](https://www.union.ai/docs/v2/union/user-guide/configure-apps/app-environment-settings/page.md)
  - Shared environment settings
  - App-specific environment settings
  - `type`
  - `port`
  - `args`
  - `command`
  - `requires_auth`
  - `domain`
  - `links`
  - `include`
  - `parameters`
  - `scaling`
  - `depends_on`
  - App startup
  - Server decorator via `@app_env.server`
  - Container command via `command` vs `args`
  - Shared settings
- [Including additional files](https://www.union.ai/docs/v2/union/user-guide/configure-apps/including-additional-files/page.md)
  - How include works
  - When to use include
  - Examples
  - Multi-file Streamlit app
  - Multi-file FastAPI app
  - App with configuration files
  - File discovery
  - Path resolution
  - Best practices
  - Limitations
- [Passing parameters into app environments](https://www.union.ai/docs/v2/union/user-guide/configure-apps/passing-parameters/page.md)
  - Parameter types overview
  - Basic parameter types
  - Delayed values
  - RunOutput
  - AppEndpoint
  - Overriding parameters at serve time
  - Example: FastAPI app with configurable model
  - Example: Using RunOutput for model serving
  - Accessing parameters in your app
  - Best practices
  - Limitations
- [Autoscaling apps](https://www.union.ai/docs/v2/union/user-guide/configure-apps/auto-scaling-apps/page.md)
  - Autoscaling apps
  - Scaling configuration
  - Basic scaling example
  - Scaling patterns
  - Idle TTL (Time To Live)
  - Autoscaling best practices
  - Autoscaling limitations
  - Autoscaling troubleshooting
- [Apps depending on other environments](https://www.union.ai/docs/v2/union/user-guide/configure-apps/apps-depending-on-environments/page.md)
  - Basic usage
  - Example: App calling another app
  - Dependency chain
  - Multiple dependencies
  - Using AppEndpoint for dependency URLs
  - Deployment behavior
  - Task environment dependencies
  - Best practices
  - Example: A/B testing with dependencies
  - Limitations

---
**Source**: https://github.com/unionai/unionai-docs/blob/main/content/user-guide/configure-apps/_index.md
**HTML**: https://www.union.ai/docs/v2/union/user-guide/configure-apps/
