Search code examples
azure-cliazure-sdk-python

Azure SDK for Python vs. Calling Azure CLI using subprocess


I need to build a series of Automated Tests using Python language. The tests need a query a series of Azure resources, get results (probably JSON format) and check a few conditions.

I can think of two options:

  1. Call Azure CLI in my Python code using Python's subprocess to get JSON output

  2. Use Azure SDK for Python

Which of the above options is easier to query Azure resources? Do I have an easier option?


Solution

  • I think using Azure CLI in python is easier, you can get the resources with one line command and simply use --query parameter to query the command output, e.g. filter with a condition, get a specific property, etc.

    For python SDK, normally you need to use different packages for different resources, define different clients to call the different methods, it is not so convenient.