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.
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.
# 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
Local Development
- install python3
- install
REQUIREMENTS.txt
usingmake init
I recommend to use Python3 virtual environments.
# sets up environment
make env
# installs requirements
make init
Docker
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
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
Built Distribution
File details
Details for the file az.cli-0.5.tar.gz
.
File metadata
- Download URL: az.cli-0.5.tar.gz
- Upload date:
- Size: 3.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.7.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6a391562373f7353607604d502b72ecad0e457fc15f1ae597d3cad8759d20508 |
|
MD5 | e2910424af64e53a8471b79f148d3054 |
|
BLAKE2b-256 | 761de97c30656e55a2fd3ed1522f322a2b4bf4f33a729708817c7a0cc24c194a |
File details
Details for the file az.cli-0.5-py3-none-any.whl
.
File metadata
- Download URL: az.cli-0.5-py3-none-any.whl
- Upload date:
- Size: 5.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.7.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 30f50b10c3420c4d821f47429caf2b5ecc8fe332b0085fdb632769f0087b8506 |
|
MD5 | de6c3c55a812c102adad51eb1d706f63 |
|
BLAKE2b-256 | 7736f47f45335b5ef530aabe5436cc17c1bcee5f5541c85f4a668a8253a15e28 |