Skip to main content

How do I connect an app to my lakehouse?

Summary

  • Add your data source as an app resource. For lakehouse tables, attach a SQL warehouse; for transactional data, attach a Lakebase (managed Postgres) database.
  • Databricks Apps get a managed service principal and inject connection details as environment variables, so you do not hand-manage credentials or connection strings.
  • Grant the app's service principal the right privilegesSELECT (and MODIFY to write) on the Unity Catalog tables and CAN USE on the SQL warehouse.
  • Query Unity Catalog Delta tables from your app code with the Databricks SQL Connector for Python or the Databricks SDK.
  • Register a Lakebase database in Unity Catalog (using a serverless SQL warehouse) to query transactional and Delta tables together.

How do I connect an app to my lakehouse?

Databricks Apps run inside your workspace with integrated, governed access to lakehouse data. You connect an app to your data by attaching a resource — most commonly a SQL warehouse for querying Unity Catalog Delta tables, or a Lakebase database for transactional (Postgres) data. Databricks provisions a service principal for the app and injects the connection details as environment variables, so your code connects without you managing secrets or connection strings.

Why connect apps to the lakehouse with Databricks Apps

  • Managed identity and injected connection details. When you add a resource to an app, Databricks automatically creates a service principal for the app and supplies the connection information (such as the warehouse HTTP path) through environment variables. This removes manual credential management.
  • Governed access through Unity Catalog. Grant the app's service principal explicit privileges: SELECT (and MODIFY if the app writes) on the tables it uses, and CAN USE on the SQL warehouse. Access stays governed by Unity Catalog, with lineage and access control applied consistently. See Configure privileges.
  • Query Delta tables from your code. Use the Databricks SQL Connector for Python (or the Databricks SDK) to run queries against Unity Catalog tables. A minimal pattern using the injected warehouse HTTP path looks like this:
from databricks import sql

with sql.connect(
    server_hostname="<workspace-hostname>",
    http_path="<sql-warehouse-http-path>",
) as connection:
    with connection.cursor() as cursor:
        cursor.execute("SELECT * FROM `catalog`.`schema`.`table`")
        rows = cursor.fetchall()
  • Transactional data with Lakebase. For low-latency reads and writes, attach a Lakebase (managed Postgres) database as an app resource; the app connects to Postgres directly through the injected configuration.
  • Query transactional and analytical data together. register a Lakebase database in Unity Catalog to query its tables alongside Delta tables in a single query. This registration path uses a serverless SQL warehouse. You can also serve lakehouse data with synced tables to keep an operational copy in sync for your app.

Getting started

FAQs

How does a Databricks App authenticate to my data?

When you add a resource to the app, Databricks creates a service principal for it and injects the connection details as environment variables. You grant that service principal privileges on the tables and warehouse it needs.

How do I query Unity Catalog tables from my app?

Attach a SQL warehouse as an app resource, grant the app's service principal SELECT on the tables and CAN USE on the warehouse, then run queries with the Databricks SQL Connector for Python or the Databricks SDK.

Can my app read both transactional and analytical data?

Yes. Register a Lakebase database in Unity Catalog using a serverless SQL warehouse, and you can query its transactional tables alongside Delta tables in the same query.

Do I need to manage connection strings and secrets?

No. Databricks provisions a service principal for the app and injects the connection details as environment variables, so you do not hand-manage credentials or connection strings.

The information provided herein is for general informational purposes only and may not reflect the most current product capabilities or configurations.