{"id":2406,"library":"azure-mgmt-reservations","title":"Microsoft Azure Reservations Client Library for Python","description":"The `azure-mgmt-reservations` library provides a Python interface for managing Azure Reservations. This allows users to programmatically interact with Azure Reservations, such as purchasing, viewing, and managing reserved instances. It is part of the new generation of Azure SDKs, following consistent design guidelines, and the current stable version is 2.3.0. The library typically follows the Azure SDK's release cadence, with updates often coinciding with API version changes or new feature rollouts.","status":"active","version":"2.3.0","language":"en","source_language":"en","source_url":"https://github.com/Azure/azure-sdk-for-python","tags":["azure","cloud","reservations","management","sdk"],"install":[{"cmd":"pip install azure-mgmt-reservations azure-identity","lang":"bash","label":"Install with pip"}],"dependencies":[{"reason":"Required for Azure Active Directory token authentication with DefaultAzureCredential or other credential types.","package":"azure-identity","optional":false},{"reason":"Core shared components for Azure SDK client libraries. Implicitly installed.","package":"azure-core","optional":false}],"imports":[{"note":"As of v0.4.0 and later, top-level client imports moved to the package root.","wrong":"from azure.mgmt.reservations.azure_reservation_api import AzureReservationAPI","symbol":"AzureReservationAPI","correct":"from azure.mgmt.reservations import AzureReservationAPI"},{"symbol":"DefaultAzureCredential","correct":"from azure.identity import DefaultAzureCredential"}],"quickstart":{"code":"import os\nfrom azure.identity import DefaultAzureCredential\nfrom azure.mgmt.reservations import AzureReservationAPI\n\n# Set these environment variables or replace with your actual values for a production setup\n# AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET for DefaultAzureCredential (Service Principal)\n# AZURE_SUBSCRIPTION_ID for the Reservations client\nsubscription_id = os.environ.get(\"AZURE_SUBSCRIPTION_ID\", \"your_subscription_id_here\")\n\n# Authenticate using DefaultAzureCredential\n# This credential type tries various authentication methods, like environment variables,\n# managed identity, or Azure CLI login.\ncredential = DefaultAzureCredential()\n\n# Create a Reservations Management client\nclient = AzureReservationAPI(credential=credential, subscription_id=subscription_id)\n\n# List all reservation orders\nprint(\"Listing reservation orders:\")\nfor order in client.reservation_order.list():\n    print(f\"  Order ID: {order.id}, Display Name: {order.display_name}, Status: {order.provisioning_state}\")\n\n# You can also list reservations within an order, for example:\n# if client.reservation_order.list():\n#     first_order_id = client.reservation_order.list().next().name # Assuming at least one order exists\n#     print(f\"\\nListing reservations for order {first_order_id}:\")\n#     for reservation in client.reservation.list(reservation_order_id=first_order_id):\n#         print(f\"  Reservation ID: {reservation.id}, Scope: {reservation.scope}, Quantity: {reservation.quantity}\")","lang":"python","description":"This quickstart demonstrates how to authenticate with `DefaultAzureCredential` and list Azure Reservation Orders using the `azure-mgmt-reservations` library. Ensure `AZURE_SUBSCRIPTION_ID` and other necessary Azure AD environment variables (e.g., `AZURE_CLIENT_ID`, `AZURE_TENANT_ID`, `AZURE_CLIENT_SECRET`) are set for `DefaultAzureCredential` to function correctly."},"warnings":[{"fix":"Update authentication logic to use `azure-identity` and replace `credentials` keyword argument with `credential`.","message":"The credential system was completely revamped in versions around 1.0.0b1/1.0.0, moving away from `azure.common.credentials` or `msrestazure.azure_active_directory`. Use `azure-identity` classes (e.g., `DefaultAzureCredential`) instead. The client constructor's `credentials` parameter was renamed to `credential`.","severity":"breaking","affected_versions":"<1.0.0"},{"fix":"Adjust code to use `begin_` prefixed methods for LROs and handle `azure.core.exceptions.HttpResponseError` for general API errors.","message":"Starting with versions around 1.0.0, operations returning a long-running poller now return `azure.core.polling.LROPoller` instead of `msrest.polling.LROPoller` and are typically prefixed with `begin_`. Additionally, `CloudError` was removed, and most exceptions are now `azure.core.exceptions.HttpResponseError`.","severity":"breaking","affected_versions":"<1.0.0"},{"fix":"Update import statements to directly import client and model classes from their top-level package or `models` submodule (e.g., `from azure.mgmt.reservations import AzureReservationAPI`).","message":"Import paths for client classes and models changed, particularly around v0.4.0. Importing `AzureReservationAPI` or models from submodules (e.g., `azure.mgmt.reservations.azure_reservation_api` or `azure.mgmt.reservations.models.my_class`) is no longer supported; they should be imported directly from the `azure.mgmt.reservations` or `azure.mgmt.reservations.models` package respectively.","severity":"breaking","affected_versions":"<0.4.0"},{"fix":"Ensure environment variables `AZURE_CLIENT_ID`, `AZURE_TENANT_ID`, `AZURE_CLIENT_SECRET`, and `AZURE_SUBSCRIPTION_ID` are correctly set, or explicitly pass credentials/subscription ID in a production environment.","message":"Authentication with `DefaultAzureCredential` relies on specific environment variables (`AZURE_CLIENT_ID`, `AZURE_TENANT_ID`, `AZURE_CLIENT_SECRET`) for service principal authentication, and `AZURE_SUBSCRIPTION_ID` is crucial for client instantiation. Misconfiguration is a common source of authentication errors.","severity":"gotcha","affected_versions":"All versions >=1.0.0"},{"fix":"Verify that the authenticated identity (user or service principal) has the necessary Reservation-specific RBAC roles or Billing Admin roles applied at the correct scope to perform the desired operations.","message":"Permissions for managing Azure Reservations are distinct and do not inherit from Azure subscription permissions. Users need specific Reservation RBAC roles (e.g., Reservations Administrator, Contributor, Reader) or relevant Billing Admin roles to view and manage reservations.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure your development and deployment environments are running Python 3.7 or a newer compatible version.","message":"Python 2.7 support for Azure SDK Python packages, including `azure-mgmt-reservations`, officially ended on January 1, 2022. The library now requires Python 3.7+.","severity":"gotcha","affected_versions":"All versions >=1.0.0"}],"env_vars":null,"last_verified":"2026-04-10T00:00:00.000Z","next_check":"2026-07-09T00:00:00.000Z"}