How to set Workspace inside Azure ML SDK

Working With Azure ML workspace can be more flexible with Azure ML SDK. In this section, we are going to see how to set a workspace via AzureML SDK inside Notebook. in summary how to access the config file for the Azure ML workspace will be shown, and how to set a new workspace with different resource groups will be presented.

What is Workspace

In Microsoft Azure, we have a Subscription that each person can have many subscriptions, inside each subscription, we can create multiple Resource Groups that act like a Folder. in each resource group we are able to define multiple Azure ML workspace ( Azure ML Component), each workspace contains the model, pipeline, data, compute, experiment and so forth.

To access current workspace information, Login to your Azure subscription, then your Resource Group, and then click on the Azure ML component. Click on the Download Config.json. This file contains information about the workspace such as Subscription ID, resource group, and workspace name.

Azure Notebook

Before starting to write code and train a model, we want to allocated out workspace to azuremlleila. as you can see in the below code, first you need to import the azureml library. I am using ws variable to get workspace specification from the currently available workspace using the below function(get function)

from azureml.core import Workspace
ws = Workspace.get(name='azuremlleila',


As you can see above my workspace in the code has been stored in variable ws, and set all to the current workspace that is azuremlleila under the aifunamentalleilaetaati resource group.

Create New Workspace

Now in another experiment, we want to use python code with help of Azure ML SDK to define a new workspace ( beside azuremlleila).

from azureml.core import Workspace
ws = Workspace.create(name='AzureMLTest',
                      subscription_id='Susbcription ID',

In this example, we are going to use a function name create under the workspace library, we need to specify the name of the workspace, subscription, resource group, location, and so forth. we are able to create a workspace in the same resource group as well.

after running this code, in our azure environment, we are able to see a new resource group with azure ml component and workspace as below

you can see a new azure ml source has been created via code and we are able to write code and train models under it.

also, watch below video to see how it works

Leila Etaati on LinkedinLeila Etaati on TwitterLeila Etaati on Youtube
Leila Etaati
Trainer, Consultant, Mentor
Leila is the first Microsoft AI MVP in New Zealand and Australia, She has Ph.D. in Information System from the University Of Auckland. She is the Co-director and data scientist in RADACAD Company with more than 100 clients in around the world. She is the co-organizer of Microsoft Business Intelligence and Power BI Use group (meetup) in Auckland with more than 1200 members, She is the co-organizer of three main conferences in Auckland: SQL Saturday Auckland (2015 till now) with more than 400 registrations, Difinity (2017 till now) with more than 200 registrations and Global AI Bootcamp 2018. She is a Data Scientist, BI Consultant, Trainer, and Speaker. She is a well-known International Speakers to many conferences such as Microsoft ignite, SQL pass, Data Platform Summit, SQL Saturday, Power BI world Tour and so forth in Europe, USA, Asia, Australia, and New Zealand. She has over ten years’ experience working with databases and software systems. She was involved in many large-scale projects for big-sized companies. She also AI and Data Platform Microsoft MVP. Leila is an active Technical Microsoft AI blogger for RADACAD.

Leave a Reply