Metadata-Version: 2.4
Name: azure-developer-loadtesting
Version: 1.2.0b1
Summary: Microsoft Corporation Azure Developer Loadtesting Client Library for Python
Author-email: Microsoft Corporation <azpysdkhelp@microsoft.com>
License-Expression: MIT
Project-URL: repository, https://github.com/Azure/azure-sdk-for-python
Keywords: azure,azure sdk
Classifier: Development Status :: 4 - Beta
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: isodate>=0.6.1
Requires-Dist: azure-core>=1.36.0
Requires-Dist: typing-extensions>=4.6.0
Dynamic: license-file

# Azure Load Testing client library for Python

Azure Load Testing provides client library in python to the user by which they can interact natively with Azure Load Testing service. Azure Load Testing is a fully managed load-testing service that enables you to generate high-scale load. The service simulates traffic for your applications, regardless of where they're hosted. Developers, testers, and quality assurance (QA) engineers can use it to optimize application performance, scalability, or capacity.

## Documentation

Various documentation is available to help you get started

- [API reference documentation][api_reference_doc]
- [Product Documentation][product_documentation]

## Getting started

### Prequisites

- Python 3.8 or later is required to use this package.
- You need an [Azure subscription][azure_sub] to use this package.
- An existing Azure LoadTesting resource.

### Installing the package

```bash
python -m pip install azure-developer-loadtesting
```

### Create with an Azure Active Directory Credential

To use an [Azure Active Directory (AAD) token credential][authenticate_with_token],
provide an instance of the desired credential type obtained from the
[azure-identity][azure_identity_credentials] library.

To authenticate with AAD, you must first [pip][pip] install [`azure-identity`][azure_identity_pip]

After setup, you can choose which type of [credential][azure_identity_credentials] from azure.identity to use.

