Skip to content

Latest commit

 

History

History
108 lines (86 loc) · 3.44 KB

File metadata and controls

108 lines (86 loc) · 3.44 KB
titledescriptionms.datems.topicms.devlangms.service
Azure Batch SDK for Python
Reference for Azure Batch SDK for Python
04/28/2025
reference
python
batch

Azure Batch libraries for python

Overview

Run large-scale parallel and high-performance computing applications efficiently in the cloud with Azure Batch.

To get started with Azure Batch, see Create a Batch account with the Azure portal.

Install the libraries

Client library

The Azure Batch client libraries let you configure compute nodes and pools, define tasks and configure them to run in jobs, and set up a job manager to control and monitor job execution. Learn more about using these objects to run large-scale parallel compute solutions.

pip install azure-batch

Example

Set up a pool of Linux compute nodes in a batch account:

importazure.batchfromazure.batchimportbatch_auth, BatchServiceClient, models# create the batch client for an account using its URI and keyscreds=batch_auth.SharedKeyCredentials(account, key) client=BatchServiceClient(creds, batch_url) # Create the VirtualMachineConfiguration, specifying# the VM image reference and the Batch node agent to# be installed on the node.vmc=models.VirtualMachineConfiguration( image_reference=models.ImageReference( publisher='Canonical', offer='UbuntuServer', sku='18.04-LTS' ), node_agent_sku_id="batch.node.ubuntu 18.04") # Assign the virtual machine configuration to the poolnew_pool=models.PoolAddParameter( id='new_pool', vm_size='standard_d2_v2', virtual_machine_configuration=vmc ) # Create pool in the Batch serviceclient.pool.add(new_pool)

[!div class="nextstepaction"] Explore the Client APIs

Management API

Use the Azure Batch management libraries to create and delete batch accounts, read and regenerate batch account keys, and manage batch account storage.

pip install azure-mgmt-batch

Example

Create an Azure Batch account and configure a new application and Azure storage account for it.

fromazure.mgmt.batchimportBatchManagementClientfromazure.mgmt.resourceimportResourceManagementClientfromazure.mgmt.storageimportStorageManagementClientLOCATION='eastus'GROUP_NAME='batchresourcegroup'STORAGE_ACCOUNT_NAME='batchstorageaccount'# Create Resource groupprint('Create Resource Group') resource_client.resource_groups.create_or_update(GROUP_NAME, {'location': LOCATION}) # Create a storage accountstorage_async_operation=storage_client.storage_accounts.create( GROUP_NAME, STORAGE_ACCOUNT_NAME, StorageAccountCreateParameters( sku=Sku(SkuName.standard_ragrs), kind=Kind.storage, location=LOCATION ) ) storage_account=storage_async_operation.result() # Create a Batch Account, specifying the storage account we want to linkstorage_resource=storage_account.idbatch_account_parameters=azure.mgmt.batch.models.BatchAccountCreateParameters( location=LOCATION, auto_storage=azure.mgmt.batch.models.AutoStorageBaseProperties(storage_resource) ) creating=batch_client.batch_account.begin_create('MyBatchResourceGroup', 'MyBatchAccount', batch_account_parameters) creating.wait()

[!div class="nextstepaction"] Explore the Management APIs

close