Code Comparison Between Azure PowerShell and Azure SDK for Python

I like to share similarities and differences of two scripts – an Azure PowerShell script and a Python script using the Azure SDK. These two scripts achieve the same azure management result. Hope this article sheds some technical insights by comparing these scripts.

The scripts connect to an Azure subscription, create a storage account into an existing resource group and list the resources in the resource group.

PowerShell script:

Console output:

Python script:

Console output:

Resource Group in Azure Portal:

Code StepAzure PowerShellAzure SDK & Python
1There is no import or include lines as the Azure PowerShell modules are already installed.The import statements are required to make use of Azure SDK management and client library modules.
2Connecting or logging into the Azure tenant and subscription.Connecting or logging into the Azure tenant and subscription. No big differences.
3Creating a storage account using using a command and a set of arguments. This is more of a “declarative” style and is easy to work with.With the storage client object, the programming is very much imperative with passing in functional arguments and any objects.
4To get an existing resource group object, it is simply calling the Az PowerShell command. No need to deal with client objects.Need to create a client object for resource group and query for the resource group.
5Iterating through resources and adding each key-value in a hashtableIterating through resources and adding each key-value in a dictionary. Syntax is quite similar to each other.
6Printing the hasthable of resourcesPrinting the dictionary of resources

Conclusion

There you have it! Simple comparison to understand the programming, syntax, style and objects in managing Azure resources. Hope this helps you decide which language suits your style and requirements.

Leave a Reply