Registry / azure / azure-mgmt-subscription

azure-mgmt-subscription

JSON →
library3.1.1pypypi✓ verified 25d ago

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.

pip install azure-mgmt-subscription azure-identity
INSTALL
IMPORT
SIG · AZURE-MGMT-SUBSCRI
A
azure-mgmt-subscription
azurepythonv3.1.1
Install
4.1s avg
Import
587ms
Disk
45MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v3.1.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
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.640s · 46.1MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 4.1s · import 0.534s · 47MB
45MB installed
● package 45MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

SubscriptionClient
from azure.mgmt.subscription import SubscriptionClient
from azure.mgmt.subscription.subscription_client import SubscriptionClient
As of v3.0.0, the SubscriptionClient class was moved directly under the `azure.mgmt.subscription` package.
Subscription
from azure.mgmt.subscription.models import Subscription
from azure.mgmt.subscription.models.my_class import MyClass
Model classes should be imported directly from `azure.mgmt.subscription.models`, not from sub-modules within `models`.
DefaultAzureCredential
from azure.identity import DefaultAzureCredential

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.

import os from azure.identity import DefaultAzureCredential from azure.mgmt.subscription import SubscriptionClient # Ensure AZURE_SUBSCRIPTION_ID, AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET are set as environment variables # for DefaultAzureCredential to work in non-interactive environments. # For local development, Azure CLI or VS Code authentication might be used, removing the need for explicit env vars. subscription_id = os.environ.get('AZURE_SUBSCRIPTION_ID', 'YOUR_SUBSCRIPTION_ID') if not subscription_id or subscription_id == 'YOUR_SUBSCRIPTION_ID': raise ValueError("Please set the AZURE_SUBSCRIPTION_ID environment variable or replace 'YOUR_SUBSCRIPTION_ID'.") try: # Authenticate using DefaultAzureCredential credential = DefaultAzureCredential() # Create a SubscriptionClient subscription_client = SubscriptionClient(credential) # List all subscriptions accessible by the credential print("Listing all subscriptions...") for subscription in subscription_client.subscriptions.list(): print(f"Subscription ID: {subscription.subscription_id}, Display Name: {subscription.display_name}, State: {subscription.state}") # Get details for a specific subscription print(f"\nGetting details for subscription ID: {subscription_id}") specific_subscription = subscription_client.subscriptions.get(subscription_id) print(f"Display Name: {specific_subscription.display_name}, State: {specific_subscription.state}") # List locations for the specific subscription print(f"\nListing locations for subscription ID: {subscription_id}") for location in subscription_client.subscriptions.list_locations(subscription_id): print(f"Location: {location.display_name} ({location.name})") except Exception as e: print(f"An error occurred: {e}") print("Ensure you are logged into Azure (e.g., via `az login`) or environment variables are set correctly.")
Debug
Known issues
breakingVersion 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.
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`.
affects: >=3.0.0
breakingImport 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`.
fix
Update import statements: `from azure.mgmt.subscription import SubscriptionClient` and `from azure.mgmt.subscription.models import ModelName`.
affects: >=3.0.0
gotchaThe `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+.
fix
Ensure your Python environment is running Python 3.7 or newer. For new projects, consider Python 3.9+.
affects: <3.7
gotchaWhen 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.
fix
Before initiating a subscription transfer, verify and if necessary, adjust the Microsoft Entra tenant association for both subscriptions to match.
affects: All
gotchaAzure 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.
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.
affects: All
gotchaVersion 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.
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.
affects: 3.1.0
Upgrade
Version history
3.1.1latest on PyPI · released Sep 6, 2022
Audit
Dependencies
azure-identityrequiredRequired for authentication using Azure Active Directory, typically via DefaultAzureCredential.
azure-corerequiredUnderlying shared core client library for Azure SDKs.
msrestrequiredUsed for REST API client and model generation.
Agent activity
15 hits · last 30 days
node
12
OpenAI (training)
1
Resources
azure-mgmt-subscription — pip install azure-mgmt-subscription · libregistry