
In this Azure article, we will discuss Azure Python SDK and we will also set up a Python dev environment in Azure.
Azure Python SDK
The Azure libraries for Python are open-source and can be used to manage, provision Azure resources from the Python application code.
The Azure libraries are all about how you are communicating with the Azure services from the Python code. You may run the Python code locally or in the cloud. The libraries support Python 2.7 and 3.5.3 versions and above. The Azure SDK for Python is composed of more than 180 individual Python libraries.
You can use the pip install <library name> to install the library package that you want to install.pip install
retrieves the latest version of a library in the Python environment.
The Azure libraries for Python build on top of the Azure REST API and you can use the Rest API from the Python code.
You can also check out the steps to Install An Azure Module In Python for the installation.
Setup the Python-Dev environment For Azure
The first step is to configure your Python-Dev environment for Azure. As part of the configuration of the Python-Dev environment, we need to install a few main components like below
- Install the main components like Azure account, Python, and the Azure CLI
- Configure the Authentication to use the Azure Libraries to provision and manage the Azure Resources.
The main required components are as below
- You must have an Azure Account or Azure Subscription. If you don’t have an Azure Account till now, Create an Azure Free Account now.
- You need the Python latest runtime version 3.x. The recommended Python runtime version is 3. x.
- You need the Azure command-line interface or Azure CLI that helps you with the environment to run the commands needed that helps to manage the Azure Resources.
The recommended components are as below
- Visual Studio Code
- Python extension for Visual Studio Code
- Azure Extension for Visual Studio Code
- Git command-line tool for the Source control
You can verify the components by following the below steps
- Open the command prompt on your machine
- Then run the command python –version to check the Python version installed on your machine
- Now, run the command az –version to check the Azure CLI version.
- Then to check the Visual Studio Code Part, you can run the code. to open the VS Code from the current folder. To verify the Extensions if you have installed them properly. Select the View —> Extensions command to open the extensions view, Now just check if you can able to see the Python and Azure Accounts in the list. Check out the Azure extensions and Docker in the list.
Sign in to Azure from the CLI using the Az login command. You need to configure the authentication using the service principal and environment variable.
Python virtual environments
It is always recommended to use Python virtual environments for each project. You can follow the below steps to create and activate the Python virtual environments.
- Open the command prompt on your machine
- Create a folder for your project that you want to create or use.
- Use the below cmdlet to create the Python virtual environments. The below command runs the Python
venv
module and creates a virtual environment
py -3 -m venv .venv
Once it got created, use the below command to activate the Python virtual environment
.venv\scripts\activate
Once you activate that environment, you can run the pip install
command that installs a library into that environment
You may also like following the below articles
Final Thoughts
In this Azure article, we discussed Azure Python SDK and we also discussed how to set up a Python dev environment in Azure. Thanks for reading this article !!!