Skip to main content

An interface to execute Azure CLI commands using Python

Project description

Az.Cli

Python azure.cli.core interface to execute az Azure CLI commands in python.

Prerequisites

Example

from az.cli import az

# AzResult = namedtuple('AzResult', ['exit_code', 'out', '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.

# cd src
# python3
from az.cli import az
az("group list") # list return tuple (exitCode, resultSet)
az("group list")[1] # return resultSet content <dict>
az("group list")[1][0]['id'] # Enumerate id of first element in resultSet

# On Error
az("group show -n does-not-exsist") # list return tuple (exitCode, resultSet)
az("group show -n does-not-exsist")[0] # 3
az("group show -n does-not-exsist")[2] # Print the logs

Build

To build the image run the following in order.

# Runs docker build & create
make create

Run

make run

see interactive

Local Development

To develop locally make sure to install Python3. I recommend to use Python3 virtual environments:

sudo apt-get install python3-venv

Then run:

python3 -m venv env
make init

Known Bugs

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

az.cli-0.1.tar.gz (3.5 kB view hashes)

Uploaded Source

Built Distribution

az.cli-0.1-py3-none-any.whl (4.5 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page