Microsoft Azure Batch Client Library for Python providing comprehensive APIs for managing batch computing workloads in Azure cloud
npx @tessl/cli install tessl/pypi-azure-batch@14.2.0Microsoft Azure Batch Client Library for Python provides comprehensive APIs for managing batch computing workloads in Azure cloud. It enables developers to create, manage, and monitor batch pools (compute nodes), jobs (logical containers for tasks), and tasks (individual work items) with capabilities for resource allocation, job scheduling, task distribution, and monitoring.
pip install azure-batchfrom azure.batch import BatchServiceClient, BatchServiceClientConfiguration
from azure.batch.batch_auth import SharedKeyCredentialsImport specific operations:
from azure.batch.operations import (
PoolOperations, JobOperations, TaskOperations,
ComputeNodeOperations, ApplicationOperations,
CertificateOperations, FileOperations,
JobScheduleOperations, AccountOperations,
ComputeNodeExtensionOperations
)Import model classes:
from azure.batch.models import (
CloudPool, CloudJob, CloudTask, PoolSpecification,
JobSpecification, TaskSpecification, BatchError
)from azure.batch import BatchServiceClient
from azure.batch.batch_auth import SharedKeyCredentials
# Set up authentication
credentials = SharedKeyCredentials(
account_name="your_batch_account",
key="your_account_key"
)
# Create the Batch service client
batch_url = "https://your_batch_account.your_region.batch.azure.com"
client = BatchServiceClient(credentials, batch_url)
# List existing pools
pools = client.pool.list()
for pool in pools:
print(f"Pool ID: {pool.id}, State: {pool.state}")
# Create a new pool
from azure.batch.models import PoolSpecification, CloudServiceConfiguration
pool_spec = PoolSpecification(
id="my-pool",
vm_size="Standard_A1",
cloud_service_configuration=CloudServiceConfiguration(
os_family="4", # Windows Server 2012 R2
target_os_version="*"
),
target_dedicated_nodes=2,
enable_auto_scale=False
)
client.pool.add(pool_spec)
# Create a job
from azure.batch.models import JobSpecification, PoolInformation
job_spec = JobSpecification(
id="my-job",
pool_info=PoolInformation(pool_id="my-pool")
)
client.job.add(job_spec)
# Add a task to the job
from azure.batch.models import TaskSpecification
task_spec = TaskSpecification(
id="my-task",
command_line="echo Hello World"
)
client.task.add("my-job", task_spec)The Azure Batch client follows a resource hierarchy with operation-specific clients:
Each operation class provides full CRUD (Create, Read, Update, Delete) capabilities for its respective resources, along with batch-specific operations like scaling, scheduling, and monitoring.
Core client initialization, configuration, and authentication management for accessing Azure Batch services.
class BatchServiceClient:
def __init__(self, credentials, batch_url): ...
class SharedKeyCredentials:
def __init__(self, account_name: str, key: str): ...Pool management capabilities including creation, deletion, scaling, and monitoring of compute node pools that execute batch workloads.
class PoolOperations:
def add(self, pool, pool_add_options=None, **kwargs): ...
def list(self, pool_list_options=None, **kwargs): ...
def get(self, pool_id, pool_get_options=None, **kwargs): ...
def delete(self, pool_id, pool_delete_options=None, **kwargs): ...
def resize(self, pool_id, pool_resize_parameter, **kwargs): ...
def enable_auto_scale(self, pool_id, auto_scale_formula, **kwargs): ...Job management capabilities for creating, configuring, and controlling logical containers that organize and manage task execution within batch pools.
class JobOperations:
def add(self, job, job_add_options=None, **kwargs): ...
def list(self, job_list_options=None, **kwargs): ...
def get(self, job_id, job_get_options=None, **kwargs): ...
def delete(self, job_id, job_delete_options=None, **kwargs): ...
def enable(self, job_id, job_enable_options=None, **kwargs): ...
def disable(self, job_id, disable_job_parameter, **kwargs): ...
def terminate(self, job_id, job_terminate_parameter=None, **kwargs): ...Task management capabilities for creating, monitoring, and controlling individual work items that execute within batch jobs on compute nodes.
class TaskOperations:
def add(self, job_id, task, task_add_options=None, **kwargs): ...
def add_collection(self, job_id, task_add_collection_parameter, **kwargs): ...
def list(self, job_id, task_list_options=None, **kwargs): ...
def get(self, job_id, task_id, task_get_options=None, **kwargs): ...
def delete(self, job_id, task_id, task_delete_options=None, **kwargs): ...
def update(self, job_id, task_id, task_update_parameter, **kwargs): ...
def terminate(self, job_id, task_id, task_terminate_options=None, **kwargs): ...Compute node management capabilities for managing individual virtual machines within pools, including user management, remote access, and node maintenance operations.
class ComputeNodeOperations:
def list(self, pool_id, compute_node_list_options=None, **kwargs): ...
def get(self, pool_id, node_id, compute_node_get_options=None, **kwargs): ...
def add_user(self, pool_id, node_id, user, **kwargs): ...
def delete_user(self, pool_id, node_id, user_name, **kwargs): ...
def reboot(self, pool_id, node_id, node_reboot_parameter=None, **kwargs): ...
def reimage(self, pool_id, node_id, node_reimage_parameter=None, **kwargs): ...File management capabilities for accessing, downloading, and managing files on compute nodes and task outputs.
class FileOperations:
def list_from_task(self, job_id, task_id, file_list_from_task_options=None, **kwargs): ...
def list_from_compute_node(self, pool_id, node_id, file_list_from_compute_node_options=None, **kwargs): ...
def get_from_task(self, job_id, task_id, file_path, **kwargs): ...
def get_from_compute_node(self, pool_id, node_id, file_path, **kwargs): ...
def delete_from_task(self, job_id, task_id, file_path, **kwargs): ...
def delete_from_compute_node(self, pool_id, node_id, file_path, **kwargs): ...Application package management capabilities for managing and deploying application packages to batch pools and tasks.
class ApplicationOperations:
def list(self, application_list_options=None, **kwargs): ...
def get(self, application_id, application_get_options=None, **kwargs): ...Certificate management capabilities for adding, listing, and managing certificates used for authentication and secure communication in batch operations.
class CertificateOperations:
def add(self, certificate, certificate_add_options=None, **kwargs): ...
def list(self, certificate_list_options=None, **kwargs): ...
def get(self, thumbprint_algorithm, thumbprint, **kwargs): ...
def delete(self, thumbprint_algorithm, thumbprint, **kwargs): ...
def cancel_deletion(self, thumbprint_algorithm, thumbprint, **kwargs): ...Job schedule management capabilities for creating and managing recurring batch jobs with time-based or interval-based scheduling.
class JobScheduleOperations:
def add(self, cloud_job_schedule, job_schedule_add_options=None, **kwargs): ...
def list(self, job_schedule_list_options=None, **kwargs): ...
def get(self, job_schedule_id, job_schedule_get_options=None, **kwargs): ...
def delete(self, job_schedule_id, job_schedule_delete_options=None, **kwargs): ...
def exists(self, job_schedule_id, job_schedule_exists_options=None, **kwargs): ...
def enable(self, job_schedule_id, job_schedule_enable_options=None, **kwargs): ...
def disable(self, job_schedule_id, job_schedule_disable_options=None, **kwargs): ...
def terminate(self, job_schedule_id, job_schedule_terminate_options=None, **kwargs): ...Account-level operations for retrieving information about supported VM images and pool node counts across the batch account.
class AccountOperations:
def list_supported_images(self, account_list_supported_images_options=None, **kwargs): ...
def list_pool_node_counts(self, account_list_pool_node_counts_options=None, **kwargs): ...Compute node extension management capabilities for managing and querying virtual machine extensions on compute nodes within batch pools.
class ComputeNodeExtensionOperations:
def get(self, pool_id, node_id, extension_name, **kwargs): ...
def list(self, pool_id, node_id, **kwargs): ...Compute Node Extension Operations
class CloudPool:
"""Pool information and configuration."""
def __init__(self):
self.id: str
self.state: str # PoolState enum
self.vm_size: str
self.target_dedicated_nodes: int
self.current_dedicated_nodes: int
self.enable_auto_scale: bool
self.auto_scale_formula: str
class CloudJob:
"""Job information and configuration."""
def __init__(self):
self.id: str
self.state: str # JobState enum
self.pool_info: PoolInformation
self.priority: int
self.constraints: JobConstraints
self.job_manager_task: JobManagerTask
class CloudTask:
"""Task information and configuration."""
def __init__(self):
self.id: str
self.state: str # TaskState enum
self.command_line: str
self.execution_info: TaskExecutionInformation
self.resource_files: List[ResourceFile]
self.output_files: List[OutputFile]
self.environment_settings: List[EnvironmentSetting]
class ComputeNode:
"""Compute node information and status."""
def __init__(self):
self.id: str
self.state: str # ComputeNodeState enum
self.vm_size: str
self.ip_address: str
self.total_tasks_run: int
self.running_tasks_count: intclass PoolSpecification:
"""Pool creation/update specification."""
def __init__(self):
self.id: str
self.vm_size: str
self.cloud_service_configuration: CloudServiceConfiguration
self.virtual_machine_configuration: VirtualMachineConfiguration
self.target_dedicated_nodes: int
self.target_low_priority_nodes: int
self.enable_auto_scale: bool
self.auto_scale_formula: str
self.start_task: StartTask
self.certificates: List[CertificateReference]
self.application_packages: List[ApplicationPackageReference]
class JobSpecification:
"""Job creation/update specification."""
def __init__(self):
self.id: str
self.pool_info: PoolInformation
self.priority: int
self.constraints: JobConstraints
self.job_manager_task: JobManagerTask
self.job_preparation_task: JobPreparationTask
self.job_release_task: JobReleaseTask
self.common_environment_settings: List[EnvironmentSetting]
class TaskSpecification:
"""Task creation/update specification."""
def __init__(self):
self.id: str
self.command_line: str
self.resource_files: List[ResourceFile]
self.output_files: List[OutputFile]
self.environment_settings: List[EnvironmentSetting]
self.constraints: TaskConstraints
self.user_identity: UserIdentity
self.depends_on: TaskDependenciesclass SharedKeyCredentials:
"""Shared key authentication for Azure Batch."""
def __init__(self, account_name: str, key: str): ...
def signed_session(self, session=None): ...
class BatchServiceClientConfiguration:
"""Configuration for BatchServiceClient."""
def __init__(self, credentials, batch_url: str): ...class BatchError:
"""Batch service error information."""
def __init__(self):
self.code: str
self.message: str
self.values: List[BatchErrorDetail]
class BatchErrorException(Exception):
"""Exception for Batch service errors."""
def __init__(self, message: str, response, error: BatchError): ...