Configure Databricks app execution with app.yaml
The app.yaml
file in a Databricks app defines how your app is executed. If your app requires a different entry point or environment-specific configuration, you can include this optional file in your project to override the default behavior.
You can use the .yaml
or .yml
file extension. This file must be located in the root of your project directory.
Supported settings
The app.yaml
file supports the following settings.
Setting | Type | Description |
---|---|---|
|
| Use this setting when you require a custom command to run your app. By default, Databricks runs Python apps using the command Because Databricks doesn't run the command in a shell, it doesn't pass environment variables defined outside the app configuration to your app. If your app requires additional parameters to run, use the This setting is optional. |
|
| Databricks automatically sets several default environment variables in the app runtime environment. This top-level key defines an optional list of additional environment variables to pass to your app. Each variable can use a hardcoded value or reference an external source, such as a secret or database entry. The valid items in the list are:
This setting is optional. |
Example app.yaml
for a Streamlit app
The following app.yaml
file shows how to configure a Streamlit app. It uses a custom command to start the app with streamlit run
, and it sets environment variables for the SQL warehouse ID and a usage tracking flag.
command: ['streamlit', 'run', 'app.py']
env:
- name: 'DATABRICKS_WAREHOUSE_ID'
value: 'quoz2bvjy8bl7skl'
- name: 'STREAMLIT_GATHER_USAGE_STATS'
value: 'false'
Use a setup like this if your app depends on a specific compute resource, such as a SQL warehouse, or requires certain environment variables to control runtime behavior.
Example app.yaml
for a Flask app
This example shows how to configure a Flask app using the Gunicorn server. The command
setting specifies the Gunicorn startup parameters, and the env
section sets the path to a Unity Catalog volume as an environment variable.
command:
- gunicorn
- app:app
- -w
- 4
env:
- name: 'VOLUME_URI'
value: '/Volumes/catalog-name/schema-name/dir-name'
Use this approach when your app needs a production-ready WSGI server like Gunicorn and when it depends on data stored in a Unity Catalog volume or another environment-specific path.