{"id":2407,"library":"azure-mgmt-subscription","title":"Azure Subscription Management Client Library for Python","description":"The `azure-mgmt-subscription` library provides Python APIs for managing Azure subscriptions. It allows developers to programmatically interact with Azure to get subscription details, list available locations, manage subscription aliases, and perform other subscription-related operations. The current stable version is 3.1.1. The Azure SDK for Python generally follows an active release cadence for its management libraries, with updates addressing bug fixes, new features, and breaking changes across major versions.","status":"active","version":"3.1.1","language":"en","source_language":"en","source_url":"https://github.com/Azure/azure-sdk-for-python","tags":["azure","cloud","subscription","management","sdk","arm","microsoft"],"install":[{"cmd":"pip install azure-mgmt-subscription azure-identity","lang":"bash","label":"Install stable version with authentication library"}],"dependencies":[{"reason":"Required for authentication using Azure Active Directory, typically via DefaultAzureCredential.","package":"azure-identity","optional":false},{"reason":"Underlying shared core client library for Azure SDKs.","package":"azure-core","optional":false},{"reason":"Used for REST API client and model generation.","package":"msrest","optional":false}],"imports":[{"note":"As of v3.0.0, the SubscriptionClient class was moved directly under the `azure.mgmt.subscription` package.","wrong":"from azure.mgmt.subscription.subscription_client import SubscriptionClient","symbol":"SubscriptionClient","correct":"from azure.mgmt.subscription import SubscriptionClient"},{"note":"Model classes should be imported directly from `azure.mgmt.subscription.models`, not from sub-modules within `models`.","wrong":"from azure.mgmt.subscription.models.my_class import MyClass","symbol":"Subscription","correct":"from azure.mgmt.subscription.models import Subscription"},{"symbol":"DefaultAzureCredential","correct":"from azure.identity import DefaultAzureCredential"}],"quickstart":{"code":"import os\nfrom azure.identity import DefaultAzureCredential\nfrom azure.mgmt.subscription import SubscriptionClient\n\n# Ensure AZURE_SUBSCRIPTION_ID, AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET are set as environment variables\n# for DefaultAzureCredential to work in non-interactive environments.\n# For local development, Azure CLI or VS Code authentication might be used, removing the need for explicit env vars.\n\nsubscription_id = os.environ.get('AZURE_SUBSCRIPTION_ID', 'YOUR_SUBSCRIPTION_ID')\n\nif not subscription_id or subscription_id == 'YOUR_SUBSCRIPTION_ID':\n    raise ValueError(\"Please set the AZURE_SUBSCRIPTION_ID environment variable or replace 'YOUR_SUBSCRIPTION_ID'.\")\n\ntry:\n    # Authenticate using DefaultAzureCredential\n    credential = DefaultAzureCredential()\n\n    # Create a SubscriptionClient\n    subscription_client = SubscriptionClient(credential)\n\n    # List all subscriptions accessible by the credential\n    print(\"Listing all subscriptions...\")\n    for subscription in subscription_client.subscriptions.list():\n        print(f\"Subscription ID: {subscription.subscription_id}, Display Name: {subscription.display_name}, State: {subscription.state}\")\n\n    # Get details for a specific subscription\n    print(f\"\\nGetting details for subscription ID: {subscription_id}\")\n    specific_subscription = subscription_client.subscriptions.get(subscription_id)\n    print(f\"Display Name: {specific_subscription.display_name}, State: {specific_subscription.state}\")\n\n    # List locations for the specific subscription\n    print(f\"\\nListing locations for subscription ID: {subscription_id}\")\n    for location in subscription_client.subscriptions.list_locations(subscription_id):\n        print(f\"Location: {location.display_name} ({location.name})\")\n\nexcept Exception as e:\n    print(f\"An error occurred: {e}\")\n    print(\"Ensure you are logged into Azure (e.g., via `az login`) or environment variables are set correctly.\")","lang":"python","description":"This quickstart demonstrates how to authenticate with Azure using `DefaultAzureCredential` and then use `SubscriptionClient` to list all accessible subscriptions, retrieve details for a specific subscription, and list available locations within that subscription."},"warnings":[{"fix":"Review the migration guide if upgrading from pre-3.0.0 versions. Update long-running operation calls to use `begin_` prefix and `azure.core.polling.LROPoller`. Handle `HttpResponseError` instead of `CloudError`.","message":"Version 3.0.0 introduced significant breaking changes, including a new code generator. Operations that returned `msrest.polling.LROPoller` now return `azure.core.polling.LROPoller` and are prefixed with `begin_`. `CloudError` was removed and most exceptions are now `azure.core.exceptions.HttpResponseError`. It also introduced stable and official support for async programming.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Update import statements: `from azure.mgmt.subscription import SubscriptionClient` and `from azure.mgmt.subscription.models import ModelName`.","message":"Import paths for `SubscriptionClient` and `SubscriptionClientConfiguration` changed. They can no longer be imported from `azure.mgmt.subscription.subscription_client`. Model classes also shifted from sub-modules (e.g., `azure.mgmt.subscription.models.my_class`) to direct import from `azure.mgmt.subscription.models`.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Ensure your Python environment is running Python 3.7 or newer. For new projects, consider Python 3.9+.","message":"The `azure-mgmt-subscription` library (and other Azure SDK Python packages) officially ended support for Python 2.7 on January 1, 2022. Version 3.1.1 requires Python 3.7+. Newer management libraries often require Python 3.9+.","severity":"gotcha","affected_versions":"<3.7"},{"fix":"Before initiating a subscription transfer, verify and if necessary, adjust the Microsoft Entra tenant association for both subscriptions to match.","message":"When moving an Azure subscription to a different tenant, both the source and destination subscriptions must reside within the same Microsoft Entra (formerly Azure Active Directory) tenant. This is a crucial prerequisite for successful transfers.","severity":"gotcha","affected_versions":"All"},{"fix":"Migrate any classic resources to Azure Resource Manager before attempting to move the subscription. This can be a complex process depending on the resources involved.","message":"Azure resources created using the classic deployment model cannot be moved between subscriptions. All resources in the source subscription must be migrated to the Azure Resource Manager (ARM) model before a subscription transfer can occur.","severity":"gotcha","affected_versions":"All"},{"fix":"Upgrade to `azure-mgmt-subscription==3.1.1` or newer. If stuck on 3.1.0, you might need to explicitly pass the `api_version` keyword argument to affected operations.","message":"Version 3.1.0 had a bug where the `api_version` was missing for some operations (e.g., `list_locations`), causing exceptions. This was fixed in version 3.1.1.","severity":"gotcha","affected_versions":"3.1.0"}],"env_vars":null,"last_verified":"2026-04-10T00:00:00.000Z","next_check":"2026-07-09T00:00:00.000Z"}