Install & Compatibility
Where this runs
tested against v2.89.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.95 runs
installs and imports cleanly · install 0.1s · import 0.116s · 586.4MB
glibcpy 3.10–3.95 runs
installs and imports cleanly · install 43.6s · import 0.108s · 588MB
661MB installed
● package 661MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
get_default_cli
✓ from azure.cli.core import get_default_cli
✗ from azure.cli.core import get_default_cli
This quickstart demonstrates how to execute Azure CLI commands programmatically from Python using the `subprocess` module. Users must have the Azure CLI installed and authenticated (e.g., via `az login`) prior to running these commands. This approach is suitable for scripting automation or integrating CLI operations within Python applications.
import subprocess
import os
# Ensure Azure CLI is installed and user is logged in (e.g., via `az login` in shell)
# You can also use service principal authentication for CI/CD environments.
def run_az_command(command):
"""Helper to run an az CLI command."""
full_command = ['az'] + command.split()
try:
result = subprocess.run(full_command, capture_output=True, text=True, check=True, env=os.environ)
print(f"Command: {' '.join(full_command)}")
print(f"STDOUT:\n{result.stdout}")
if result.stderr:
print(f"STDERR:\n{result.stderr}")
return result.stdout
except subprocess.CalledProcessError as e:
print(f"Error running command: {' '.join(full_command)}")
print(f"Error STDOUT:\n{e.stdout}")
print(f"Error STDERR:\n{e.stderr}")
raise
# Example 1: List resource groups in JSON format
print("\n--- Listing resource groups ---")
resource_groups_json = run_az_command("group list --output json")
# Further processing with resource_groups_json if needed, e.g., json.loads()
# Example 2: Get current account details
print("\n--- Getting current account details ---")
account_details = run_az_command("account show --output tsv")
# Example 3: Create a resource group (requires appropriate permissions)
# Replace with unique name if running interactively
# RG_NAME = os.environ.get('AZURE_TEST_RG', 'my-python-test-rg')
# LOCATION = os.environ.get('AZURE_TEST_LOCATION', 'eastus')
# print(f"\n--- Creating resource group {RG_NAME} in {LOCATION} ---")
# try:
# run_az_command(f"group create --name {RG_NAME} --location {LOCATION} --output none")
# print(f"Resource group '{RG_NAME}' created successfully.")
# except Exception:
# print(f"Could not create resource group '{RG_NAME}'. It might already exist or permissions are insufficient.")
# Example 4: Delete a resource group (USE WITH CAUTION!)
# print(f"\n--- Deleting resource group {RG_NAME} ---")
# run_az_command(f"group delete --name {RG_NAME} --no-wait --yes")
# print(f"Deletion command issued for resource group '{RG_NAME}'.")
az --version
Debug
Known issues
gotchaThe `azure-cli` PyPI package is the source for the command-line tool, but end-users are strongly advised to install it via official installers (e.g., `apt`, `yum`, `brew`, MSI) or the install script, rather than `pip install`. `pip install azure-cli` is primarily for developers, CI/CD, or highly isolated environments where pathing and dependencies must be managed carefully, and may not automatically set up the `az` executable on the system PATH.fixRefer to the official Azure CLI installation guide for your operating system (aka.ms/installazurecliwindows, aka.ms/installazureclinux, aka.ms/installazurecliosx).
affects: All versions
breakingAzure CLI continuously updates its Python version requirements. Starting with 2.49.0, Python >=3.10 is required. For 2.61.0+, Python >=3.11 is required. Newer versions have incrementally dropped support for older Python versions (e.g., Python 3.7 support dropped in 2.40.0, Python 3.8 dropped for versions requiring 3.10+). Ensure your Python environment meets the minimum requirement for your Azure CLI version.fixUpgrade your Python environment to meet the minimum requirement for the desired Azure CLI version. Check `az --version` for current Python runtime. If using `pip install`, ensure your virtual environment uses a compatible Python version.
affects: >=2.40.0
gotchaAzure CLI is a command-line tool, not a Python SDK. Do not attempt to `import azure.cli` to interact with Azure resources from your Python application. For programmatic interaction with Azure services, use the dedicated `azure-sdk-for-python` libraries (e.g., `azure-mgmt-storage`, `azure-identity`, `azure-storage-blob`). The `azure-cli` components are for extending the CLI itself or for internal operations.fixFor Python development, use the `azure-sdk-for-python` client libraries relevant to the Azure service you wish to interact with. If you need to execute CLI commands from Python, use `subprocess.run(['az', ...])`.
affects: All versions
deprecatedThe `--json` output option has been deprecated in favor of `--output json` (or `-o json`). While `--json` might still work for some commands, `az` strongly recommends using the standard `--output` or `-o` parameter for consistency.fixAlways use `--output json` or `-o json` when specifying JSON output format for Azure CLI commands.
affects: All recent versions
breakingThe `az feedback` command was removed in Azure CLI 2.50.0. This command was used to provide feedback directly to the Azure CLI team.fixTo provide feedback, use the GitHub issues page (https://github.com/Azure/azure-cli/issues) or other official feedback channels.
affects: >=2.50.0
gotchaAzure CLI commands require authentication to interact with Azure resources. Before running commands, ensure you are logged in to an Azure account.fixRun `az login` interactively to log in. For CI/CD or non-interactive environments, use methods like `az login --service-principal` with credentials, `az login --identity` for Managed Identities, or environment variables for authentication.
affects: All versions
gotchaAzure CLI commands that interact with Azure resources (e.g., listing resource groups, creating resources) require prior authentication. Attempting to execute such commands without logging in will result in an error indicating that an account needs to be set up.fixBefore running Azure CLI commands that interact with Azure, ensure you are authenticated. For interactive use, run `az login`. For automated scripts (e.g., CI/CD), configure non-interactive authentication methods like service principals (using environment variables `AZURE_CLIENT_ID`, `AZURE_TENANT_ID`, `AZURE_CLIENT_SECRET`) or managed identity.
affects: All versions
Upgrade
Version history
2.89.1latest on PyPI · released Aug 12, 2026
Audit
Dependencies
PythonrequiredAzure CLI 2.49.0+ requires Python >=3.10.0; newer versions often bump this requirement.