Skip to main content

Define environment variables in a Databricks app

Databricks automatically sets several environment variables in the app runtime environment. These variables provide essential information about the app and workspace and are accessible to all Databricks apps by default.

Default environment variables

The following default environment variables are available to every app:

Variable

Description

DATABRICKS_APP_NAME

The name of the running app.

DATABRICKS_WORKSPACE_ID

The unique ID for the Databricks workspace the app belongs to.

DATABRICKS_HOST

The URL of the Databricks workspace to which the app belongs.

DATABRICKS_APP_PORT

The network port the app should listen on.

DATABRICKS_CLIENT_ID

The client ID for the Databricks service principal assigned to the app.

DATABRICKS_CLIENT_SECRET

The OAuth secret for the Databricks service principal assigned to the app.

Define additional environment variables

If your app requires additional environment variables, define them explicitly in the app.yaml configuration file in the env section. Each variable requires a name and a value. For example:

YAML
env:
- name: 'API_KEY'
value: '12345abcde67890'
- name: 'LOG_LEVEL'
value: 'DEBUG'
- name: 'FEATURE_FLAG_NEW_UI'
value: 'true'

Default environment variables for Streamlit

If you use the Streamlit framework, the Databricks Apps environment pre-configures several Streamlit-specific environment variables:

Variable

Description

STREAMLIT_SERVER_ADDRESS

The server address for use by Streamlit. This value is set to 0.0.0.0 and must not be overridden.

STREAMLIT_SERVER_PORT

The port for use by Streamlit. This value is set to DATABRICKS_APP_PORT and must not be overridden.

STREAMLIT_SERVER_ENABLE_XSRF_PROTECTION

Because the Databricks Apps reverse proxy protects against Cross-Site Request Forgery (XSRF), this is set to false.

STREAMLIT_SERVER_ENABLE_CORS

Because the Databricks Apps reverse proxy protects against Cross-Origin Resource Sharing (CORS), This is set to false.

STREAMLIT_SERVER_HEADLESS

This is set to true so Streamlit runs without opening a browser window when starting.

STREAMLIT_BROWSER_GATHER_USAGE_STATS

This is set to false to prevent sending user stats to Streamlit.