is now available! Read about the new features and fixes from November.

Polyglot Notebooks in VS Code

What is Polyglot Programming?

Polyglot programming is the practice of using multiple programming languages to leverage the strength of each language for different tasks.

What are Notebooks?

Notebooks are interactive files that allow the mixing of executable code, visualizations, equations, and narrative text. Notebooks are composed of code cells that make it easy to quickly iterate on code. Popularized by the open-source project Jupyter, they have become the de facto tool for Python data science and a great resource for teaching or learning a new programming language and quick prototyping.

Polyglot Notebooks

When polyglot programming meets notebooks, you get Polyglot Notebooks! As opposed to traditional notebooks that are typically used with Python, the Polyglot Notebooks extension allows you to use multiple programming languages natively all in the same notebook in Visual Studio Code! No more needing wrapper libraries or magic commands to work with your favorite languages in the same notebook!

Polyglot Notebooks Extension

Languages supported

  • C#
  • F#
  • PowerShell
  • JavaScript
  • HTML
  • Mermaid
  • SQL
  • KQL (Kusto Query Language)

Features

In addition to executing the code for the languages above, you can take advantage of:

  • Connecting to and querying from Microsoft SQL Server databases and Kusto clusters.

  • Language server support such as IntelliSense, autocompletion, and syntax highlighting for each language.

  • Variable sharing between languages that ensures a continuous workflow within the notebook. (Variable sharing not available for HTML and Mermaid)

  • Variable Explorer to check state of variables and the subkernel variables exist in.

  • Full portability between Jupyter/JupyterLab.

To learn about all the features, visit the VS Code Marketplace Polyglot Notebooks extension.

Prerequisites

To use Polyglot Notebooks in VS Code, you will need:

Why do I need the .NET SDK?

The Polyglot Notebooks extension is powered by .NET Interactive, which is a cutting edge and innovative engine built on .NET technology that can run multiple languages and share variables between them. In Polyglot Notebooks, this engine behaves as the notebook's kernel and is the reason that the .NET 7 SDK is required.

Getting started

  1. To create your first polyglot notebook, open the Command Palette (⇧⌘P (Windows, Linux Ctrl+Shift+P)) and select Polyglot Notebooks: Create new blank notebook, select .ipynb, and select the language you'd like to start with.

    You can also create a notebook by creating a new file and giving it the extension .ipynb. In this case, make sure that .NET Interactive is selected as the kernel of the notebook in the top right.

    Kernel Picker

  2. By default, added cells will be the same language as the cell above it. To change the language, select the language picker in the bottom right of the cell.

    Cell Language Picker

  3. Get coding!

    Example of Polyglot Notebook

Working with data

Connect to and query Microsoft SQL Server databases and Kusto clusters.

To get more detailed instructions on connecting to and working with data sources, visit the Working with Data documentation.

Connecting to SQL Example

Language server support

Each language in Polyglot Notebooks gets a first-class editing experience with language server support such as autocompletion, syntax highlighting, and signature help.

Variable Sharing and Variable Explorer

Share variables between languages using the #!set command and check on the values of variables for each language using the Variable explorer. Note that if you were previously using the #!share command, it will continue to work. Select the Variables icon in the global toolbar to open the Variable explorer.

To learn more about variable sharing, visit the Variable Sharing documentation.

Feature requests and feedback

The Polyglot Notebooks extension is powered by .NET Interactive and you can provide feedback and enter issues on the .NET Interactive GitHub repository.