44from typing import Any , Dict , Optional , Union
55from eppo_client .assignment_logger import AssignmentLogger
66from eppo_client .bandit import (
7- ActionContextsDict ,
7+ ActionAttributes ,
88 BanditEvaluator ,
99 BanditResult ,
10- Attributes ,
10+ ContextAttributes ,
1111 ActionContexts ,
1212)
1313from eppo_client .configuration_requestor import (
1717from eppo_client .models import VariationType
1818from eppo_client .poller import Poller
1919from eppo_client .sharders import MD5Sharder
20- from eppo_client .types import AttributesDict , ValueType
20+ from eppo_client .types import Attributes , ValueType
2121from eppo_client .validation import validate_not_blank
2222from eppo_client .eval import FlagEvaluation , Evaluator , none_result
2323from eppo_client .version import __version__
@@ -49,7 +49,7 @@ def get_string_assignment(
4949 self ,
5050 flag_key : str ,
5151 subject_key : str ,
52- subject_attributes : AttributesDict ,
52+ subject_attributes : Attributes ,
5353 default : str ,
5454 ) -> str :
5555 return self .get_assignment_variation (
@@ -64,7 +64,7 @@ def get_integer_assignment(
6464 self ,
6565 flag_key : str ,
6666 subject_key : str ,
67- subject_attributes : AttributesDict ,
67+ subject_attributes : Attributes ,
6868 default : int ,
6969 ) -> int :
7070 return self .get_assignment_variation (
@@ -79,7 +79,7 @@ def get_numeric_assignment(
7979 self ,
8080 flag_key : str ,
8181 subject_key : str ,
82- subject_attributes : AttributesDict ,
82+ subject_attributes : Attributes ,
8383 default : float ,
8484 ) -> float :
8585 # convert to float in case we get an int
@@ -97,7 +97,7 @@ def get_boolean_assignment(
9797 self ,
9898 flag_key : str ,
9999 subject_key : str ,
100- subject_attributes : AttributesDict ,
100+ subject_attributes : Attributes ,
101101 default : bool ,
102102 ) -> bool :
103103 return self .get_assignment_variation (
@@ -112,7 +112,7 @@ def get_json_assignment(
112112 self ,
113113 flag_key : str ,
114114 subject_key : str ,
115- subject_attributes : AttributesDict ,
115+ subject_attributes : Attributes ,
116116 default : Dict [Any , Any ],
117117 ) -> Dict [Any , Any ]:
118118 json_value = self .get_assignment_variation (
@@ -131,7 +131,7 @@ def get_assignment_variation(
131131 self ,
132132 flag_key : str ,
133133 subject_key : str ,
134- subject_attributes : AttributesDict ,
134+ subject_attributes : Attributes ,
135135 default : Optional [ValueType ],
136136 expected_variation_type : VariationType ,
137137 ):
@@ -155,7 +155,7 @@ def get_assignment_detail(
155155 self ,
156156 flag_key : str ,
157157 subject_key : str ,
158- subject_attributes : AttributesDict ,
158+ subject_attributes : Attributes ,
159159 expected_variation_type : VariationType ,
160160 ) -> FlagEvaluation :
161161 """Maps a subject to a variation for a given flag
@@ -231,8 +231,8 @@ def get_bandit_action(
231231 self ,
232232 flag_key : str ,
233233 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 ],
236236 default : str ,
237237 ) -> BanditResult :
238238 """
@@ -250,11 +250,11 @@ def get_bandit_action(
250250 Args:
251251 flag_key (str): The feature flag key that contains the bandit as one of the variations.
252252 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
256256 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.
258258 default (str): The default variation to use if the subject is not part of the bandit.
259259
260260 Returns:
@@ -267,13 +267,16 @@ def get_bandit_action(
267267 result = client.get_bandit_action(
268268 "flag_key",
269269 "subject_key",
270- Attributes (
270+ ContextAttributes (
271271 numeric_attributes={"age": 25},
272272 categorical_attributes={"country": "USA"}),
273273 {
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+ ),
275278 "action2": {"price": 10.0, "category": "B"}
276- "action3": Attributes .empty(),
279+ "action3": ContextAttributes .empty(),
277280 },
278281 "default"
279282 )
@@ -300,8 +303,8 @@ def get_bandit_action_detail(
300303 self ,
301304 flag_key : str ,
302305 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 ],
305308 default : str ,
306309 ) -> BanditResult :
307310 subject_attributes = convert_subject_context_to_attributes (subject_context )
@@ -428,17 +431,17 @@ def check_value_type_match(
428431
429432
430433def convert_subject_context_to_attributes (
431- subject_context : Union [Attributes , AttributesDict ]
432- ) -> Attributes :
434+ subject_context : Union [ContextAttributes , Attributes ]
435+ ) -> ContextAttributes :
433436 if isinstance (subject_context , dict ):
434- return Attributes .from_dict (subject_context )
437+ return ContextAttributes .from_dict (subject_context )
435438 return subject_context
436439
437440
438441def convert_actions_to_action_contexts (
439- actions : Union [ActionContexts , ActionContextsDict ]
442+ actions : Union [ActionContexts , ActionAttributes ]
440443) -> ActionContexts :
441444 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
443446 for k , v in actions .items ()
444447 }
0 commit comments