Microsoft Azure Developer LoadTesting Client Library for Python providing programmatic access to Azure's load testing platform.
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Complete management of load test definitions, test scripts, and configuration through the LoadTestAdministrationClient. This includes creating and updating test definitions, uploading JMeter scripts and supporting files, configuring application components for monitoring, and setting up server-side metrics collection.
Create, update, retrieve, and delete load test definitions. Tests define the basic configuration including display name, description, engine instances, and pass/fail criteria.
def create_or_update_test(test_id: str, body: Union[JSON, IO], **kwargs) -> JSON:
"""
Create a new test or update an existing test.
Parameters:
- test_id (str): Unique name for the load test (2-50 chars, lowercase alphanumeric, underscore, hyphen)
- body (Union[JSON, IO]): Load test definition
Returns:
JSON: Test definition with metadata
"""
def delete_test(test_id: str, **kwargs) -> None:
"""
Delete a test by its ID.
Parameters:
- test_id (str): Unique test identifier
"""
def get_test(test_id: str, **kwargs) -> JSON:
"""
Get load test details by ID.
Parameters:
- test_id (str): Unique test identifier
Returns:
JSON: Test definition with metadata
"""
def list_tests(
*,
orderby: Optional[str] = None,
search: Optional[str] = None,
last_modified_start_time: Optional[datetime] = None,
last_modified_end_time: Optional[datetime] = None,
**kwargs
) -> Iterable[JSON]:
"""
List all load tests with optional filtering.
Parameters:
- orderby (str, optional): Sort order ("lastModifiedDateTime asc" or "lastModifiedDateTime desc")
- search (str, optional): Search filter by displayName or createdBy
- last_modified_start_time (datetime, optional): Filter by last modified start time
- last_modified_end_time (datetime, optional): Filter by last modified end time
Returns:
Iterable[JSON]: Paginated list of test definitions
"""from azure.core.credentials import DefaultAzureCredential
from azure.developer.loadtesting import LoadTestAdministrationClient
credential = DefaultAzureCredential()
client = LoadTestAdministrationClient(
endpoint="https://your-resource.loadtest.azure.com",
credential=credential
)
# Define test configuration
test_definition = {
"displayName": "API Performance Test",
"description": "Load test for REST API endpoints",
"loadTestConfiguration": {
"engineInstances": 1,
"splitAllCSVs": False
},
"passFailCriteria": {
"passFailMetrics": {
"response_time_95": {
"clientMetric": "response_time_ms",
"aggregate": "percentage",
"condition": "<=",
"value": 1000.0
}
}
}
}
with client:
test = client.create_or_update_test("api-perf-test", test_definition)
print(f"Created test: {test['displayName']}")Upload, retrieve, and manage test files including JMeter scripts, CSV data files, and other supporting files. Files can be up to 50 MB in size.
def begin_upload_test_file(
test_id: str,
file_name: str,
body: IO,
*,
file_type: Optional[str] = None,
**kwargs
) -> JSON:
"""
Upload input file for a test.
Parameters:
- test_id (str): Unique test identifier
- file_name (str): Name of the file to upload
- body (IO): File content as binary stream
- file_type (str, optional): File type ("JMX_FILE", "USER_PROPERTIES", "ADDITIONAL_ARTIFACTS")
Returns:
JSON: File metadata including validation status
"""
def get_test_file(test_id: str, file_name: str, **kwargs) -> JSON:
"""
Get test file metadata.
Parameters:
- test_id (str): Unique test identifier
- file_name (str): Name of the file
Returns:
JSON: File metadata including validation status
"""
def delete_test_file(test_id: str, file_name: str, **kwargs) -> None:
"""
Delete a test file.
Parameters:
- test_id (str): Unique test identifier
- file_name (str): Name of the file to delete
"""
def list_test_files(test_id: str, **kwargs) -> Iterable[JSON]:
"""
List all files for a test.
Parameters:
- test_id (str): Unique test identifier
Returns:
Iterable[JSON]: List of file metadata
"""with client:
# Upload JMeter test script
with open("load-test.jmx", "rb") as jmx_file:
upload_result = client.begin_upload_test_file(
test_id="my-test",
file_name="load-test.jmx",
body=jmx_file,
file_type="JMX_FILE"
)
print(f"Upload status: {upload_result['validationStatus']}")
# Upload CSV data file
with open("test-data.csv", "rb") as csv_file:
upload_result = client.begin_upload_test_file(
test_id="my-test",
file_name="test-data.csv",
body=csv_file,
file_type="ADDITIONAL_ARTIFACTS"
)
# List all files for the test
files = list(client.list_test_files("my-test"))
for file_info in files:
print(f"File: {file_info['fileName']} - Status: {file_info['validationStatus']}")Configure Azure resources to monitor during load testing. This enables collection of server-side metrics like CPU usage, memory consumption, and custom application metrics during test execution.
def create_or_update_app_components(test_id: str, body: Union[JSON, IO], **kwargs) -> JSON:
"""
Create or update app components configuration for a test.
Parameters:
- test_id (str): Unique test identifier
- body (Union[JSON, IO]): App components configuration
Returns:
JSON: App components configuration
"""
def get_app_components(test_id: str, **kwargs) -> JSON:
"""
Get app components configuration for a test.
Parameters:
- test_id (str): Unique test identifier
Returns:
JSON: App components configuration
"""app_components = {
"components": {
"web-app": {
"resourceId": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/my-rg/providers/Microsoft.Web/sites/my-webapp",
"resourceName": "my-webapp",
"resourceType": "Microsoft.Web/sites",
"kind": "web"
},
"sql-db": {
"resourceId": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/my-rg/providers/Microsoft.Sql/servers/my-server/databases/my-db",
"resourceName": "my-db",
"resourceType": "Microsoft.Sql/servers/databases",
"kind": "database"
}
}
}
with client:
components = client.create_or_update_app_components("my-test", app_components)
print(f"Configured {len(components['components'])} app components")Configure server-side metrics collection for Azure resources during load testing. This enables monitoring of infrastructure performance alongside client-side load testing metrics.
def create_or_update_server_metrics_config(test_id: str, body: Union[JSON, IO], **kwargs) -> JSON:
"""
Create or update server metrics configuration for a test.
Parameters:
- test_id (str): Unique test identifier
- body (Union[JSON, IO]): Server metrics configuration
Returns:
JSON: Server metrics configuration
"""
def get_server_metrics_config(test_id: str, **kwargs) -> JSON:
"""
Get server metrics configuration for a test.
Parameters:
- test_id (str): Unique test identifier
Returns:
JSON: Server metrics configuration
"""server_metrics_config = {
"metrics": {
"web-app-cpu": {
"resourceId": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/my-rg/providers/Microsoft.Web/sites/my-webapp",
"metricNamespace": "Microsoft.Web/sites",
"name": "CpuPercentage",
"aggregation": "Average",
"unit": "Percent"
},
"sql-dtu": {
"resourceId": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/my-rg/providers/Microsoft.Sql/servers/my-server/databases/my-db",
"metricNamespace": "Microsoft.Sql/servers/databases",
"name": "dtu_consumption_percent",
"aggregation": "Average",
"unit": "Percent"
}
}
}
with client:
metrics_config = client.create_or_update_server_metrics_config("my-test", server_metrics_config)
print(f"Configured {len(metrics_config['metrics'])} server metrics")All administration operations have async equivalents available in azure.developer.loadtesting.aio.LoadTestAdministrationClient:
from azure.developer.loadtesting.aio import LoadTestAdministrationClient
from azure.core.credentials_async import DefaultAzureCredential
async def manage_tests():
credential = DefaultAzureCredential()
client = LoadTestAdministrationClient(
endpoint="https://your-resource.loadtest.azure.com",
credential=credential
)
async with client:
# Create test
test = await client.create_or_update_test("my-test", test_definition)
# Upload file
with open("test.jmx", "rb") as f:
result = await client.begin_upload_test_file("my-test", "test.jmx", f)
# List tests
async for test in client.list_tests():
print(f"Test: {test['displayName']}")Install with Tessl CLI
npx tessl i tessl/pypi-azure-developer-loadtesting