Skip to main content

An interface to execute Azure CLI commands using Python

Project description

Az.Cli

PyPi Build Status

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, see 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.

# cd src
# python3
from az.cli import az
# on Success, the `error_code` is 0 and the result_dict contains the output
az("group list") # list return tuple (exit_code, result_dict, log)
az("group list")[0] # 0
az("group list")[1] # print result_dict
az("group list")[1][0]['id'] # enumerate the id of the first element in dictionary

# On Error, the `error_code` will be != 1 and the log is present
az("group show -n does-not-exsist") # list return tuple (exit_code, result_dict, log)
az("group show -n does-not-exsist")[0] # 3
az("group show -n does-not-exsist")[2] # print the log

Build

To build the image run the following in order.

# Runs docker build & create
make create

Run

After the container is build & created you can run the az.cli interactivly.

# Run docker run
make run

see interactive

Local Development

  • install python3
  • install REQUIREMENTS.txt using make init

I recommend to use Python3 virtual environments.

python3 -m venv env
source env/bin/activate
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.2.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

az.cli-0.2-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

Details for the file az.cli-0.2.tar.gz.

File metadata

  • Download URL: az.cli-0.2.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.6

File hashes

Hashes for az.cli-0.2.tar.gz
Algorithm Hash digest
SHA256 4f8e66a332328d752807018537908a9d0733055b28d6bad12a3f19b0e3c221d5
MD5 adf6adbd27c773c3a717e6c44a808b7d
BLAKE2b-256 2c4886bcf54aab7f82ce4b6b70f81bb4391ecae950e4897016c5e714ddba7f9c

See more details on using hashes here.

File details

Details for the file az.cli-0.2-py3-none-any.whl.

File metadata

  • Download URL: az.cli-0.2-py3-none-any.whl
  • Upload date:
  • Size: 5.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.6

File hashes

Hashes for az.cli-0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 4b4adbe77191301b75974d80a9c91ff5ef9c28f94a17eafbbdfff8117ed910b7
MD5 1e7b5351bc186a7a9e0950621df62e74
BLAKE2b-256 dd311f92684255bc159ce2424d5897f9e752119871458059f7580b677517f5c2

See more details on using hashes here.

Supported by

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