Install & Compatibility
Where this runs
tested against v19.0.0 · 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
muslpy 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.634s · 44.8MB
glibcpy 3.10–3.95 runs
installs and imports cleanly · install 3.8s · import 0.576s · 45MB
44MB installed
● package 44MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
BatchManagementClient
✓ from azure.mgmt.batch import BatchManagementClient
DefaultAzureCredential
✓ from azure.identity import DefaultAzureCredential
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.
import os
from azure.identity import DefaultAzureCredential
from azure.mgmt.batch import BatchManagementClient
# Ensure you have your Azure Subscription ID set as an environment variable (AZURE_SUBSCRIPTION_ID)
# or replace 'YOUR_SUBSCRIPTION_ID' with your actual subscription ID.
subscription_id = os.environ.get("AZURE_SUBSCRIPTION_ID", "YOUR_SUBSCRIPTION_ID")
if subscription_id == "YOUR_SUBSCRIPTION_ID":
print("WARNING: AZURE_SUBSCRIPTION_ID environment variable not set. Using placeholder.")
print("Please set AZURE_SUBSCRIPTION_ID for actual resource management.")
try:
# Acquire a credential object for authentication
credential = DefaultAzureCredential()
# Create a BatchManagementClient instance
batch_client = BatchManagementClient(credential, subscription_id)
print(f"Listing Batch accounts in subscription: {subscription_id}")
# List all Batch accounts in the current subscription
# This operation is synchronous.
batch_accounts = batch_client.batch_account.list_by_subscription()
found_accounts = 0
for account in batch_accounts:
print(f"- Account name: {account.name}, Location: {account.location}, Provisioning State: {account.provisioning_state.value}")
found_accounts += 1
if found_accounts == 0:
print("No Batch accounts found in this subscription.")
except Exception as e:
print(f"An error occurred: {e}")
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).")
Debug
Known issues
breakingMajor 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.fixAlways 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.
affects: All major version transitions (e.g., 17.x.x -> 18.x.x, 18.x.x -> 19.x.x).
gotchaAuthentication 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.fixEnsure 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.
affects: All versions using `azure-identity` for authentication.
gotchaMany 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.fixWhen 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.
affects: All versions, for operations that create or modify resources.
Upgrade
Version history
19.0.0latest on PyPI · released Mar 12, 2026
Audit
Dependencies
azure-identityrequiredRequired for authentication using Azure Active Directory credentials, such as DefaultAzureCredential.