0

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?

Allan Xu
  • 7,998
  • 11
  • 51
  • 122

1 Answers1

1

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.

Joy Wang
  • 39,905
  • 3
  • 30
  • 54
  • Thank you for help. What subprocess setup work well when calling az cli? Appreciate it if you could provide a small code snippet. – Allan Xu May 12 '21 at 15:57
  • @AllanXu Refer to the samples: [here](https://stackoverflow.com/a/52870361/9455659) and [here](https://stackoverflow.com/a/54706701/9455659). – Joy Wang May 13 '21 at 01:22