March 15th, 2023

Announcing Polyglot Notebooks! Multi-language notebooks in Visual Studio Code

Claudia Regio
Product Manager

We are excited to announce that Polyglot Notebooks, Visual Studio Code’s multi-language notebook extension, is now generally available in the VS Code Marketplace!

Please note: While the Polyglot Notebooks extension in Visual Studio Code is now generally available, the .NET Interactive APIs that power it are still in preview.

What are Notebooks?

If you’re not familiar with notebooks – stop here! A notebook is an interactive programming and computational file that supports mixing executable code, visualizations, equations, and narrative text. Contrary to scripts that need to be run in their entirety, notebooks have code cells that allow code to be run in an incremental and segmented manner. Popularized by the open-source Project Jupyter, you may have heard of these referred to as ‘Jupyter Notebooks’. The component responsible for running code in a notebook is a kernel, and traditionally, Jupyter Notebooks have been most commonly used with Python kernels. Their ability to quickly iterate on code and create visualizations with narrative text have led them to become the de facto tool for data science and great tools for teaching or learning a new programming language, and quick prototyping.

Classic Jupyter Notebook

What are Polyglot Notebooks?

Polyglot notebooks elevate notebooks to a whole new level. Polyglot Notebooks’ philosophy is that developers should always be able to choose the best language for the task at hand and today using multiple languages in a traditional notebook is quite cumbersome. You may have a few options through magic commands and wrapper libraries, but both fall victim to a poor editing experience as they lack syntax highlighting, autocompletion and signature help. With Polyglot Notebooks, not only can you use multiple languages natively within the same notebook with full language server support, but you can also share variables between them to maintain a continuous workflow. No need to bounce around from tool to tool and manually transfer data between tools to continue your work.

*It is important to note that Polyglot Notebooks in VS Code are powered by .NET Interactive, which is an innovative engine built using .NET technology that can run multiple languages and share variables between them. Since it is capable of behaving as a kernel in the context of notebooks, .NET Interactive lights up the Polyglot Notebooks experience.

The Polyglot Notebooks extension in VS Code currently supports the following languages with more to come:

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

*Variable sharing not available

For example, developers using Polyglot Notebooks in VS Code today can connect to and query a Microsoft SQL Server database, share the tabular result to JavaScript, and create visualizations all within the same tool and the same notebook.

Polyglot Notebook Features

Connect to and query Microsoft SQL Server Databases and Kusto Clusters

Polyglot Notebooks currently has support for connecting to and querying Microsoft SQL Server Databases and Kusto Clusters. After connecting, natively write your SQL or KQL (Kusto Query Language) code to run queries.

Connecting to MS SQL Server in Polyglot Notebooks

Language Server support for all languages

Language server support such as autocompletion, syntax highlighting, and signature help for all languages. Say goodbye to using wrapper libraries when wanting to use multiple languages in the same notebook, and say hello to natively writing code in your preferred language with a first-class editing experience.

Variable Sharing

Retire the archaic method of jumping from tool to tool and manually transferring data between them when completing one part of your workflow. When you’re done working with one language in Polyglot Notebooks, simply share any relevant variables to the next language and enjoy your continuous workflow in the same file. In the example below, raw SQL is being used to query a Microsoft SQL Server database, the tabular result is shared to JavaScript and HTML in order to create a custom interactive visualization.

Getting Started

To get started you will need the following:

  1. Visual Studio Code
  2. .NET 7 SDK
  3. Polyglot Notebooks Extension

Create your first notebook by opening the command palette (Ctrl+Shift+P in Windows, Cmd+Shift+P on iOS) and selecting “Polyglot Notebook: Create new blank notebook”, select ‘.ipynb’, and select the language you’d like to start with. You should see “.NET Interactive” in the top right as this indicates the kernel being used. To change the language of a cell being used, simply click on the language picker in the bottom right of the cell and choose your desired language. Last but not least, get coding!

Polyglot Notebook

Feedback

We are excited for you to try out Polyglot Notebooks! If you would like to provide any feedback, file any bugs, or request any features, please file an issue on the .NET Interactive GitHub repository. To learn more, visit our Polyglot Notebook Documentation.

Author

Claudia Regio
Product Manager

Product Manager

15 comments

Discussion is closed. Login to edit/delete existing comments.

  • Prashant Priyadarshi

    love it

  • Ruslan Shakirov

    Is it possible to run a notebook file from the CLI (without launching the editor)?

    • Jon SequeiraMicrosoft employee

      You can use dotnet repl for this right now. If there’s enough demand for the automation features there, we might consider including them directly in .NET Interactive, so please let us know what you think.

      • Ruslan Shakirov · Edited

        I think, polyglot notebooks could be used as a more convenient alternative to modern CI/CD pipelines based on yaml/json declarative languages.
        Polyglot notebook is much easier to write and debug, it produces a meaningful output, so I would like to integrate it with my build pipelines.

  • Ken Foubert

    Are there plans to add additional languages?

      • Luis Joaquín Guzmán Hernández

        Why not Python?

      • Claudia RegioMicrosoft employee Author

        Python is on the way 🙂

        We are currently in the process of getting feedback from some early testers. If you’d like to get the instructions to try it out and provide feedback please email dotnetInteractive@microsoft.com

      • Luis Joaquín Guzmán Hernández

        Tried to email the request, but delivery failed.

  • Garlon Arthur
     Cmd+Shift+P on iOS

    I think you probably meant macOS, not iOS? Of course if this works on my iPad, then I’m getting excited!

  • Andrey Kurdyumov

    I really was surprised how easy it was to extend Polyglot Notebooks with your own language. For these who really wat polyglot experience, and not only based on English keywords you can try https://github.com/kant2002/fsharp-ua-notebook which show you F# in Ukrainian. Truly remarkable how easy it was to extend this product.

  • Ken Arthur

    In the article, you say “In the example below, raw SQL is being used to query a Microsoft SQL Server database, the tabular result is shared to JavaScript and HTML in order to create a custom interactive visualization.” – however the example is missing. Could you post it please? This is an issue I’ve been trying to learn more about.

  • Emmanuel Adebiyi

    Glad to see this hit GA. It has been one of my favourite products from MS for a while now