Skip to main content

Loadero-Python client

Loadero-Python is a python package that provides easy-to-use programmatic access to Loadero API. It allows to manage tests, participants, asserts, runs and other Loadero resources, start and stop tests and extract test run results.

To access the Loadero API via Python client, Java client or directly an access token is required. Information about how to acquire an access token can be found here.

The package is open source and can be found in Loadero-Python Github repository.

Installation

Loadero-Python is available via PyPI, and can be installed with pip.

pip install loadero-python

Example Usage

This example is intended to demonstrate only the core capabilities of the package. A more complete description of the packages usage and capabilities can be found in its repositories README.

Initialization

First the client needs to be initialized with a valid access token and the project ID that the token was created for.

from loadero_python.api_client import APIClient

APIClient(project_id=1234, access_token="your_access_token")

Creating a test

Creating a test is as simple as initializing a new Test instance and calling its method create. Before doing that the test's configuration needs to be set, similar to how this is done via the Loadero WebApp.

from loadero_python.resources.test import Test, TestParams, Script
from loadero_python.resources.classificator import TestMode, IncrementStrategy

test = Test(
params=TestParams(
name="my first loadero python test",
start_interval=1,
participant_timeout=10 * 60, # ten minutes
mode=TestMode.TM_LOAD,
increment_strategy=IncrementStrategy.IS_LINEAR,
script=Script(content='print("hello test script")'),
)
).create()

Creating a group

from loadero_python.resources.group import Group, GroupParams

group = Group(
params=GroupParams(name="small group", count=8, test_id=test.params.test_id)
).create()

The group will be created as a sub-resource of the previously created test, this is indicated by setting the groups parent test to be test.params.test_id.

Creating a participant

from loadero_python.resources.participant import Participant, ParticipantParams
from loadero_python.resources.classificator import (
ComputeUnit,
AudioFeed,
Browser,
Location,
Network,
VideoFeed,
)

Participant(
params=ParticipantParams(
group_id=group.param.group_id,
test_id=test.params.test_id,
count=3,
record_audio=False,
name="9 out of 10 dentists",
compute_unit=ComputeUnit.CU_G4,
audio_feed=AudioFeed.AF_SILENCE,
browser=Browser.B_CHROMELATEST,
network=Network.N_4G,
location=Location.L_EU_CENTRAL_1,
video_feed=VideoFeed.VF_480P_15FPS,
)
).create()

Similarly, the participant resource is created as a sub-resource of the previously created group.

Launching a Test

Now that the test configuration is complete it can be launched with

run = test.launch()

Polling

To wait for a launched test run to finish call poll method.

run.poll()

Result retrieval

After the test execution finishes results of each test participant can be retrieved by calling results method.

results, _, _ = run.results()

Results contain a lot of useful information and metrics about the test, processing them is usually use case specific. To view all the results data simply print the result object.

for r in results:
print(r)

Output will look something like this

{
"id": 992341,
"created": "2022-04-01 13:54:25.689000+00:00",
"updated": "2024-02-03 15:42:54.689000+00:00",
"start": "2018-03-02 11:34:28.689000+00:00",
"end": "2020-08-01 18:12:24.689000+00:00",
"status": "timeout",
"selenium_result": "aborted",
"mos_status": "calculating",
"participant_details": {
"id": 233992,
"created": "2022-04-01 13:54:25.689000+00:00",
"updated": "2024-02-03 15:42:54.689000+00:00",
"participant_num": 123,
"participant_name": "9 out of 10 dentists",
"group_num": 23,
"group_name": "small group",
"compute_unit": "g4",
"audio_feed": "silence",
"browser": "chromeLatest",
"location": "eu-central-1",
"network": "4g",
"video_feed": "480p-15fps",
"run_id": 937561,
"record_audio": true
}
}
// ...