4
4
from typing import Any , Dict , Optional , Union
5
5
from eppo_client .assignment_logger import AssignmentLogger
6
6
from eppo_client .bandit import (
7
- ActionContextsDict ,
7
+ ActionAttributes ,
8
8
BanditEvaluator ,
9
9
BanditResult ,
10
- Attributes ,
10
+ ContextAttributes ,
11
11
ActionContexts ,
12
12
)
13
13
from eppo_client .configuration_requestor import (
17
17
from eppo_client .models import VariationType
18
18
from eppo_client .poller import Poller
19
19
from eppo_client .sharders import MD5Sharder
20
- from eppo_client .types import AttributesDict , ValueType
20
+ from eppo_client .types import Attributes , ValueType
21
21
from eppo_client .validation import validate_not_blank
22
22
from eppo_client .eval import FlagEvaluation , Evaluator , none_result
23
23
from eppo_client .version import __version__
@@ -49,7 +49,7 @@ def get_string_assignment(
49
49
self ,
50
50
flag_key : str ,
51
51
subject_key : str ,
52
- subject_attributes : AttributesDict ,
52
+ subject_attributes : Attributes ,
53
53
default : str ,
54
54
) -> str :
55
55
return self .get_assignment_variation (
@@ -64,7 +64,7 @@ def get_integer_assignment(
64
64
self ,
65
65
flag_key : str ,
66
66
subject_key : str ,
67
- subject_attributes : AttributesDict ,
67
+ subject_attributes : Attributes ,
68
68
default : int ,
69
69
) -> int :
70
70
return self .get_assignment_variation (
@@ -79,7 +79,7 @@ def get_numeric_assignment(
79
79
self ,
80
80
flag_key : str ,
81
81
subject_key : str ,
82
- subject_attributes : AttributesDict ,
82
+ subject_attributes : Attributes ,
83
83
default : float ,
84
84
) -> float :
85
85
# convert to float in case we get an int
@@ -97,7 +97,7 @@ def get_boolean_assignment(
97
97
self ,
98
98
flag_key : str ,
99
99
subject_key : str ,
100
- subject_attributes : AttributesDict ,
100
+ subject_attributes : Attributes ,
101
101
default : bool ,
102
102
) -> bool :
103
103
return self .get_assignment_variation (
@@ -112,7 +112,7 @@ def get_json_assignment(
112
112
self ,
113
113
flag_key : str ,
114
114
subject_key : str ,
115
- subject_attributes : AttributesDict ,
115
+ subject_attributes : Attributes ,
116
116
default : Dict [Any , Any ],
117
117
) -> Dict [Any , Any ]:
118
118
json_value = self .get_assignment_variation (
@@ -131,7 +131,7 @@ def get_assignment_variation(
131
131
self ,
132
132
flag_key : str ,
133
133
subject_key : str ,
134
- subject_attributes : AttributesDict ,
134
+ subject_attributes : Attributes ,
135
135
default : Optional [ValueType ],
136
136
expected_variation_type : VariationType ,
137
137
):
@@ -155,7 +155,7 @@ def get_assignment_detail(
155
155
self ,
156
156
flag_key : str ,
157
157
subject_key : str ,
158
- subject_attributes : AttributesDict ,
158
+ subject_attributes : Attributes ,
159
159
expected_variation_type : VariationType ,
160
160
) -> FlagEvaluation :
161
161
"""Maps a subject to a variation for a given flag
@@ -231,8 +231,8 @@ def get_bandit_action(
231
231
self ,
232
232
flag_key : str ,
233
233
subject_key : str ,
234
- subject_context : Union [Attributes , AttributesDict ],
235
- actions : Union [ActionContexts , ActionContextsDict ],
234
+ subject_context : Union [ContextAttributes , Attributes ],
235
+ actions : Union [ActionContexts , ActionAttributes ],
236
236
default : str ,
237
237
) -> BanditResult :
238
238
"""
@@ -250,11 +250,11 @@ def get_bandit_action(
250
250
Args:
251
251
flag_key (str): The feature flag key that contains the bandit as one of the variations.
252
252
subject_key (str): The key identifying the subject.
253
- subject_context (Attributes | AttributesDict ): The subject context.
254
- If supplying an AttributesDict , it gets converted to an Attributes instance
255
- actions (ActionContexts | ActionContextsDict ): The dictionary that maps action keys
253
+ subject_context (ActionContexts | ActionAttributes ): The subject context.
254
+ If supplying an ActionAttributes , it gets converted to an ActionContexts instance
255
+ actions (ActionContexts | ActionAttributes ): The dictionary that maps action keys
256
256
to their context of actions with their contexts.
257
- If supplying an AttributesDict , it gets converted to an Attributes instance.
257
+ If supplying an ActionAttributes , it gets converted to an ActionContexts instance.
258
258
default (str): The default variation to use if the subject is not part of the bandit.
259
259
260
260
Returns:
@@ -267,13 +267,16 @@ def get_bandit_action(
267
267
result = client.get_bandit_action(
268
268
"flag_key",
269
269
"subject_key",
270
- Attributes (
270
+ ContextAttributes (
271
271
numeric_attributes={"age": 25},
272
272
categorical_attributes={"country": "USA"}),
273
273
{
274
- "action1": Attributes(numeric_attributes={"price": 10.0}, categorical_attributes={"category": "A"}),
274
+ "action1": ContextAttributes(
275
+ numeric_attributes={"price": 10.0},
276
+ categorical_attributes={"category": "A"}
277
+ ),
275
278
"action2": {"price": 10.0, "category": "B"}
276
- "action3": Attributes .empty(),
279
+ "action3": ContextAttributes .empty(),
277
280
},
278
281
"default"
279
282
)
@@ -300,8 +303,8 @@ def get_bandit_action_detail(
300
303
self ,
301
304
flag_key : str ,
302
305
subject_key : str ,
303
- subject_context : Union [Attributes , AttributesDict ],
304
- actions : Union [ActionContexts , ActionContextsDict ],
306
+ subject_context : Union [ContextAttributes , Attributes ],
307
+ actions : Union [ActionContexts , ActionAttributes ],
305
308
default : str ,
306
309
) -> BanditResult :
307
310
subject_attributes = convert_subject_context_to_attributes (subject_context )
@@ -428,17 +431,17 @@ def check_value_type_match(
428
431
429
432
430
433
def convert_subject_context_to_attributes (
431
- subject_context : Union [Attributes , AttributesDict ]
432
- ) -> Attributes :
434
+ subject_context : Union [ContextAttributes , Attributes ]
435
+ ) -> ContextAttributes :
433
436
if isinstance (subject_context , dict ):
434
- return Attributes .from_dict (subject_context )
437
+ return ContextAttributes .from_dict (subject_context )
435
438
return subject_context
436
439
437
440
438
441
def convert_actions_to_action_contexts (
439
- actions : Union [ActionContexts , ActionContextsDict ]
442
+ actions : Union [ActionContexts , ActionAttributes ]
440
443
) -> ActionContexts :
441
444
return {
442
- k : Attributes .from_dict (v ) if isinstance (v , dict ) else v
445
+ k : ContextAttributes .from_dict (v ) if isinstance (v , dict ) else v
443
446
for k , v in actions .items ()
444
447
}
0 commit comments