Azure Quota Management Client Library

3.0.1 · active · verified Thu Apr 16

The `azure-mgmt-quota` library is the Microsoft Azure Quota Management Client Library for Python. It provides programmatic access to manage Azure resource quotas, including retrieving current limits, checking usage, and requesting quota increases. The current version is 3.0.1, and it follows the Azure SDK release cadence, with frequent updates to align with Azure service changes.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize the `QuotaMgmtClient` using `DefaultAzureCredential`. It relies on environment variables (`AZURE_CLIENT_ID`, `AZURE_TENANT_ID`, `AZURE_CLIENT_SECRET`, `AZURE_SUBSCRIPTION_ID`) for authentication. A simple client initialization is shown; actual quota operations (listing, getting, or updating quotas) require specific resource scopes and resource provider names, which are detailed in the official Azure SDK samples.

import os
from azure.identity import DefaultAzureCredential
from azure.mgmt.quota import QuotaMgmtClient

# Ensure these environment variables are set for DefaultAzureCredential to work:
# AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET, AZURE_SUBSCRIPTION_ID

subscription_id = os.environ.get('AZURE_SUBSCRIPTION_ID', 'YOUR_SUBSCRIPTION_ID')

if subscription_id == 'YOUR_SUBSCRIPTION_ID':
    print("Please set the AZURE_SUBSCRIPTION_ID environment variable.")
    exit(1)

try:
    credential = DefaultAzureCredential()
    client = QuotaMgmtClient(credential=credential, subscription_id=subscription_id)

    # Example: List Azure resource usages for a specific scope (e.g., location)
    # The scope usually follows the format '/subscriptions/{subscriptionId}/providers/{resourceProviderNamespace}/locations/{location}'
    # Or for a specific resource type: '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}'
    # For simplicity, listing operations are often tied to locations and resource providers.

    # This is a simplified example. Real-world usage requires a valid scope.
    # Example scope for listing regional quotas (requires specific resource provider and location)
    # Replace 'eastus' and 'Microsoft.Compute' with your target location and resource provider.
    # Note: Exact API calls and required parameters depend on the specific quota operation (e.g., list, get, create or update).

    print(f"Attempting to list quota operations for subscription: {subscription_id}")
    # Listing all operations is a general way to check service availability, actual quota calls are more specific.
    # For actual quota listing, you'd typically target a specific resource provider and location.

    # A more concrete example to get current usages for 'Microsoft.Compute' in 'eastus'
    # This assumes the 'usages' operation group is available for the client and scope
    # Please refer to the official SDK samples for detailed usage scenarios.
    # The `usages` object might not be directly accessible on the base client; it's an operation group.
    # Correct way to access operations might involve client.usages.list()

    # As per 3.0.0, operation groups are added. Let's try a generic operation to ensure client creation works.
    # A common operation is to list current quotas for a resource provider in a location.
    # The exact method name might vary, check the SDK documentation or samples for `list` or `get` methods.
    
    # Placeholder for actual quota retrieval - this part varies significantly based on specific needs
    # For instance, to list quotas for 'Microsoft.Compute' in 'eastus':
    # It would look something like:
    # scope = "/subscriptions/{}/providers/Microsoft.Compute/locations/eastus".format(subscription_id)
    # current_quotas = client.usages.list(scope=scope)
    # for usage in current_quotas:
    #     print(f"  Resource: {usage.name.value}, Current Value: {usage.current_value}, Limit: {usage.limit}")

    # Let's perform a simple operation that generally works if authentication is successful,
    # such as listing available operations on the client.
    # Note: `QuotaMgmtClient` may not have a direct `operations.list()` method.
    # Actual quota listing requires specific `scope` and `providerName`.
    # A safer quickstart is to ensure the client is initialized.

    print("QuotaMgmtClient initialized successfully.")

except Exception as e:
    print(f"An error occurred: {e}")

view raw JSON →