0
# Service Management
1
2
Account-level operations for managing Azure Tables service including table lifecycle management, service configuration, analytics, and Cross-Origin Resource Sharing (CORS) settings.
3
4
## Capabilities
5
6
### Service Client Initialization
7
8
Create and configure TableServiceClient for account-level operations with various authentication methods.
9
10
```python { .api }
11
class TableServiceClient:
12
def __init__(
13
self,
14
endpoint: str,
15
credential: Optional[Any] = None,
16
*,
17
audience: Optional[str] = None,
18
api_version: Optional[str] = None,
19
**kwargs
20
):
21
"""
22
Initialize TableServiceClient for account-level operations.
23
24
Parameters:
25
- endpoint: Full URL to the Tables account
26
- credential: Authentication credential (AzureNamedKeyCredential, SAS token, etc.)
27
- audience: Service audience for token authentication
28
- api_version: Storage API version to use
29
"""
30
31
@classmethod
32
def from_connection_string(
33
cls,
34
conn_str: str,
35
**kwargs
36
) -> "TableServiceClient":
37
"""
38
Create client from connection string.
39
40
Parameters:
41
- conn_str: Connection string with account credentials
42
43
Returns:
44
TableServiceClient instance
45
"""
46
```
47
48
#### Usage Example
49
50
```python
51
from azure.data.tables import TableServiceClient
52
from azure.core.credentials import AzureNamedKeyCredential
53
54
# From connection string
55
service_client = TableServiceClient.from_connection_string(
56
conn_str="DefaultEndpointsProtocol=https;AccountName=myaccount;AccountKey=mykey"
57
)
58
59
# From endpoint and credential
60
credential = AzureNamedKeyCredential("myaccount", "mykey")
61
service_client = TableServiceClient(
62
endpoint="https://myaccount.table.core.windows.net/",
63
credential=credential
64
)
65
```
66
67
### Table Management
68
69
Create, delete, list, and query tables within the storage account.
70
71
```python { .api }
72
class TableServiceClient:
73
def create_table(self, table_name: str, **kwargs) -> TableClient:
74
"""
75
Create a new table.
76
77
Parameters:
78
- table_name: Name of the table to create
79
80
Returns:
81
TableClient for the created table
82
83
Raises:
84
ResourceExistsError: If table already exists
85
"""
86
87
def create_table_if_not_exists(self, table_name: str, **kwargs) -> TableClient:
88
"""
89
Create table if it doesn't exist.
90
91
Parameters:
92
- table_name: Name of the table
93
94
Returns:
95
TableClient for the table
96
"""
97
98
def delete_table(self, table_name: str, **kwargs) -> None:
99
"""
100
Delete a table.
101
102
Parameters:
103
- table_name: Name of the table to delete
104
105
Raises:
106
ResourceNotFoundError: If table doesn't exist
107
"""
108
109
def list_tables(
110
self,
111
*,
112
results_per_page: Optional[int] = None,
113
**kwargs
114
) -> ItemPaged[TableItem]:
115
"""
116
List all tables in the account.
117
118
Parameters:
119
- results_per_page: Maximum number of tables per page
120
121
Returns:
122
Paged iterator of TableItem objects
123
"""
124
125
def query_tables(
126
self,
127
query_filter: str,
128
*,
129
results_per_page: Optional[int] = None,
130
parameters: Optional[Dict[str, Any]] = None,
131
**kwargs
132
) -> ItemPaged[TableItem]:
133
"""
134
Query tables with OData filter.
135
136
Parameters:
137
- query_filter: OData filter expression
138
- results_per_page: Maximum results per page
139
- parameters: Parameter substitution values
140
141
Returns:
142
Paged iterator of matching TableItem objects
143
"""
144
145
def get_table_client(self, table_name: str, **kwargs) -> TableClient:
146
"""
147
Get TableClient for specific table.
148
149
Parameters:
150
- table_name: Name of the table
151
152
Returns:
153
TableClient instance
154
"""
155
```
156
157
#### Usage Example
158
159
```python
160
from azure.data.tables import TableServiceClient
161
162
service_client = TableServiceClient.from_connection_string(conn_str)
163
164
# Create table
165
table_client = service_client.create_table("customers")
166
167
# List all tables
168
for table in service_client.list_tables():
169
print(f"Table: {table.name}")
170
171
# Query tables by name pattern
172
tables = service_client.query_tables("TableName ge 'c'")
173
for table in tables:
174
print(f"Found table: {table.name}")
175
176
# Delete table
177
service_client.delete_table("old_table")
178
```
179
180
### Service Properties
181
182
Configure service-level settings including analytics logging, metrics collection, and CORS rules.
183
184
```python { .api }
185
class TableServiceClient:
186
def get_service_properties(self, **kwargs) -> Dict[str, object]:
187
"""
188
Get current service properties.
189
190
Returns:
191
Dictionary containing service configuration including:
192
- analytics_logging: TableAnalyticsLogging settings
193
- hour_metrics: TableMetrics for hourly data
194
- minute_metrics: TableMetrics for minute data
195
- cors: List of TableCorsRule objects
196
"""
197
198
def set_service_properties(
199
self,
200
*,
201
analytics_logging: Optional[TableAnalyticsLogging] = None,
202
hour_metrics: Optional[TableMetrics] = None,
203
minute_metrics: Optional[TableMetrics] = None,
204
cors: Optional[List[TableCorsRule]] = None,
205
**kwargs
206
) -> None:
207
"""
208
Set service properties.
209
210
Parameters:
211
- analytics_logging: Logging configuration
212
- hour_metrics: Hourly metrics configuration
213
- minute_metrics: Minute metrics configuration
214
- cors: CORS rules list
215
"""
216
217
def get_service_stats(self, **kwargs) -> Dict[str, object]:
218
"""
219
Get service statistics including geo-replication status.
220
221
Returns:
222
Dictionary with replication statistics
223
224
Note:
225
Only available for read-access geo-redundant storage accounts
226
"""
227
```
228
229
#### Usage Example
230
231
```python
232
from azure.data.tables import (
233
TableServiceClient, TableAnalyticsLogging,
234
TableMetrics, TableRetentionPolicy, TableCorsRule
235
)
236
237
service_client = TableServiceClient.from_connection_string(conn_str)
238
239
# Configure analytics logging
240
logging_config = TableAnalyticsLogging(
241
version="1.0",
242
delete=True,
243
read=True,
244
write=True,
245
retention_policy=TableRetentionPolicy(enabled=True, days=7)
246
)
247
248
# Configure metrics
249
metrics_config = TableMetrics(
250
version="1.0",
251
enabled=True,
252
include_apis=True,
253
retention_policy=TableRetentionPolicy(enabled=True, days=30)
254
)
255
256
# Configure CORS
257
cors_rule = TableCorsRule(
258
allowed_origins=["https://example.com"],
259
allowed_methods=["GET", "POST"],
260
allowed_headers=["x-ms-*"],
261
exposed_headers=["x-ms-*"],
262
max_age_in_seconds=3600
263
)
264
265
# Apply configuration
266
service_client.set_service_properties(
267
analytics_logging=logging_config,
268
hour_metrics=metrics_config,
269
minute_metrics=metrics_config,
270
cors=[cors_rule]
271
)
272
273
# Get current properties
274
properties = service_client.get_service_properties()
275
print(f"Logging enabled: {properties['analytics_logging'].read}")
276
```
277
278
## Data Models
279
280
```python { .api }
281
class TableItem:
282
"""Represents a table in the service."""
283
name: str
284
285
class TableAnalyticsLogging:
286
"""Analytics logging configuration."""
287
def __init__(
288
self,
289
version: str = "1.0",
290
delete: bool = False,
291
read: bool = False,
292
write: bool = False,
293
retention_policy: TableRetentionPolicy = None
294
): ...
295
296
class TableMetrics:
297
"""Service metrics configuration."""
298
def __init__(
299
self,
300
version: str = "1.0",
301
enabled: bool = False,
302
include_apis: bool = None,
303
retention_policy: TableRetentionPolicy = None
304
): ...
305
306
class TableRetentionPolicy:
307
"""Data retention policy."""
308
def __init__(self, enabled: bool = False, days: int = None): ...
309
310
class TableCorsRule:
311
"""Cross-Origin Resource Sharing rule."""
312
def __init__(
313
self,
314
allowed_origins: List[str],
315
allowed_methods: List[str],
316
allowed_headers: List[str],
317
exposed_headers: List[str],
318
max_age_in_seconds: int
319
): ...
320
```