{"id":1346,"library":"azure-cli","title":"Azure CLI","description":"The Azure CLI is a set of command-line tools provided by Microsoft for managing Azure resources. While it is a Python-based application, it is primarily intended to be used as a shell command (`az`) rather than directly imported as a Python library in application code. It offers commands for data-plane and control-plane operations. The current version is 2.85.0, with frequent monthly releases.","status":"active","version":"2.85.0","language":"en","source_language":"en","source_url":"https://github.com/Azure/azure-cli","tags":["cli","azure","cloud","microsoft","automation"],"install":[{"cmd":"pip install azure-cli","lang":"bash","label":"For development or isolated environments"},{"cmd":"curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash","lang":"bash","label":"Recommended for Linux (Debian/Ubuntu)"},{"cmd":"brew update && brew install azure-cli","lang":"bash","label":"Recommended for macOS"}],"dependencies":[{"reason":"Azure CLI 2.49.0+ requires Python >=3.10.0; newer versions often bump this requirement.","package":"Python","optional":false}],"imports":[{"note":"The `azure-cli` package is not designed for direct import and use as a typical Python SDK. Its modules (like `azure.cli.core` or `azure.cli.command_modules`) are primarily for extending the CLI itself or for internal use. For interacting with Azure services from Python, use the specific `azure-sdk-for-python` client libraries (e.g., `azure-mgmt-compute`, `azure-storage-blob`).","wrong":"import azure.cli","symbol":"azure.cli.core","correct":"from azure.cli.core import get_default_cli"}],"quickstart":{"code":"import subprocess\nimport os\n\n# Ensure Azure CLI is installed and user is logged in (e.g., via `az login` in shell)\n# You can also use service principal authentication for CI/CD environments.\n\ndef run_az_command(command):\n    \"\"\"Helper to run an az CLI command.\"\"\"\n    full_command = ['az'] + command.split()\n    try:\n        result = subprocess.run(full_command, capture_output=True, text=True, check=True, env=os.environ)\n        print(f\"Command: {' '.join(full_command)}\")\n        print(f\"STDOUT:\\n{result.stdout}\")\n        if result.stderr:\n            print(f\"STDERR:\\n{result.stderr}\")\n        return result.stdout\n    except subprocess.CalledProcessError as e:\n        print(f\"Error running command: {' '.join(full_command)}\")\n        print(f\"Error STDOUT:\\n{e.stdout}\")\n        print(f\"Error STDERR:\\n{e.stderr}\")\n        raise\n\n# Example 1: List resource groups in JSON format\nprint(\"\\n--- Listing resource groups ---\")\nresource_groups_json = run_az_command(\"group list --output json\")\n# Further processing with resource_groups_json if needed, e.g., json.loads()\n\n# Example 2: Get current account details\nprint(\"\\n--- Getting current account details ---\")\naccount_details = run_az_command(\"account show --output tsv\")\n\n# Example 3: Create a resource group (requires appropriate permissions)\n# Replace with unique name if running interactively\n# RG_NAME = os.environ.get('AZURE_TEST_RG', 'my-python-test-rg')\n# LOCATION = os.environ.get('AZURE_TEST_LOCATION', 'eastus')\n# print(f\"\\n--- Creating resource group {RG_NAME} in {LOCATION} ---\")\n# try:\n#     run_az_command(f\"group create --name {RG_NAME} --location {LOCATION} --output none\")\n#     print(f\"Resource group '{RG_NAME}' created successfully.\")\n# except Exception:\n#     print(f\"Could not create resource group '{RG_NAME}'. It might already exist or permissions are insufficient.\")\n\n# Example 4: Delete a resource group (USE WITH CAUTION!)\n# print(f\"\\n--- Deleting resource group {RG_NAME} ---\")\n# run_az_command(f\"group delete --name {RG_NAME} --no-wait --yes\")\n# print(f\"Deletion command issued for resource group '{RG_NAME}'.\")\n","lang":"python","description":"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."},"warnings":[{"fix":"Refer to the official Azure CLI installation guide for your operating system (aka.ms/installazurecliwindows, aka.ms/installazureclinux, aka.ms/installazurecliosx).","message":"The `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.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Upgrade 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.","message":"Azure 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.","severity":"breaking","affected_versions":">=2.40.0"},{"fix":"For 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', ...])`.","message":"Azure 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.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Always use `--output json` or `-o json` when specifying JSON output format for Azure CLI commands.","message":"The `--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.","severity":"deprecated","affected_versions":"All recent versions"},{"fix":"To provide feedback, use the GitHub issues page (https://github.com/Azure/azure-cli/issues) or other official feedback channels.","message":"The `az feedback` command was removed in Azure CLI 2.50.0. This command was used to provide feedback directly to the Azure CLI team.","severity":"breaking","affected_versions":">=2.50.0"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}