What is Databricks Connect and when should I use it?
Summary
- Databricks Connect is a client library for the Databricks Runtime that lets you write Spark API code in an IDE, notebook server or custom application and run it on Databricks compute.
- Use it to develop and debug Spark code in your own IDE with its native run and debug tools, and to embed Databricks compute in an interactive data application, the way you'd embed a JDBC driver.
- It's built on open-source Spark Connect. DataFrame operations run on Databricks, while the rest of your Python or Scala code runs locally, so breakpoints work as usual.
- It's available for Python, Scala and R, requires a Unity Catalog-enabled workspace, and supports serverless compute starting with Databricks Connect version 15.1.
- Plan around its documented limits: RDDs, the Spark Context,
dataframe.display()and distributed ML training aren't supported.
What is Databricks Connect and when should I use it?
Databricks Connect is how you run Spark code on Databricks from outside the workspace. It's a client library that connects IDEs such as Visual Studio Code, PyCharm and IntelliJ IDEA, notebook servers and custom applications to Databricks compute. Use it when you want to write, run and debug code with your own local tools while the data processing happens on a Databricks cluster or serverless compute. It's also the right choice when an application needs Spark on Databricks behind it.
How Databricks Connect works
Databricks Connect is built on Spark Connect, the open-source, decoupled client-server architecture for Apache Spark. The protocol sends Spark unresolved logical plans over gRPC, with Apache Arrow for data, and the client is thin enough to embed in application servers, IDEs and notebooks. That design decides where each line of your code runs:
- General code runs locally. Your Python or Scala logic executes on your machine, so interactive debugging works.
- DataFrame operations run on Databricks. Transformations become Spark plans that execute on Databricks compute. Results come back to your machine only when you call methods such as
collect(),show()ortoPandas(). - UDFs run on Databricks. Locally defined UDFs are serialized and sent to the cluster, and the same applies to
foreach,foreachBatchandtransformWithState.
Dependencies follow the same split. Install application dependencies in your local virtual environment and UDF dependencies on Databricks. For Databricks Runtime 13.3 LTS and above, Databricks Connect extends Spark Connect with support for Databricks compute modes and Unity Catalog. It doesn't connect to open-source Apache Spark servers.
When to use Databricks Connect
| Scenario | Fit | Why |
|---|---|---|
| Developing and debugging Spark code in an IDE | Strong | Local code uses the IDE's native run and debug tools, and DataFrame work runs on Databricks |
| Building an interactive data app | Strong | The library embeds in any application, like a JDBC driver, with the full expressiveness of PySpark |
| Running code from a notebook server or the Spark shell | Good | Both are documented ways to use Databricks Connect for Python |
| Code that relies on RDDs or the Spark Context | Not supported | The docs list RDDs, Spark Context and libraries that depend on them as unavailable |
| Distributed ML training | Not supported | Listed as a Databricks Connect for Python limitation |
| Syncing your local environment with the cluster | Not supported | Manage local and UDF dependencies separately |
How to get started with Databricks Connect for Python
Check the requirements. Your Databricks account and workspace need Unity Catalog enabled. The Databricks Runtime version of your compute must be greater than or equal to your Databricks Connect package version, and Databricks recommends the most recent package that matches your runtime. If you use UDFs, your local Python minor version must match the compute's.
Install the client. Activate a Python virtual environment, uninstall PySpark if it's present (the package conflicts with it), then install a version that matches your compute:
pip install "databricks-connect==17.3.*"
Create a session and run code. This example from the Databricks serverless tutorial reads a sample table:
from databricks.connect import DatabricksSession
spark = DatabricksSession.builder.serverless().profile("<profile-name>").getOrCreate()
df = spark.read.table("samples.nyctaxi.trips")
df.show(5)
For production code, the docs recommend a session builder with no compute settings, DatabricksSession.builder.getOrCreate(). Set the target in your configuration profile instead, for example serverless_compute_id = auto, so the same code uses the default Spark session when it runs on Databricks.
Databricks Connect and the Databricks IDE extension
The Databricks IDE extension for Visual Studio Code and Cursor uses Databricks Connect for built-in debugging of user code on Databricks. It can build a local Python environment that matches your target compute and install a compatible Databricks Connect version for you, then debug Python files and notebook cells with breakpoints. In PyCharm, IntelliJ IDEA, a notebook server or your own application, install and use the library directly.
FAQs
Is Databricks Connect the same as Spark Connect?
No. Spark Connect is the open-source gRPC-based protocol in Apache Spark for remote execution with the DataFrame API. Databricks Connect builds on it with additions and modifications for Databricks compute modes and Unity Catalog.
Does Databricks Connect work with serverless compute?
Yes, starting with Databricks Connect version 15.1. Use DatabricksSession.builder.serverless() while developing, or set serverless_compute_id = auto in your configuration profile.
Which languages does Databricks Connect support?
Python, Scala and R. Each language has its own documentation and tutorial.
Why doesn't dataframe.display() work?
The display() API isn't available in Databricks Connect, and neither are some Databricks Utilities, such as widgets and notebook workflows. Use standard DataFrame methods such as show() to inspect results.
The information provided herein is for general informational purposes only and may not reflect the most current product capabilities or configurations.