forked from Eppo-exp/python-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path01_script.py
More file actions
45 lines (32 loc) · 1.24 KB
/
Copy path01_script.py
File metadata and controls
45 lines (32 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import os
import sys
import time
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
import eppo_client # noqa
from eppo_client.config import Config # noqa
from eppo_client.assignment_logger import AssignmentLogger # noqa
API_KEY = "REPLACE WITH YOUR API KEY"
class ExampleAssignmentLogger(AssignmentLogger):
def log_assignment(self, assignment):
print(
f'{assignment["subject"]} assigned {assignment["variation"]} for key {assignment["experiment"]}'
)
def init_eppo_and_assign():
client_config = Config(api_key=API_KEY, assignment_logger=ExampleAssignmentLogger())
eppo_client.init(client_config)
eppo = eppo_client.get_instance()
# ensure the client is initialized before assigning
time.sleep(1)
subject = "user_1234"
flag_key = "my-flag-key"
assigned_variation = eppo.get_string_assignment(
flag_key, subject, subject_attributes={}, default="control"
)
if assigned_variation == "control":
print("Assigned to control")
elif assigned_variation == "treatment":
print("Assigned to treatment")
else:
print(f"Assigned unknown variation: {assigned_variation}")
if __name__ == "__main__":
init_eppo_and_assign()