An interface to execute Azure CLI commands using Python
Likely abandoned. No release or commit for years (last release over 5 years ago).
pip install az-cliAz.Cli
Python azure.cli.core interface to execute az Azure CLI commands in python.
The method returns a named tuple AzResult = namedtuple('AzResult', ['exit_code', 'result_dict', 'log']). The error_code where 0 == success. A result_dict containing successfull return as a python dictionary. On failure (error_code > 0) a log message inside log as a string.
Usage
Install the package
pip install az.cli
Login using az login or sign in using a service principal.
Under the hood the package uses the ~/.azure folder to persist and retrieve config.
Example
from az.cli import az
# AzResult = namedtuple('AzResult', ['exit_code', 'result_dict', 'log'])
exit_code, result_dict, logs = az("group show -n test")
# On 0 (SUCCESS) print result_dict, otherwise get info from `logs`
if exit_code == 0:
print (result_dict)
else:
print(logs)
Interactive
You can run the command interactively to traverse the dictionary.
Navigate to src and run python3.
Import the library from az.cli import az and run any command by executing the method az("<my command>") to invoke Azure CLI.