As an example, sign in via the Azure CLI `az login` command and [DefaultAzureCredential](https://learn.microsoft.com/python/api/azure-identity/azure.identity.defaultazurecredential?view=azure-python) will authenticate as that user.

Use the returned token credential to authenticate the client.

### Create the client

Azure Developer LoadTesting SDK has 2 sub-clients of the main client (`LoadTestingClient`) to interact with the service, 'LoadTestAdministrationClient' for administrative operations and 'LoadTestRunClient' to run tests/test-profiles.

```python
from azure.developer.loadtesting import LoadTestAdministrationClient

# for managing authentication and authorization
# can be installed from pypi, follow: https://pypi.org/project/azure-identity/
# using DefaultAzureCredentials, read more at: https://learn.microsoft.com/en-us/python/api/azure-identity/azure.identity.defaultazurecredential?view=azure-python
from azure.identity import DefaultAzureCredential

client = LoadTestAdministrationClient(endpoint='<endpoint>', credential=DefaultAzureCredential())
```

`<endpoint>` refers to the data-plane endpoint/URL of the resource.

The data-plane endpoint is obtained from Control Plane APIs. To obtain the data-plane endpoint for your resource, follow [this documentation][obtaining_data_plane_uri].

## Key concepts

The Azure Load Test client library for python allows you to interact with each of these components through the use of clients. There are two top-level clients which are the main entry points for the library

- `LoadTestAdministrationClient` (`azure.developer.loadtesting.LoadTestAdministrationClient`)
- `LoadTestRunClient` (`azure.developer.loadtesting.LoadTestRunClient`)

These two clients also have there asynchronous counterparts, which are 
- `LoadTestAdministrationClient` (`azure.developer.loadtesting.aio.LoadTestAdministrationClient`)
- `LoadTestRunClient` (`azure.developer.loadtesting.aio.LoadTestRunClient`)

### Load Test Administration Client

The `LoadTestAdministrationClient` is used to administer and configure the load tests, test profiles, app components and metrics.

#### Test

A test specifies the test script, and configuration settings for running a load test. You can create one or more tests in an Azure Load Testing resource.

#### App Component

When you run a load test for an Azure-hosted application, you can monitor resource metrics for the different Azure application components (server-side metrics). While the load test runs, and after completion of the test, you can monitor and analyze the resource metrics in the Azure Load Testing dashboard.

#### Metrics

During a load test, Azure Load Testing collects metrics about the test execution. There are two types of metrics:

1. Client-side metrics give you details reported by the test engine. These metrics include the number of virtual users, the request response time, the number of failed requests, or the number of requests per second.

2. Server-side metrics are available for Azure-hosted applications and provide information about your Azure application components. Metrics can be for the number of database reads, the type of HTTP responses, or container resource consumption.

### Test Run Client

The `LoadTestRunClient`  is used to start and stop test runs corresponding to a load test. It can also be used to start and stop test profile runs corresponding to a test profile. A test run represents one execution of a load test. It collects the logs associated with running the Apache JMeter or Locust script, the load test YAML configuration, the list of app components to monitor, and the results of the test.

### Data-Plane Endpoint

Data-plane of Azure Load Testing resources is addressable using the following URL format:

`00000000-0000-0000-0000-000000000000.aaa.cnt-prod.loadtesting.azure.com`

The first GUID `00000000-0000-0000-0000-000000000000` is the unique identifier used for accessing the Azure Load Testing resource. This is followed by  `aaa` which is the Azure region of the resource.

The data-plane endpoint is obtained from Control Plane APIs. To obtain the data-plane endpoint for your resource, follow [this documentation][obtaining_data_plane_uri].

**Example:** `1234abcd-12ab-12ab-12ab-123456abcdef.eastus.cnt-prod.loadtesting.azure.com`

In the above example, `eastus` represents the Azure region `East US`.

## Examples

### Creating a load test 

```python
from azure.developer.loadtesting import LoadTestAdministrationClient
from azure.identity import DefaultAzureCredential
from azure.core.exceptions import HttpResponseError
import os

TEST_ID = "some-test-id"  
DISPLAY_NAME = "my-load-test"  

# set SUBSCRIPTION_ID as an environment variable
SUBSCRIPTION_ID = os.environ["SUBSCRIPTION_ID"]  

client = LoadTestAdministrationClient(endpoint='<endpoint>', credential=DefaultAzureCredential())

try:
    result = client.create_or_update_test(
        TEST_ID,
        {
            "description": "",
            "displayName": "My New Load Test",
            "loadTestConfiguration": {
                "engineInstances": 1,
                "splitAllCSVs": False,
            },
            "passFailCriteria": {
                "passFailMetrics": {
                    "condition1": {
                        "clientmetric": "response_time_ms",
                        "aggregate": "avg",
                        "condition": ">",
                        "value": 300
                    },
                    "condition2": {
                        "clientmetric": "error",
                        "aggregate": "percentage",
                        "condition": ">",
                        "value": 50
                    },
                    "condition3": {
                        "clientmetric": "latency",
                        "aggregate": "avg",
                        "condition": ">",
                        "value": 200,
                        "requestName": "GetCustomerDetails"
                    }
                }
            },
            "secrets": {
                "secret1": {
                    "value": "https://sdk-testing-keyvault.vault.azure.net/secrets/sdk-secret",
                    "type": "AKV_SECRET_URI"
                }
            },
            "environmentVariables": {
                "my-variable": "value"
            }
        }
    )
    print(result)
except HttpResponseError as e:
     print('Service responded with error: {}'.format(e.response.json()))

```

### Uploading test script file to a Test

```python
from azure.developer.loadtesting import LoadTestAdministrationClient
from azure.identity import DefaultAzureCredential
from azure.core.exceptions import HttpResponseError

# This sample uploads a JMX Test Script File
TEST_ID = "some-test-id"  
FILE_NAME = "some-file-name.jmx"  

client = LoadTestAdministrationClient(endpoint='<endpoint>', credential=DefaultAzureCredential())

try:

    # uploading .jmx file to a test
    resultPoller = client.begin_upload_test_file(TEST_ID, FILE_NAME, open("sample.jmx", "rb"))

    # getting result of LRO poller with timeout of 600 secs
    validationResponse = resultPoller.result(600)
    print(validationResponse)
    
except HttpResponseError as e:
    print("Failed with error: {}".format(e.response.json()))
```

### Running a Test

```python
from azure.developer.loadtesting import LoadTestRunClient
from azure.identity import DefaultAzureCredential
from azure.core.exceptions import HttpResponseError

TEST_ID = "some-test-id"  
TEST_RUN_ID = "some-testrun-id" 
DISPLAY_NAME = "my-load-test-run"  

client = LoadTestRunClient(endpoint='<endpoint>', credential=DefaultAzureCredential())

try:
    testRunPoller = client.begin_test_run(
    TEST_RUN_ID,
        {
            "testId": TEST_ID,
            "displayName": "My New Load Test Run",
        }
    )

    #waiting for test run status to be completed with timeout = 3600 seconds
    result = testRunPoller.result(3600)
    
    print(result)
except HttpResponseError as e:
    print("Failed with error: {}".format(e.response.json()))
```

## Troubleshooting

### Logging

This SDK uses Python standard [logging][python_logging] library for logging.
Basic information about HTTP sessions (URLs, headers, etc.) is logged at INFO
level.

Detailed DEBUG level logging, including request/response bodies and unredacted
headers, can be enabled on a client with the `logging_enable` keyword argument.
Do note that DEBUG level logging can contain sensitive information:

```python
import sys
import logging
from azure.identity import DefaultAzureCredential

# Create a logger for the 'azure' SDK
logger = logging.getLogger('azure')
logger.setLogLevel(logging.DEBUG)

# Configure console output
handler = logging.StreamHandler(stream=sys.stdout)
logger.addHandler(handler)

# Enable logging for a client
client = LoadTestAdministrationClient(endpoint='<endpoint>', credential=DefaultAzureCredential(), logging_enable=True)
```

Similarly, `logging_enable` can enable detailed logging for a single call, even when it isn't enabled for the whole client

```python
client.create_or_update_test(..., logging_enable=True)
```

## Next steps

More samples can be found [here](https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/loadtesting/azure-developer-loadtesting/samples).

## Contributing

This project welcomes contributions and suggestions. Most contributions require
you to agree to a Contributor License Agreement (CLA) declaring that you have
the right to, and actually do, grant us the rights to use your contribution.
For details, visit https://cla.microsoft.com.

When you submit a pull request, a CLA-bot will automatically determine whether
you need to provide a CLA and decorate the PR appropriately (e.g., label,
comment). Simply follow the instructions provided by the bot. You will only
need to do this once across all repos using our CLA.

This project has adopted the
[Microsoft Open Source Code of Conduct][code_of_conduct]. For more information,
see the Code of Conduct FAQ or contact opencode@microsoft.com with any
additional questions or comments.

<!-- LINKS -->
[code_of_conduct]: https://opensource.microsoft.com/codeofconduct/
[authenticate_with_token]: https://docs.microsoft.com/azure/cognitive-services/authentication?tabs=powershell#authenticate-with-an-authentication-token
[azure_identity_credentials]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/identity/azure-identity#credentials
[azure_identity_pip]: https://pypi.org/project/azure-identity/
[default_azure_credential]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/identity/azure-identity#defaultazurecredential
[pip]: https://pypi.org/project/pip/
[azure_sub]: https://azure.microsoft.com/free/
[api_reference_doc]: https://learn.microsoft.com/rest/api/apptesting/loadtest/
[product_documentation]: https://azure.microsoft.com/services/load-testing/
[obtaining_data_plane_uri]: https://learn.microsoft.com/rest/api/apptesting/loadtest/data-plane-uri
[python_logging]: https://docs.python.org/3/library/logging.html

# Release History

## 1.2.0b1 (2026-03-06)

Updated the client library to use API Version 2025-11-01-preview. This adds all the capabilities that were introduced until this API version.

### Features Added

- This release adds models and enums for all the APIs supported by Azure Load Testing   
- Support for Notification Rules
    - Added methods `create_or_update_notification_rule`, `get_notification_rule`, `delete_notification_rule` and `list_notification_rules` in `LoadTestAdministrationClient` to work with Notification rules.
- Support for Trigger
    - Added methods `create_or_update_trigger`, `get_trigger`, `delete_trigger` and `list_triggers` in `LoadTestAdministrationClient` to work with Scheduling test triggers.
- Support for Actionable Insights
    - Added methods `begin_generate_test_run_insights`, `update_latest_test_run_insights` and `get_latest_test_run_insights` in `LoadTestRunClient` to work with actionable insights.
- Support for generating test plan recommendations
    - Added method `begin_generate_test_plan_recommendations` in `LoadTestAdministrationClient` which generates test plan recommendations.
- Support for Cloning load test
    - Added method `begin_clone_test` in `LoadTestAdministrationClient` to Clone a load test.

## 1.1.0b1 (2025-03-27)

Updated the client library to use API Version 2025-05-01-preview. This adds all the capabilities that were introduced until this API version.

This version and all future versions will require Python 3.8+. Python 3.7 is no longer supported.

### Features Added

- This release adds models and enums for all the APIs supported by Azure Load Testing   
- Support for AutoStop Criteria
    - Use `auto_stop_criteria` property on the `Test` model to add autostop criteria
- Support for Quick Load Tests with RPS (Requests Per Second) Inputs
    - Use `requests_per_second` and `max_response_time_in_ms` in `OptionalLoadTestConfig` model to specify desired RPS for a quick load test
- Support for URL Tests with JSON based test plans
    - Added enum `TestKind` with value `URL` and support for `URL_TEST_CONFIG` file type in the `FileType` enum
- Support for Locust Load Tests
    - Added value `Locust` in the `TestKind` enum
- Support for Multi Region Load Tests
    - Added property `regional_load_test_config` in `LoadTestConfiguration` model to specify regional load distribution
- Support for Disabling Public IP Deployment for Private Load Tests
    - Added property `public_ip_disabled` to the `Test` model to disable injecting public IP
- Support for uploading ZIP Artifacts
    - Added value `ZIPPED_ARTIFACTS` in the `FileType` enum
- Support for all Test Profiles & Test Profile Run Scenarios
    - Added methods `create_or_update_test_profile`, `get_test_profile`, `delete_test_profile` and `list_test_profiles` in `LoadTestAdministrationClient` to work with Test Profiles
    - Added methods `begin_test_profile_run`, `get_test_profile_run`, `delete_test_profile_run` and `list_test_profile_runs` in `LoadTestRunClient` to work with Test Profile Runs

## 1.0.1 (2025-01-20)

### Bugs Fixed

- Update API response enum typo for VALIDATION_FAILURE

### Other Changes

- Add NOT_VALIDATED to the list of terminal states for the file validation poller

## 1.0.0 (2023-03-07)

### Breaking Changes
- moved all operations under `azure.developer.loadtesting.LoadTestingClient.test_run` to `azure.developer.loadtesting.LoadTestRunClient` 
- moved all operations under `azure.developer.loadtesting.LoadTestingClient.administration` to `azure.developer.loadtesting.LoadTestAdministrationClient` 
- moved all operations under `azure.developer.loadtesting.aio.LoadTestingClient.test_run` to `azure.developer.loadtesting.aio.LoadTestRunClient` 
- moved all operations under `azure.developer.loadtesting.aio.LoadTestingClient.administration` to `azure.developer.loadtesting.aio.LoadTestAdministrationClient` 
- removed `azure.developer.loadtesting.LoadTestingClient.administration.upload_test_file` as it moved all functionality to `azure.developer.loadtesting.LoadTestAdministrationClient.begin_upload_test_file`
- removed `azure.developer.loadtesting.aio.LoadTestingClient.administration.upload_test_file` as it moved all functionality to `azure.developer.loadtesting.aio.LoadTestAdministrationClient.begin_upload_test_file`
- removed `azure.developer.loadtesting.LoadTestingClient.test_run.create_or_update_test_run` as it moved all functionality to `azure.developer.loadtesting.LoadTestRunClient.begin_test_run`
- removed `azure.developer.loadtesting.aio.LoadTestingClient.test_run.create_or_update_test_run` as it moved all functionality to `azure.developer.loadtesting.aio.LoadTestRunClient.begin_test_run`
- removed `azure.developer.loadtesting.aio.LoadTestingClient.test_run.list_metric_definitions` as it moved all functionality to `azure.developer.loadtesting.aio.LoadTestRunClient.get_metric_definitions`
- removed `azure.developer.loadtesting.LoadTestingClient.test_run.list_metric_definitions` as it moved all functionality to `azure.developer.loadtesting.LoadTestRunClient.get_metric_definitions`
- removed `azure.developer.loadtesting.aio.LoadTestingClient.test_run.list_metric_definitions` as it moved all functionality to `azure.developer.loadtesting.aio.LoadTestRunClient.get_metric_definitions`
- removed `azure.developer.loadtesting.LoadTestingClient.test_run.list_metric_namespaces` as it moved all functionality to `azure.developer.loadtesting.LoadTestRunClient.get_metric_namespaces`

### Other Changes
- bumped version to stable `1.0.0`
- updated README.md

## 1.0.0b3 (2023-01-01)

### Features Added 
- Method added `azure.developer.loadtesting.LoadTestingClient.test_run.list_metric_namespaces`
- Method added `azure.developer.loadtesting.LoadTestingClient.test_run.list_metric_definitions`
- Method added `azure.developer.loadtesting.LoadTestingClient.test_run.list_metrics`
- Method added `azure.developer.loadtesting.LoadTestingClient.test_run.create_or_update_app_components`
- Method added `azure.developer.loadtesting.LoadTestingClient.test_run.get_app_components`
- Method added `azure.developer.loadtesting.LoadTestingClient.test_run.create_or_update_server_metrics_config`
- Method added `azure.developer.loadtesting.LoadTestingClient.test_run.get_server_metrics_config`
- Method added `azure.developer.loadtesting.LoadTestingClient.administration.begin_upload_test_file`
- Method added `azure.developer.loadtesting.LoadTestingClient.test_run.begin_test_run`
- Method added `azure.developer.loadtesting.LoadTestingClient.test_run.begin_test_run_status`
- Method added `azure.developer.loadtesting.aio.LoadTestingClient.test_run.list_metric_namespaces`
- Method added `azure.developer.loadtesting.aio.LoadTestingClient.test_run.list_metric_definitions`
- Method added `azure.developer.loadtesting.aio.LoadTestingClient.test_run.list_metrics`
- Method added `azure.developer.loadtesting.aio.LoadTestingClient.test_run.create_or_update_app_components`
- Method added `azure.developer.loadtesting.aio.LoadTestingClient.test_run.get_app_components`
- Method added `azure.developer.loadtesting.aio.LoadTestingClient.test_run.create_or_update_server_metrics_config`
- Method added `azure.developer.loadtesting.aio.LoadTestingClient.test_run.get_server_metrics_config`
- Method added `azure.developer.loadtesting.aio.LoadTestingClient.administration.begin_upload_test_file`
- Method added `azure.developer.loadtesting.aio.LoadTestingClient.test_run.begin_test_run_status`
- Method added `azure.developer.loadtesting.aio.LoadTestingClient.test_run.get_metric_dimension_values`
- Method added `azure.developer.loadtesting.aio.LoadTestingClient.test_run.begin_test_run`


### Breaking Changes
- Changed subclients `load_test_runs` and `load_test_adminsitration` to `test_run` and `adminsitrative` respectively
- Removed `continuation_token` as a parameter for method `azure.developer.loadtesting.aio.LoadTestingClient.test_run.list_test_runs`
- Removed `continuation_token` as a parameter for method `azure.developer.loadtesting.LoadTestingClient.test_run.list_test_runs`,
- Removed `continuation_token` as a parameter for method `azure.developer.loadtesting.aio.LoadTestingClient.administration.list_test_files`
- Removed `continuation_token` as a parameter for method `azure.developer.loadtesting.LoadTestingClient.administration.list_test_files`
- Removed `continuation_token` as a parameter for method `azure.developer.loadtesting.aio.LoadTestingClient.administration.list_tests`
- Removed `continuation_token` as a parameter for method `azure.developer.loadtesting.LoadTestingClient.administration.list_tests`

### Other Changes
- Updated README

## 1.0.0b2 (2022-10-17)

### Bug Fixed 
- `delete_app_components` method from `azure.developer.loadtesting.LoadTestingClient.load_test_administration.delete_app_components` was not discoverable in expected location, fixed discoverability.

### Other Changes
- Updated README

## 1.0.0b1 (2022-07-28)

### Features Added
- Initial version
