0
# A/B Testing
1
2
Controlled experimentation platform for testing search configurations, UI changes, and business strategies with statistical significance. Run experiments to optimize search performance and user experience.
3
4
## Capabilities
5
6
### A/B Testing Client
7
8
```python { .api }
9
class AbtestingClient:
10
def __init__(
11
self,
12
app_id: Optional[str] = None,
13
api_key: Optional[str] = None,
14
transporter: Optional[Transporter] = None,
15
config: Optional[AbtestingConfig] = None
16
) -> None: ...
17
18
async def close(self) -> None: ...
19
async def set_client_api_key(self, api_key: str) -> None: ...
20
```
21
22
### Test Management
23
24
Create and manage A/B tests for search optimization.
25
26
```python { .api }
27
async def list_ab_tests(
28
self,
29
offset: Optional[int] = None,
30
limit: Optional[int] = None,
31
index_prefix: Optional[str] = None,
32
index_suffix: Optional[str] = None,
33
request_options: Optional[Union[dict, RequestOptions]] = None
34
) -> ListABTestsResponse:
35
"""
36
List all A/B tests in the application.
37
38
Parameters:
39
- offset: Offset for pagination
40
- limit: Maximum number of tests to return
41
- index_prefix: Filter by index name prefix
42
- index_suffix: Filter by index name suffix
43
- request_options: Additional request options
44
45
Returns:
46
ListABTestsResponse with test list
47
"""
48
49
async def get_ab_test(
50
self,
51
id: int,
52
request_options: Optional[Union[dict, RequestOptions]] = None
53
) -> ABTest:
54
"""
55
Get details of a specific A/B test.
56
57
Parameters:
58
- id: Test identifier
59
- request_options: Additional request options
60
61
Returns:
62
ABTest object with test details
63
"""
64
65
async def add_ab_test(
66
self,
67
ab_test_create: Union[ABTestCreate, dict],
68
request_options: Optional[Union[dict, RequestOptions]] = None
69
) -> ABTestResponse:
70
"""
71
Create a new A/B test.
72
73
Parameters:
74
- ab_test_create: Test configuration
75
- request_options: Additional request options
76
77
Returns:
78
ABTestResponse with test creation details
79
"""
80
81
async def stop_ab_test(
82
self,
83
id: int,
84
request_options: Optional[Union[dict, RequestOptions]] = None
85
) -> ABTestResponse:
86
"""
87
Stop a running A/B test.
88
89
Parameters:
90
- id: Test identifier
91
- request_options: Additional request options
92
93
Returns:
94
ABTestResponse with stop confirmation
95
"""
96
97
async def delete_ab_test(
98
self,
99
id: int,
100
request_options: Optional[Union[dict, RequestOptions]] = None
101
) -> ABTestResponse:
102
"""
103
Delete an A/B test.
104
105
Parameters:
106
- id: Test identifier
107
- request_options: Additional request options
108
109
Returns:
110
ABTestResponse with deletion confirmation
111
"""
112
```
113
114
## Usage Example
115
116
```python
117
from algoliasearch.abtesting.client import AbtestingClient
118
119
# Initialize client
120
client = AbtestingClient("YOUR_APP_ID", "YOUR_API_KEY")
121
122
# Create an A/B test
123
test_response = await client.add_ab_test({
124
"name": "Search Ranking Test",
125
"variants": [
126
{
127
"index": "products_variant_a",
128
"trafficPercentage": 50,
129
"description": "Default ranking"
130
},
131
{
132
"index": "products_variant_b",
133
"trafficPercentage": 50,
134
"description": "Custom ranking with boost"
135
}
136
],
137
"endAt": "2024-12-31T23:59:59Z"
138
})
139
140
print(f"Test created with ID: {test_response.ab_test_id}")
141
```
142
143
## Types
144
145
```python { .api }
146
class ABTestCreate(BaseModel):
147
name: str
148
variants: List[ABTestVariant]
149
end_at: str
150
151
class ABTestVariant(BaseModel):
152
index: str
153
traffic_percentage: int
154
description: Optional[str] = None
155
156
class ABTest(BaseModel):
157
ab_test_id: int
158
name: str
159
variants: List[ABTestVariant]
160
status: str
161
created_at: str
162
end_at: Optional[str] = None
163
164
class ListABTestsResponse(BaseModel):
165
ab_tests: List[ABTest]
166
count: int
167
total: int
168
```