# How to Run PySpark and Databricks Code Locally (Delta Lake Included)

> Run PySpark and most Databricks notebook code on your laptop: Spark 3.5 with Delta Lake in Docker, what works the same, what to change (dbutils, display, Unity Catalog) and how to test.

Page: https://datautility.in/blog/run-pyspark-databricks-code-locally
This is the Markdown copy of the page. The tool itself runs in the browser: your files are processed on your own device and are not uploaded.

Published 2026-11-28 · Analyze & protect · run databricks code locally, pyspark local development, databricks local testing, delta lake local, dbutils locally, pyspark docker

Most Databricks code is plain PySpark and Delta Lake, and both run locally. The parts that are Databricks-only (dbutils, display(), Unity Catalog names, Photon) need a small change. The quickest local setup is Data Utility's Spark Lab: Spark 3.5 with Delta Lake 3.2 in Docker, with Delta switched on for every session.

Open the tool: [Spark Lab](https://datautility.in/sparklab)

## What runs the same

- DataFrame code, Spark SQL, window functions, UDFs.

- Delta Lake: `format("delta")`, `DeltaTable.forPath`, MERGE, UPDATE, DELETE, `versionAsOf`, `restoreToVersion`, `history()`.

- Reading and writing Parquet, CSV and JSON.

## What to change

| Databricks | Locally |
|---|---|
| `display(df)` | `df.show()` or `df.limit(20).toPandas()` |
| `dbutils.fs.ls(path)` | `os.listdir(path)` |
| `catalog.schema.table` (Unity Catalog) | a path such as `/data/outputs/table`, or `saveAsTable` in the local catalog |
| Widgets, secrets | plain variables or environment variables |

## Set it up

1. Install Docker Desktop and run the Set up and Start commands from the [Spark Lab](https://datautility.in/pyspark-spark-ui-lab).

2. Paste your code into a new file in the editor (My files), or download the VS Code workspace and open it as a Dev Container.

3. Put test files in /data/uploads, run, and check the Spark UI and the Delta log panel.

## Why test locally

It is free, fast to reset, and you can see every stage in the Spark UI. Bugs in joins, nulls and MERGE conditions show up on small data long before a cluster bill does.

## How to use the Spark Lab: step by step

1. Start the Spark Lab
2. Create a file under My files
3. Replace display() and dbutils calls
4. Run and check the Spark UI

## When to use the Spark Lab

- Unit-testing Databricks transformations
- Developing offline
- Debugging a slow join on sample data

## Frequently asked questions

### Can I run Databricks notebooks locally?
The PySpark and Delta code in them, yes. Databricks-only helpers such as dbutils and display() need small replacements.

### Does Delta Lake work locally?
Yes. In the Spark Lab image Delta Lake is enabled for every Spark session, including plain scripts and VS Code.

## Also try

- [Run PySpark in VS Code](https://datautility.in/blog/run-pyspark-in-vs-code-docker-dev-container)
- [Delta MERGE and time travel](https://datautility.in/blog/delta-lake-merge-time-travel-restore-pyspark)

## More guides

- [Data Profiler: Check Data Quality Before You Use It](https://datautility.in/blog/data-profiler-check-data-quality)
- [Compare Two CSV or Excel Files: Find Added, Removed and Changed Rows](https://datautility.in/blog/compare-two-csv-files-find-differences)
- [Data Masking: Hide Emails, Phones and Names Before Sharing](https://datautility.in/blog/data-masking-hide-emails-phones-pii)
