{"id":1355,"library":"azure-mgmt-batch","title":"Azure Batch Management Client Library","description":"The Azure Batch Management Client Library for Python, currently at version 19.0.0, allows developers to programmatically manage Azure Batch accounts, pools, and jobs. It provides interfaces for creating, updating, deleting, and querying Batch resources within an Azure subscription. Releases are frequent, typically aligned with new Azure Batch service API versions and broader Azure SDK updates.","status":"active","version":"19.0.0","language":"en","source_language":"en","source_url":"https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/batch/azure-mgmt-batch","tags":["azure","batch","management","cloud","paas"],"install":[{"cmd":"pip install azure-mgmt-batch azure-identity","lang":"bash","label":"Install core library and authentication"}],"dependencies":[{"reason":"Required for authentication using Azure Active Directory credentials, such as DefaultAzureCredential.","package":"azure-identity","optional":false}],"imports":[{"symbol":"BatchManagementClient","correct":"from azure.mgmt.batch import BatchManagementClient"},{"symbol":"DefaultAzureCredential","correct":"from azure.identity import DefaultAzureCredential"}],"quickstart":{"code":"import os\nfrom azure.identity import DefaultAzureCredential\nfrom azure.mgmt.batch import BatchManagementClient\n\n# Ensure you have your Azure Subscription ID set as an environment variable (AZURE_SUBSCRIPTION_ID)\n# or replace 'YOUR_SUBSCRIPTION_ID' with your actual subscription ID.\nsubscription_id = os.environ.get(\"AZURE_SUBSCRIPTION_ID\", \"YOUR_SUBSCRIPTION_ID\")\n\nif subscription_id == \"YOUR_SUBSCRIPTION_ID\":\n    print(\"WARNING: AZURE_SUBSCRIPTION_ID environment variable not set. Using placeholder.\")\n    print(\"Please set AZURE_SUBSCRIPTION_ID for actual resource management.\")\n\ntry:\n    # Acquire a credential object for authentication\n    credential = DefaultAzureCredential()\n\n    # Create a BatchManagementClient instance\n    batch_client = BatchManagementClient(credential, subscription_id)\n\n    print(f\"Listing Batch accounts in subscription: {subscription_id}\")\n    \n    # List all Batch accounts in the current subscription\n    # This operation is synchronous.\n    batch_accounts = batch_client.batch_account.list_by_subscription()\n\n    found_accounts = 0\n    for account in batch_accounts:\n        print(f\"- Account name: {account.name}, Location: {account.location}, Provisioning State: {account.provisioning_state.value}\")\n        found_accounts += 1\n    \n    if found_accounts == 0:\n        print(\"No Batch accounts found in this subscription.\")\n\nexcept Exception as e:\n    print(f\"An error occurred: {e}\")\n    print(\"Please ensure you have set AZURE_SUBSCRIPTION_ID and are authenticated (e.g., via Azure CLI 'az login' or environment variables for a Service Principal).\")","lang":"python","description":"This quickstart demonstrates how to authenticate with Azure and list existing Azure Batch accounts within a subscription. It uses `DefaultAzureCredential` for flexible authentication and `BatchManagementClient` to interact with the Azure Batch management plane."},"warnings":[{"fix":"Always consult the `CHANGELOG.md` file in the package's GitHub directory (e.g., `sdk/batch/azure-mgmt-batch/CHANGELOG.md`) for specific changes when upgrading major versions. Update your code based on the new API patterns.","message":"Major version increments (e.g., 18.x.x to 19.x.x) often signify an update to a newer Azure Batch service API version. This regularly involves breaking changes to model schemas, parameter names, and client method signatures. For instance, version 19.0.0 updated to API version 2024-02-01 and included model and parameter renames.","severity":"breaking","affected_versions":"All major version transitions (e.g., 17.x.x -> 18.x.x, 18.x.x -> 19.x.x)."},{"fix":"Ensure necessary environment variables are configured for service principal authentication, or authenticate interactively using `az login` (Azure CLI) or `Connect-AzAccount` (Azure PowerShell). Verify the identity you are using has the 'Contributor' or 'Batch Account Contributor' role on the target subscription/resource group.","message":"Authentication with `DefaultAzureCredential` can fail with `CredentialUnavailableError` if required environment variables (e.g., `AZURE_CLIENT_ID`, `AZURE_TENANT_ID`, `AZURE_CLIENT_SECRET` for a Service Principal) are not set, or if you are not logged in via Azure CLI (`az login`) or other supported means.","severity":"gotcha","affected_versions":"All versions using `azure-identity` for authentication."},{"fix":"When performing operations that return a poller, make sure to call `.result()` on the poller object (e.g., `poller.result()`) to block until the operation finishes and get its final outcome.","message":"Many operations that modify or create resources (e.g., `create`, `update`, `delete`) are Long-Running Operations (LROs) that return a poller object. It's crucial to `wait()` on this poller (for synchronous clients) or `await` its completion (for asynchronous clients) to ensure the operation completes successfully and to retrieve the final result.","severity":"gotcha","affected_versions":"All versions, for operations that create or modify resources."}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}