Export and import Databricks notebooks

This page describes how to import and export notebooks in Azure Databricks and the notebook formats that Azure Databricks supports.

Supported notebook formats

Databricks can import and export notebooks in the following formats:

  • Source file: A file containing only source code statements with the extension .scala, .py, .sql, or .r.
  • HTML: An Azure Databricks notebook with the extension .html.
  • Databricks .dbc archive.
  • IPython notebook: A Jupyter notebook with the extension .ipynb.
  • RMarkdown: An R Markdown document with the extension .Rmd.

Import a notebook

You can import an external notebook from a URL or a file. You can also import a ZIP archive of notebooks exported in bulk from an Azure Databricks workspace.

  1. Click Workspace Icon Workspace in the sidebar. Do one of the following:
    • Right-click on a folder and select Import.
    • To import a notebook at the top level of the current workspace folder, click the kebab menu at the upper right and select Import.
  2. Specify the URL or browse to a file containing a supported external format or a ZIP archive of notebooks exported from an Azure Databricks workspace.
  3. Click Import.
    • If you choose a single notebook, it is exported in the current folder.
    • If you choose a DBC or ZIP archive, its folder structure is recreated in the current folder and each notebook is imported.

Import a file and convert it to a notebook

You can convert Python, SQL, Scala, and R scripts to single-cell notebooks by adding a comment to the first cell of the file:

Python

# Databricks notebook source

SQL

-- Databricks notebook source

Scala

// Databricks notebook source

R

# Databricks notebook source

To define cells in a script, use the special comment shown below. When you import the script to Databricks, cells are created as marked by the COMMAND lines shown.

Python

# COMMAND ----------

SQL

-- COMMAND ----------

Scala

// COMMAND ----------

R

# COMMAND ----------

Export notebooks

Note

When you export a notebook as HTML, IPython notebook (.ipynb), or archive (DBC), and you have not cleared the command outputs, the outputs are included in the export.

To export a notebook, select File > Export in the notebook toolbar and select the export format.

To export all folders in a workspace folder as a ZIP archive:

  1. Click Workspace Icon Workspace in the sidebar.
  2. Right-click the folder and select Export.
  3. Select the export format:
    • DBC Archive: Export a Databricks archive, a binary format that includes metadata and notebook command outputs.
    • Source File: Export a ZIP archive of notebook source files, which can be imported into an Azure Databricks workspace, used in a CI/CD pipeline, or viewed as source files in each notebook’s default language. Notebook command outputs are not included.
    • HTML Archive: Export a ZIP archive of HTML files. Each notebook’s HTML file can be imported into an Azure Databricks workspace or viewed as HTML. Notebook command outputs are included.