{"id":969,"library":"azure-batch","title":"Azure Batch Client Library for Python","description":"The `azure-batch` client library for Python enables users to configure compute nodes and pools, define tasks, and manage jobs for large-scale parallel and high-performance computing (HPC) applications in Azure. The current stable version is 14.2.0, with ongoing development as part of the broader Azure SDK for Python, which typically sees monthly releases for various packages.","status":"active","version":"14.2.0","language":"python","source_language":"en","source_url":"https://github.com/Azure/azure-sdk-for-python","tags":["azure","batch","hpc","cloud computing","microsoft entra id","task scheduling"],"install":[{"cmd":"pip install azure-batch azure-identity","lang":"bash","label":"Install stable version with Azure Identity"},{"cmd":"pip install azure-batch==15.1.0b3 azure-identity","lang":"bash","label":"Install latest preview (v15+) with Azure Identity"}],"dependencies":[{"reason":"Recommended for modern Azure Active Directory (Entra ID) authentication.","package":"azure-identity","optional":false},{"reason":"Often used in conjunction with Azure Batch for input/output data storage.","package":"azure-storage-blob","optional":true}],"imports":[{"note":"Direct import from the top-level package is standard.","wrong":"from azure.batch.batch_service_client import BatchServiceClient","symbol":"BatchServiceClient","correct":"from azure.batch import BatchServiceClient"},{"note":"Models are typically exposed directly under the `azure.batch` namespace for convenience.","wrong":"from azure.batch.models import ...","symbol":"models","correct":"from azure.batch import models"},{"note":"The standard credential type for authenticating with Azure services using Microsoft Entra ID.","symbol":"DefaultAzureCredential","correct":"from azure.identity import DefaultAzureCredential"},{"note":"Used for shared key authentication, though Microsoft Entra ID is now recommended.","symbol":"SharedKeyCredentials","correct":"from azure.batch.batch_auth import SharedKeyCredentials"}],"quickstart":{"code":"import os\nfrom azure.batch import BatchServiceClient\nfrom azure.identity import DefaultAzureCredential\n\n# Retrieve Batch account details from environment variables\nbatch_account_url = os.environ.get(\"AZURE_BATCH_ACCOUNT_URL\", \"https://<your-batch-account>.westus.batch.azure.com\")\n\n# Authenticate using DefaultAzureCredential (recommended for Azure AD)\n# This will attempt to authenticate via environment variables, managed identity, etc.\ntry:\n    credential = DefaultAzureCredential()\n    batch_client = BatchServiceClient(credential, batch_url=batch_account_url)\n    \n    # Example: List existing pools\n    pools = batch_client.pool.list()\n    print(f\"Successfully connected to Azure Batch. Found {len(pools)} pools.\")\n    for pool in pools:\n        print(f\"  - Pool ID: {pool.id}, VM Size: {pool.vm_size}\")\n\nexcept Exception as e:\n    print(f\"Error connecting to Azure Batch: {e}\")\n    print(\"Please ensure AZURE_BATCH_ACCOUNT_URL is set and your environment is authenticated (e.g., via Azure CLI).\")\n\n# For shared key authentication (less recommended, but available):\n# batch_account_name = os.environ.get(\"AZURE_BATCH_ACCOUNT_NAME\", \"<your-batch-account-name>\")\n# batch_account_key = os.environ.get(\"AZURE_BATCH_ACCOUNT_KEY\", \"<your-batch-account-key>\")\n# if batch_account_name and batch_account_key:\n#     from azure.batch.batch_auth import SharedKeyCredentials\n#     creds = SharedKeyCredentials(batch_account_name, batch_account_key)\n#     batch_client_shared_key = BatchServiceClient(creds, batch_url=batch_account_url)\n#     print(\"Successfully connected with Shared Key credentials.\")\n","lang":"python","description":"This quickstart demonstrates how to instantiate `BatchServiceClient` using the recommended `DefaultAzureCredential` from `azure-identity`. It retrieves the Batch account URL from an environment variable and then lists the existing pools. For shared key authentication, an alternative commented-out section is provided."},"warnings":[{"fix":"Consult the official migration guide for `azure-batch` in the Azure SDK for Python GitHub repository to adapt your code. This often involves changes to client instantiation and model usage.","message":"Version 15.x and above introduces significant changes and improvements from v14.x and below. A migration guide is available in the official GitHub repository's README.","severity":"breaking","affected_versions":">=15.0.0"},{"fix":"Remove calls to `get_all_lifetime_statistics` methods. You may need to implement custom logic to track lifetime statistics if needed, using other available APIs.","message":"The `lifetime statistics API` was removed in version 14.0.0. Specifically, `job.get_all_lifetime_statistics` and `pool.get_all_lifetime_statistics` are no longer supported.","severity":"breaking","affected_versions":">=14.0.0"},{"fix":"Migrate any certificate management logic to use Azure KeyVault Extension. Avoid using the deprecated CertificateOperations methods.","message":"CertificateOperations-related methods were deprecated in version 14.0.0 and were scheduled for removal after February 2024. Users are advised to use Azure KeyVault Extension instead.","severity":"deprecated","affected_versions":">=14.0.0"},{"fix":"Always prefer `DefaultAzureCredential` from `azure-identity` for authentication. Ensure your application or user principal has appropriate Azure RBAC roles assigned to the Batch account.","message":"Microsoft Entra ID (formerly Azure AD) authentication using `azure-identity` and `DefaultAzureCredential` is strongly recommended for `azure-batch`. Some Batch capabilities require this, and Batch account API authentication can be restricted to only Microsoft Entra ID, rejecting shared key authentication.","severity":"gotcha","affected_versions":"All"},{"fix":"Use a platform image that comes with a suitable Python environment (e.g., Ubuntu 18.04 LTS for Python 3.6). If custom packages are needed, use a `StartTask` to install them (e.g., `pip install -r requirements.txt`) or consider custom VM images. Ensure correct paths for Python executables.","message":"When installing packages on Batch compute nodes, if using StartTask, ensure the Python environment is correctly set up. Common issues include `pip` not being recognized or incorrect Python versions.","severity":"gotcha","affected_versions":"All"},{"fix":"If longer retention is required, explicitly set the `retention_time` property when creating tasks or jobs. Ensure critical output files are persisted to an Azure Storage account.","message":"The default task retention time for all tasks was changed from infinite to 7 days. This means task-related files and stdout/stderr logs will only be available for 7 days by default.","severity":"gotcha","affected_versions":"<=14.x (changed in an older version, but still a common pitfall)"}],"env_vars":null,"last_verified":"2026-05-12T21:56:27.418Z","next_check":"2026-06-27T00:00:00.000Z","problems":[{"fix":"Install the package using pip: 'pip install azure-batch'.","cause":"The 'azure-batch' package is not installed in the Python environment.","error":"ModuleNotFoundError: No module named 'azure.batch'"},{"fix":"Use 'batch_service_client.job_operations' instead of 'batch_service_client.job'.","cause":"The 'BatchServiceClient' object does not have a 'job' attribute; the correct attribute is 'job_operations'.","error":"AttributeError: 'BatchServiceClient' object has no attribute 'job'"},{"fix":"Provide the 'batch_url' parameter when creating the client: 'BatchServiceClient(credentials, batch_url)'.","cause":"The 'batch_url' parameter is required when initializing 'BatchServiceClient'.","error":"TypeError: __init__() missing 1 required positional argument: 'batch_url'"},{"fix":"Use 'from azure.batch import BatchServiceClient' instead of 'from azure.batch.models import BatchServiceClient'.","cause":"The import statement is incorrect; 'BatchServiceClient' should be imported from 'azure.batch' directly.","error":"ImportError: cannot import name 'BatchServiceClient' from 'azure.batch'"},{"fix":"Ensure that the 'id' parameter is provided and not None when creating a job or pool.","cause":"The 'id' parameter is missing or set to None when creating a job or pool.","error":"ValueError: The 'id' parameter is required and cannot be None."}],"ecosystem":"pypi","meta_description":null,"install_score":100,"install_tag":"verified","quickstart_score":null,"quickstart_tag":null,"pypi_latest":"15.1.0","cli_name":"","install_checks":{"last_tested":"2026-05-12","tag":"verified","tag_description":"installs cleanly on critical runtimes, fast import, recently tested","results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":"45.6M"},{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":1.07,"mem_mb":18,"disk_size":"47.7M"},{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":"45.6M"},{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":3.8,"import_time_s":null,"mem_mb":null,"disk_size":"46M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.78,"mem_mb":18,"disk_size":"48M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":3.9,"import_time_s":null,"mem_mb":null,"disk_size":"46M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":"49.6M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":1.41,"mem_mb":19.4,"disk_size":"51.9M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":"49.6M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":3.7,"import_time_s":null,"mem_mb":null,"disk_size":"50M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":1.09,"mem_mb":19.4,"disk_size":"52M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":3.8,"import_time_s":null,"mem_mb":null,"disk_size":"50M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":"41.0M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":1.25,"mem_mb":19.5,"disk_size":"43.2M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":"41.0M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":3.2,"import_time_s":null,"mem_mb":null,"disk_size":"41M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":1.3,"mem_mb":19.5,"disk_size":"44M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":3.3,"import_time_s":null,"mem_mb":null,"disk_size":"41M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":"40.7M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":1.19,"mem_mb":19.9,"disk_size":"42.8M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":"40.7M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":3.3,"import_time_s":null,"mem_mb":null,"disk_size":"41M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":1.22,"mem_mb":19.9,"disk_size":"43M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":3.4,"import_time_s":null,"mem_mb":null,"disk_size":"41M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":"45.7M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":1.02,"mem_mb":17.5,"disk_size":"47.8M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":"45.6M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":4.4,"import_time_s":null,"mem_mb":null,"disk_size":"46M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.96,"mem_mb":17.5,"disk_size":"48M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":4.3,"import_time_s":null,"mem_mb":null,"disk_size":"46M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null}]},"quickstart_checks":{"last_tested":"2026-04-24","tag":null,"tag_description":null,"results":[{"runtime":"python:3.10-alpine","exit_code":0},{"runtime":"python:3.10-slim","exit_code":0},{"runtime":"python:3.11-alpine","exit_code":0},{"runtime":"python:3.11-slim","exit_code":0},{"runtime":"python:3.12-alpine","exit_code":0},{"runtime":"python:3.12-slim","exit_code":0},{"runtime":"python:3.13-alpine","exit_code":0},{"runtime":"python:3.13-slim","exit_code":0},{"runtime":"python:3.9-alpine","exit_code":0},{"runtime":"python:3.9-slim","exit_code":0}]}}