Azure CLI SQL Module

raw JSON →
2.2.5 verified Sat May 09 auth: no python

Microsoft Azure CLI SQL command module for managing Azure SQL databases, servers, and elastic pools. Current version 2.2.5. Released alongside Azure CLI core; no independent release cadence.

pip install azure-cli-sql
error ModuleNotFoundError: No module named 'azure.cli.core'
cause Missing Azure CLI core package.
fix
Run pip install azure-cli to install the full CLI.
error ImportError: cannot import name 'SqlCommandsLoader' from 'azure.cli.command_modules.sql'
cause Using outdated import path; the loader may have moved.
fix
Use from azure.cli.command_modules.sql import SqlCommandsLoader directly.
breaking The SQL module no longer supports the older SQL DB create/update parameters from versions < 2.0.0. Use `--capacity` and `--edition` instead of `--max-size-bytes` and `--sku-name`.
fix Update scripts to use new parameter names: `az sql db create --capacity ... --edition ...`
deprecated Azure SQL Managed Instance commands using `az sql mi` are being deprecated in favor of the new `az sql mi` command group in the "mssql" extension. This module will eventually drop Managed Instance support.
fix Install the mssql extension: `az extension add --name mssql` and use `az mssql mi` instead.
gotcha Module import fails if Azure CLI is not fully installed. Running `pip install azure-cli-sql` alone will not pull all dependencies; you must also install `azure-cli` or `azure-cli-core`.
fix Install full CLI: `pip install azure-cli` or at least `pip install azure-cli-core`.

Initialize CLI and list SQL servers using the SQL command module. Requires prior `az login`.

from azure.cli.core import get_default_cli
from azure.cli.command_modules.sql import SqlCommandsLoader

cli = get_default_cli()
loader = SqlCommandsLoader(cli)
# List SQL servers (requires authenticated CLI session)
result = cli.invoke(['sql', 'server', 'list'])
print(result.result)