Skip to main content

Introducing Upgrades to Databricks Notebooks - New Editor, Python Formatting, and More

Weston Hutchins
Jim Allen Wallace
Deka Auliya Akbar
Share this post

Databricks Notebooks offers a simple, unified environment for anyone building Data and AI products. Today we are excited to introduce updates to the Notebooks experience:

  1. New editor with faster autocomplete, improved syntax highlighting, code collapsing and more to help you code faster
  2. Python Code Formatter using Black to make code easier to read and review
  3. Run Selected Text inside Notebooks to accelerate debugging

New notebook editor

Our new editor enables many features for users that make coding easier, faster, and less error-prone. We want you to be able to seamlessly move from the IDE to the browser and have access to a similar user experience. We have adopted Monaco, the open source editor that powers Microsoft's VS Code to make your life easier.

Autocomplete-as-you-type

Previously you needed to manually activate the autocomplete suggestion box by hitting Shift+Tab. Now, with the new editor, the autocomplete suggestion box will appear automatically as you type.

auto complete

The autocomplete function not only works for symbols like Python methods and attributes, but it will also provide table and column names in SQL statements. It also recognizes and adds Databricks SQL functions from the tokenizer. This lets you reduce errors and grab the right object the first time.

Parameter hints

Get a helpful reminder of the function call arguments with inline parameter hints.

Mac: Shift-Cmd-Space
Windows: Ctrl-Shift-Space

See what parameters are needed inside of functions

Docstrings on hover

You can now hover over types and functions in your code to display the docstrings.

Hover over a function to see the docstring

Syntax highlighting

Having properly highlighted code makes coding, editing, and troubleshooting much faster. In the Monaco editor, we do a better job highlighting the tokens in your code cells.

Syntax highlighting

Code collapsing

Code folding lets you temporarily hide sections of code. This can be helpful when working with long code blocks because it lets you focus on specific sections of code you are working on.

Code collapsing

Multiple cursors

You can add multiple cursors for fast, simultaneous edits. This common shortcut makes editing easier when you have a series of similar inputs and want to change them together. You can add additional cursors with Alt-click in the editor window or by pressing ⌥⌘↓ or ⌥⌘↑ on Macs or Ctrl-Alt-Down or Ctrl-Alt-Up on Windows.

Multi cursor

Toggle line comment

You can toggle comments on a line of code or for multiple lines of code at once. To do so, select the desired lines of code and hit the shortcut for your operating system.

Mac: Cmd-/
Windows: Ctrl-/

Toggle comment

Additionally, you can use block comments if your language supports it.

Mac: Option-Shift-A
Windows: Option-Shift-A

block quote

Column (box) selection

Column Selection is very handy when you need to edit a whole column of text. To do so, place the cursor in one corner and then hold Option-Shift (Mac) / Alt-Shift (Windows) while dragging to the opposite corner to create a selection.

column selection

Bracket matching

When you click near a parenthesis, square bracket, or curly brace, the editor highlights that character and its matching bracket so you can make sure you have complete and matching sets.

Bracket matching

Side-by-side diff in version history

When displaying a previous version of your notebook, the new notebook editor will display side-by-side diffs to easily see what changed.

Diff

Python code formatting

Databricks now supports Black, a PEP 8 compatible code formatter. Black formats all code the same so you spend less time formatting and more time creating what matters. All Black-formatted code is styled the same, regardless of what project you are reviewing, so code reviews go faster too.

To use Black, connect to a cluster on DBR 11.2 or later. You can format a single Python cell by clicking on the cell Edit menu, indicated by the down chevron, and clicking "Format Python". You can also format multiple selected cells or the entire notebook by clicking on the global Edit menu in the header and selecting "Format cell(s)" or "Format notebook" respectively.

Python formating

Run selected text

While troubleshooting a long block of code, it can be helpful to only execute a few lines. Databricks now supports "Run selected text" in Notebooks. You can highlight one or more lines within a cell, open the Run menu, and select "Run selected text" to execute only those lines. This ensures that you can test the smallest portion of code to identify and fix any errors there, to reduce the time you spend debugging.

Run selected

Enabling the new notebook editor

Our new editor is now in preview and available to the public but is not enabled by default. To enable the new editor in the Notebook:

  1. Click your username at the top right of the workspace and select User Settings from the drop down.
  2. Click the Notebook Settings tab.
  3. Check the box next to Turn on the new notebook editor.

To try it out yourself, import the example notebook in this repo into your Databricks workspace.

In summary

At Databricks, we continually work to improve the development experience for all our users. The Notebook is the front door of the Databricks Lakehouse, and we want it to be the best data-native development tool in the market. Earlier this year, we simplified the UI, improved Jupyter compatibility, and added Bamboolib for analysis and visualizations.

This is just the start. Our new editor for Notebooks also opens the door to future potential improvements for language services that will allow us to improve our Notebooks developer experience even more throughout 2023.

Try Databricks for free

Related posts

See all Platform Blog posts