0
# Client Management
1
2
Core client initialization, configuration, and authentication management for accessing Azure Batch services. The client provides the main entry point for all Batch operations and handles authentication, configuration, and operation routing.
3
4
## Capabilities
5
6
### BatchServiceClient
7
8
The primary client class for issuing REST requests to the Azure Batch service. Provides access to all Batch operations through specialized operation classes.
9
10
```python { .api }
11
class BatchServiceClient:
12
"""
13
A client for issuing REST requests to the Azure Batch service.
14
15
Args:
16
credentials: Authentication credentials (SharedKeyCredentials or Azure AD)
17
batch_url: Base URL for Azure Batch service requests
18
19
Attributes:
20
application: ApplicationOperations instance
21
pool: PoolOperations instance
22
account: AccountOperations instance
23
certificate: CertificateOperations instance
24
file: FileOperations instance
25
job_schedule: JobScheduleOperations instance
26
job: JobOperations instance
27
task: TaskOperations instance
28
compute_node: ComputeNodeOperations instance
29
compute_node_extension: ComputeNodeExtensionOperations instance
30
api_version: API version string (2024-02-01.19.0)
31
"""
32
def __init__(self, credentials, batch_url: str): ...
33
```
34
35
### SharedKeyCredentials
36
37
Shared key authentication for Azure Batch using account name and access key. This is the most common authentication method for Batch applications.
38
39
```python { .api }
40
class SharedKeyCredentials:
41
"""
42
Shared key authentication for Azure Batch.
43
44
Args:
45
account_name: Name of the Batch account
46
key: Primary or secondary access key for the account
47
"""
48
def __init__(self, account_name: str, key: str): ...
49
def signed_session(self, session=None): ...
50
```
51
52
### BatchServiceClientConfiguration
53
54
Configuration settings for the BatchServiceClient including credentials, endpoint, and request settings.
55
56
```python { .api }
57
class BatchServiceClientConfiguration:
58
"""
59
Configuration for BatchServiceClient.
60
61
Args:
62
credentials: Authentication credentials
63
batch_url: Base URL for Batch service
64
"""
65
def __init__(self, credentials, batch_url: str): ...
66
```
67
68
## Usage Examples
69
70
### Basic Client Setup
71
72
```python
73
from azure.batch import BatchServiceClient
74
from azure.batch.batch_auth import SharedKeyCredentials
75
76
# Create credentials
77
credentials = SharedKeyCredentials(
78
account_name="mybatchaccount",
79
key="your_primary_or_secondary_key"
80
)
81
82
# Create client
83
batch_url = "https://mybatchaccount.eastus.batch.azure.com"
84
client = BatchServiceClient(credentials, batch_url)
85
86
# Access operations
87
pools = client.pool.list()
88
jobs = client.job.list()
89
```
90
91
### Error Handling
92
93
```python
94
from azure.batch.models import BatchErrorException
95
96
try:
97
pool = client.pool.get("nonexistent-pool")
98
except BatchErrorException as e:
99
print(f"Batch error: {e.error.code} - {e.error.message}")
100
for detail in e.error.values:
101
print(f" {detail.key}: {detail.value}")
102
```
103
104
### Using Different Authentication
105
106
```python
107
# With Azure Active Directory (requires azure-identity)
108
from azure.identity import DefaultAzureCredential
109
from msrest.authentication import TokenCredential
110
111
# For Azure AD authentication, use the standard Azure identity libraries
112
credential = DefaultAzureCredential()
113
# Note: Azure Batch typically uses SharedKeyCredentials
114
# Azure AD auth requires additional configuration
115
```
116
117
## Types
118
119
### Configuration Types
120
121
```python { .api }
122
class BatchServiceClientConfiguration:
123
"""Client configuration settings."""
124
def __init__(self):
125
self.credentials: Any
126
self.batch_url: str
127
self.base_url: str
128
self.filepath: str
129
```
130
131
### Authentication Types
132
133
```python { .api }
134
class SharedKeyAuth:
135
"""Internal shared key authentication implementation."""
136
def __init__(self, header: str, account_name: str, key: str): ...
137
def __call__(self, request): ...
138
```