Have you ever wanted to write code in a web browser without having to save it locally or in source control to share it? It's quite common in the learning space for many instructors, primarily for the sharing bit, without committing the code to source control. Sometimes you want to share code with someone who maybe doesn't have a GitHub account.

Azure Notebooks allows developers, data scientists, students, and all-around engineers to create code files, equations, code output and even live code files. If you're familiar with Jupyter Notebooks, Azure Notebooks is a hosted service for Jupyter.  

In this blog post you will learn how to get started with Azure Notebooks and use Python3 code in an Azure Notebook.

Prerequisites

To follow along in this blog post from a hands-on perspective, you should have the following:

  • An Azure subscription. If you don't have one, you can set up a 30-day free trial here.
  • A beginner to intermediate level understanding of Python.

Language Support

Although Azure Notebooks is powerful, it currently does not support all languages. Let's break down the languages that it does support.

  • Python - Python is a programming and scripting language created in 1989. With Python, you can pretty much do anything. Backend applications, frontend applications, APIs, automation etc..
  • R - R is a programming language specifically around statistical computing and graphics. It's primarily in the data science community and very popular.
  • F# - A programming language that encompasses functional imperative and object-oriented programming. F#, like R, is great for specific areas like scientific or data analysis, but it can be used for enterprise development too. For example, F# can be used to generate JavaScript and graphics processing unit code.
Source: https://docs.microsoft.com/en-us/azure/notebooks/azure-notebooks-overview

Pricing

In the previous section you learned about the language support that is available in Azure Notebooks. Now you will learn about the pricing.

At the time of writing this... it's free! Yep, free free. When you set up an Azure Notebook, it is free to develop and run Jupyter notebooks in the cloud with zero installation needed. With Azure Notebooks being free, it has a limited capacity of power at the starting point.

Source: https://docs.microsoft.com/en-us/azure/notebooks/azure-notebooks-overview

An Azure Notebook is limited to 4GB of memory and 1GB of data to prevent abuse on the preview-rich platform. If you reach that limit, you will be presented with a captcha challenge to continue running the notebook. That means if you're a robot, you may or may not be able to go past that limit.

Setting up Your First Project

Now that you know all about the pricing and quotas around Azure Notebooks, it's time to get to the hands-on material! In this section you'll set up an Azure Notebook project, let's get started.

The first thing you will need to do is go to the Azure Notebooks page and click the blue TRY IT NOW button.

After clicking the blue TRY IT NOW now, you will be presented with a screen of test notebooks, as shown in the screenshot below.

While on the page in the screenshot above, ensure you sign in with the same account that you use for the Azure portal login by clicking the Sign in button.

Once you are signed in, click on My Projects like in the screenshot below.

To create a new project where the Python3 code will live, click on the +New Project button.

Type in a project name of the project that you are creating to store the Python3 code. For the purposes of this blog post, Python3Testing will be used. If you would like the code to be public facing, meaning anyone can access it, check the box next to Public. The notebook created in this blog post will not be using the Public option. Once you type in the project name, click the blue Create button as shown in the screenshot below.

The project is now created.

Using Python3 in Azure Notebooks

In the previous section you took a hands-on approach to create the first Azure Notebook project for Python3 code. Now you will set up the notebook itself to run Python3 code.

Creating the New Notebook

To start creating a notebook, click on the blue + button and select Notebook from the drop-down.

Give the notebook a name and select Python3.6 as that's the most recent version of Python3 and Python2 is now deprecated. For the purposes of this blog post, the notebook name will be called PythonNotebook. Once you choose a name, click the blue New button.

Running Python3 Code

To open up the notebook and start writing Python3 code, click the notebook name. The notebook name in this blog post is PythonNotebook.ipynb.

The notebook is now open and you can start writing Python3 code.

In the notebook, In []: is what code will be passed in, for example, a print statement. Once code is typed, you can press enter and then the output will show right below. For example, you are going to use the following code to check a variable value.

az = 'azure cli'
if 'azure' in az:
    print('Yep, its azure cli')

If you type the code into the In []: block and click SHIFT + ENTER, you will see an output similar to the screenshot below.

Congrats! You have successfully created an Azure Notebook and utilized the Python3 programming language to show input and output in an Azure Notebook.

Conclusion

In this blog post you got a theoretical and a hands-on approach around all-things Azure Notebooks with Python. You first took a look at what languages are available in Azure Notebooks and the pricing, which is free, woohoo! You then dove into creating an Azure Notebook and using Python3 inside of the notebook.

For your next challenge, try sharing that notebook out to others and collaborating on it. Programming is fun, but its even more fun with others!

Interested in learning more about Python? If you like my content, check out my new skill on CBT Nuggets using Python3 in Azure which you can find here.