Sitemap

Member-only story

Notebooks as files

2 min readMar 1, 2025

--

Access for free via a friend’s link

Starting with Databricks Runtime 16.2, notebooks are treated like regular files and the workspace is a regular folder. You can open, move, or modify them like any other file. For developers, this means:

Programmatic Notebook Creation: Use Python’s file I/O to create new notebooks.
Logging to Local Files: Save logs right next to your notebooks.
Git Integration: remember about .gitignore to avoid the mess which you will make this way
Drag and Drop: Easily move notebooks in the workspace by dragging them around or doing any file operations you can imagine.

Below is a concise example that demonstrates:
- Creating a folder and placeholder notebook file programmatically (thanks to Lucas Jurgensen for fixing my code).
- Setting up logging to a file.
- Generating a .gitignore to ignore logs and temp files.

# Step 1: Create /temp directory and a placeholder notebook file
import os

os.makedirs("temp", exist_ok=True)

# databricks source notebook
placeholder_path = os.path.join("temp", "placeholder_source_notebook.py")
with open(placeholder_path, "w") as f:
f.write("# Databricks notebook source\n")
f.write("# Placeholder notebook content\n")
f.write("print('Hello from the placeholder notebook!')\n")
print(f"Created notebook: {placeholder_path}")

# Step 2: Configure Logging and Write a Test Message
import logging…

--

--

Responses (2)