How to Run PySpark and Databricks Code Locally (Delta Lake Included)
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.
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.
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.
Also try
How to use the Spark Lab: step by step
- Start the Spark Lab
- Create a file under My files
- Replace display() and dbutils calls
- 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.