{"id":1299,"library":"azure-cli-core","title":"Azure CLI Core","description":"The `azure-cli-core` library provides the core runtime and fundamental services for the Microsoft Azure Command-Line Interface (Azure CLI). It is a key internal component that enables the Azure CLI to function, providing capabilities such as command dispatch, argument parsing, and output formatting. The current version is 2.85.0, and the Azure CLI project typically follows a monthly release cadence, including updates to this core module.","status":"active","version":"2.85.0","language":"en","source_language":"en","source_url":"https://github.com/Azure/azure-cli","tags":["azure","cli","microsoft","cloud","administration","command-line"],"install":[{"cmd":"pip install azure-cli-core","lang":"bash","label":"Install only the core library"},{"cmd":"pip install azure-cli","lang":"bash","label":"Recommended: Install the full Azure CLI"}],"dependencies":[],"imports":[{"note":"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.","wrong":"import azure.cli.core","symbol":"get_default_cli","correct":"from azure.cli.core import get_default_cli"}],"quickstart":{"code":"import os\nfrom azure.cli.core import get_default_cli\n\n# Initialize the Azure CLI core\naz_cli = get_default_cli()\n\n# Example 1: Run a simple command (e.g., list resource groups)\n# Ensure you are logged in via `az login` or have AZURE_CLIENT_ID, AZURE_CLIENT_SECRET, AZURE_TENANT_ID set\nprint(\"\\n--- Listing Azure resource groups ---\")\ntry:\n    exit_code_list = az_cli.run(['group', 'list', '--output', 'json'])\n    print(f\"'az group list' command exited with code: {exit_code_list}\")\nexcept Exception as e:\n    print(f\"Error running 'az group list': {e}\")\n\n# Example 2: Create a dummy resource group (requires authentication and permissions)\nresource_group_name = os.environ.get('AZURE_TEST_RG_NAME', 'my-test-rg-cli-core')\nlocation = os.environ.get('AZURE_TEST_LOCATION', 'eastus')\n\nprint(f\"\\n--- Attempting to create resource group: {resource_group_name} in {location} ---\")\ntry:\n    exit_code_create = az_cli.run(['group', 'create', '--name', resource_group_name, '--location', location, '--output', 'json'])\n    print(f\"'az group create' command exited with code: {exit_code_create}\")\nexcept Exception as e:\n    print(f\"Error running 'az group create': {e}\")\n\n# Example 3: Clean up the dummy resource group (if created successfully)\nprint(f\"\\n--- Attempting to delete resource group: {resource_group_name} ---\")\ntry:\n    # Use --yes for non-interactive deletion\n    exit_code_delete = az_cli.run(['group', 'delete', '--name', resource_group_name, '--yes', '--output', 'none'])\n    print(f\"'az group delete' command exited with code: {exit_code_delete}\")\nexcept Exception as e:\n    print(f\"Error running 'az group delete': {e}\")\n","lang":"python","description":"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."},"warnings":[{"fix":"Install 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.","message":"`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.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Upgrade 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.","message":"The 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.","severity":"breaking","affected_versions":"All versions, specifically 2.66.2+ (Python 3.12+ recommended for embedded Python), 2.85.0+ (Python >=3.10.0 required)"},{"fix":"Pin 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.","message":"When 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.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure 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.","message":"Programmatic 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.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-08T00:00:00.000Z","next_check":"2026-07-07T00:00:00.000Z"}