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.910 runs
installs and imports cleanly · install 0.1s · import 0.117s · 59.5MB
glibcpy 3.10–3.910 runs
installs and imports cleanly · install 24.3s · import 0.106s · 61MB
556MB installed
● package 556MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
get_default_cli
✓ from azure.cli.core import get_default_cli
✗ import azure.cli.core
Directly importing the module usually isn't enough; you need to import and use the `get_default_cli` function to interact with the CLI runtime.
This quickstart demonstrates how to initialize the Azure CLI core and execute Azure CLI commands programmatically within a Python script using `get_default_cli().run()`. It includes examples for listing, creating, and deleting a resource group. Ensure you are authenticated to Azure (e.g., via `az login` in your terminal or by setting relevant environment variables) for commands requiring credentials to succeed.
import os
from azure.cli.core import get_default_cli
# Initialize the Azure CLI core
az_cli = get_default_cli()
# Example 1: Run a simple command (e.g., list resource groups)
# Ensure you are logged in via `az login` or have AZURE_CLIENT_ID, AZURE_CLIENT_SECRET, AZURE_TENANT_ID set
print("\n--- Listing Azure resource groups ---")
try:
exit_code_list = az_cli.run(['group', 'list', '--output', 'json'])
print(f"'az group list' command exited with code: {exit_code_list}")
except Exception as e:
print(f"Error running 'az group list': {e}")
# Example 2: Create a dummy resource group (requires authentication and permissions)
resource_group_name = os.environ.get('AZURE_TEST_RG_NAME', 'my-test-rg-cli-core')
location = os.environ.get('AZURE_TEST_LOCATION', 'eastus')
print(f"\n--- Attempting to create resource group: {resource_group_name} in {location} ---")
try:
exit_code_create = az_cli.run(['group', 'create', '--name', resource_group_name, '--location', location, '--output', 'json'])
print(f"'az group create' command exited with code: {exit_code_create}")
except Exception as e:
print(f"Error running 'az group create': {e}")
# Example 3: Clean up the dummy resource group (if created successfully)
print(f"\n--- Attempting to delete resource group: {resource_group_name} ---")
try:
# Use --yes for non-interactive deletion
exit_code_delete = az_cli.run(['group', 'delete', '--name', resource_group_name, '--yes', '--output', 'none'])
print(f"'az group delete' command exited with code: {exit_code_delete}")
except Exception as e:
print(f"Error running 'az group delete': {e}")
az --version
Debug
Known issues
gotcha`azure-cli-core` is primarily an internal component. For most users, installing the full `azure-cli` package (`pip install azure-cli`) or using one of the standalone installers (MSI, Deb, RPM, Homebrew) is the recommended way to get a functional Azure CLI. Installing `azure-cli-core` alone will not provide the full CLI experience and may lack necessary command modules.fixInstall the `azure-cli` package directly or use the official standalone installers for a complete Azure CLI experience. Only install `azure-cli-core` if you are developing extensions or integrating deeply with the CLI's internal mechanisms.
affects: All versions
breakingThe minimum required Python version for `azure-cli-core` (and thus `azure-cli`) can change with major releases. As of version 2.85.0, Python >=3.10.0 is required. Older versions may support or require different Python versions. Ensure your environment meets the `requires_python` specification.fixUpgrade your Python environment to meet the specified minimum version (e.g., Python 3.10 or newer for recent versions). Always check the `requires_python` metadata on PyPI or the official release notes for the version you intend to use.
affects: All versions, specifically 2.66.2+ (Python 3.12+ recommended for embedded Python), 2.85.0+ (Python >=3.10.0 required)
gotchaWhen executing CLI commands programmatically using `az_cli.run()`, the output format and command syntax are subject to change between Azure CLI versions. Scripts relying on specific JSON output structures or command parameters may break unexpectedly with CLI updates.fixPin the Azure CLI version in your environment (`pip install azure-cli==X.Y.Z`). Be prepared to review and update your scripts after upgrading the Azure CLI, especially for major or minor version bumps. Prefer `--output json` and robust JSON parsing over fragile string matching.
affects: All versions
gotchaProgrammatic execution via `get_default_cli().run()` relies on the same authentication context as the standalone Azure CLI. If your script is not running in an authenticated environment (e.g., `az login` not performed, or relevant environment variables not set for service principal login), commands requiring authentication will fail.fixEnsure your environment is authenticated to Azure. This can be done interactively via `az login` before running the script, or non-interactively by setting environment variables (`AZURE_CLIENT_ID`, `AZURE_CLIENT_SECRET`, `AZURE_TENANT_ID` for service principal) or using managed identity if applicable.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'azure.cli.core'
This error occurs when the 'azure-cli-core' package is not installed or not accessible in the current Python environment.
fixInstall the Azure CLI package using pip: 'pip install azure-cli'.
ModuleNotFoundError: No module named 'azure'
This error occurs when the 'azure' package is not installed or not accessible in the current Python environment.
fixInstall the Azure SDK for Python using pip: 'pip install azure'.
ModuleNotFoundError: No module named 'azure.cli'
This error occurs when the 'azure-cli' package is not installed or not accessible in the current Python environment.
fixInstall the Azure CLI package using pip: 'pip install azure-cli'.
No module named 'azure.cli.command_modules'. 'login' is misspelled or not recognized by the system.
This error occurs when attempting to use Azure CLI commands in Python without the necessary modules installed.
fixEnsure that the 'azure-cli' package is installed and accessible in your Python environment: 'pip install azure-cli'.
'az' is not recognized as an internal or external command, operable program or batch file.
The Azure CLI installation directory is not included in the system's PATH environment variable, or the terminal session has not been restarted since installation/update.
fixRestart your terminal/IDE. If the issue persists, manually add the Azure CLI installation path (e.g., C:\Program Files\Microsoft SDKs\Azure\CLI2\wbin on Windows) to your system's PATH environment variables, then restart the terminal again.
Upgrade
Version history
2.89.1latest on PyPI · released Aug 12, 2026
Audit
Dependencies
No dependency data recorded yet.