1313def main ():
1414 """
1515 Sample usage of the DevCycle OpenFeature Provider along with the Python Server SDK using Local Bucketing.
16-
16+
1717 This example demonstrates how to use all variable types supported by DevCycle through OpenFeature:
1818 - Boolean variables
1919 - String variables
2020 - Number variables (integer and float)
2121 - JSON object variables
22-
22+
2323 See DEVCYCLE_SETUP.md for instructions on creating the required variables in DevCycle.
2424 """
2525 logging .basicConfig (level = "INFO" , format = "%(levelname)s: %(message)s" )
@@ -28,9 +28,11 @@ def main():
2828 server_sdk_key = os .environ .get ("DEVCYCLE_SERVER_SDK_KEY" )
2929 if not server_sdk_key :
3030 logger .error ("DEVCYCLE_SERVER_SDK_KEY environment variable is not set" )
31- logger .error ("Please set it with: export DEVCYCLE_SERVER_SDK_KEY='your-sdk-key'" )
31+ logger .error (
32+ "Please set it with: export DEVCYCLE_SERVER_SDK_KEY='your-sdk-key'"
33+ )
3234 exit (1 )
33-
35+
3436 devcycle_client = DevCycleLocalClient (server_sdk_key , DevCycleLocalOptions ())
3537
3638 # Wait for DevCycle to initialize and load the configuration
@@ -69,7 +71,7 @@ def main():
6971 logger .info ("=" * 60 )
7072 logger .info ("Testing Boolean Variable" )
7173 logger .info ("=" * 60 )
72-
74+
7375 # Test Boolean Variable
7476 boolean_details = open_feature_client .get_boolean_details (
7577 "test-boolean-variable" , False , context
@@ -81,162 +83,156 @@ def main():
8183 logger .info ("✓ Boolean variable is ENABLED" )
8284 else :
8385 logger .info ("✗ Boolean variable is DISABLED" )
84-
86+
8587 logger .info ("\n " + "=" * 60 )
8688 logger .info ("Testing String Variable" )
8789 logger .info ("=" * 60 )
88-
90+
8991 # Test String Variable
9092 string_details = open_feature_client .get_string_details (
9193 "test-string-variable" , "default string" , context
9294 )
9395 logger .info (f"Variable Key: test-string-variable" )
9496 logger .info (f"Value: { string_details .value } " )
9597 logger .info (f"Reason: { string_details .reason } " )
96-
98+
9799 logger .info ("\n " + "=" * 60 )
98100 logger .info ("Testing Number Variable (Integer)" )
99101 logger .info ("=" * 60 )
100-
102+
101103 # Test Number Variable (Integer)
102104 integer_details = open_feature_client .get_integer_details (
103105 "test-number-variable" , 0 , context
104106 )
105107 logger .info (f"Variable Key: test-number-variable" )
106108 logger .info (f"Value: { integer_details .value } " )
107109 logger .info (f"Reason: { integer_details .reason } " )
108-
110+
109111 logger .info ("\n " + "=" * 60 )
110112 logger .info ("Testing Number Variable (Float)" )
111113 logger .info ("=" * 60 )
112-
114+
113115 # Test Number Variable as Float
114116 # Note: If the DevCycle variable is an integer, it will be cast to float
115117 float_value = open_feature_client .get_float_value (
116118 "test-number-variable" , 0.0 , context
117119 )
118120 logger .info (f"Variable Key: test-number-variable (as float)" )
119121 logger .info (f"Value: { float_value } " )
120-
122+
121123 logger .info ("\n " + "=" * 60 )
122124 logger .info ("Testing JSON Object Variable" )
123125 logger .info ("=" * 60 )
124-
126+
125127 # Test JSON Object Variable
126128 json_details = open_feature_client .get_object_details (
127129 "test-json-variable" , {"default" : "value" }, context
128130 )
129131 logger .info (f"Variable Key: test-json-variable" )
130132 logger .info (f"Value: { json_details .value } " )
131133 logger .info (f"Reason: { json_details .reason } " )
132-
134+
133135 logger .info ("\n " + "=" * 60 )
134136 logger .info ("Testing Object Variable - Empty Dictionary" )
135137 logger .info ("=" * 60 )
136-
138+
137139 # Test with empty dictionary default (valid per OpenFeature spec)
138140 empty_dict_result = open_feature_client .get_object_value (
139141 "test-json-variable" , {}, context
140142 )
141143 logger .info (f"Variable Key: test-json-variable (with empty default)" )
142144 logger .info (f"Value: { empty_dict_result } " )
143-
145+
144146 logger .info ("\n " + "=" * 60 )
145147 logger .info ("Testing Object Variable - Mixed Types" )
146148 logger .info ("=" * 60 )
147-
149+
148150 # Test with flat dictionary containing mixed primitive types
149151 # OpenFeature allows string, int, float, bool, and None in flat dictionaries
150152 mixed_default = {
151153 "string_key" : "hello" ,
152154 "int_key" : 42 ,
153155 "float_key" : 3.14 ,
154156 "bool_key" : True ,
155- "none_key" : None
157+ "none_key" : None ,
156158 }
157159 mixed_result = open_feature_client .get_object_value (
158160 "test-json-variable" , mixed_default , context
159161 )
160162 logger .info (f"Variable Key: test-json-variable (with mixed types)" )
161163 logger .info (f"Value: { mixed_result } " )
162- logger .info (f"Value types: { [(k , type (v ).__name__ ) for k , v in mixed_result .items ()]} " )
163-
164+ logger .info (
165+ f"Value types: { [(k , type (v ).__name__ ) for k , v in mixed_result .items ()]} "
166+ )
167+
164168 logger .info ("\n " + "=" * 60 )
165169 logger .info ("Testing Object Variable - All String Values" )
166170 logger .info ("=" * 60 )
167-
171+
168172 # Test with all string values
169173 string_dict_default = {
170174 "name" : "John Doe" ,
171175172- "status" : "active"
176+ "status" : "active" ,
173177 }
174178 string_dict_result = open_feature_client .get_object_value (
175179 "test-json-variable" , string_dict_default , context
176180 )
177181 logger .info (f"Variable Key: test-json-variable (all strings)" )
178182 logger .info (f"Value: { string_dict_result } " )
179-
183+
180184 logger .info ("\n " + "=" * 60 )
181185 logger .info ("Testing Object Variable - Numeric Values" )
182186 logger .info ("=" * 60 )
183-
187+
184188 # Test with numeric values (integers and floats)
185- numeric_dict_default = {
186- "count" : 100 ,
187- "percentage" : 85.5 ,
188- "threshold" : 0
189- }
189+ numeric_dict_default = {"count" : 100 , "percentage" : 85.5 , "threshold" : 0 }
190190 numeric_dict_result = open_feature_client .get_object_value (
191191 "test-json-variable" , numeric_dict_default , context
192192 )
193193 logger .info (f"Variable Key: test-json-variable (numeric)" )
194194 logger .info (f"Value: { numeric_dict_result } " )
195-
195+
196196 logger .info ("\n " + "=" * 60 )
197197 logger .info ("Testing Object Variable - Boolean Flags" )
198198 logger .info ("=" * 60 )
199-
199+
200200 # Test with boolean values
201- bool_dict_default = {
202- "feature_a" : True ,
203- "feature_b" : False ,
204- "feature_c" : True
205- }
201+ bool_dict_default = {"feature_a" : True , "feature_b" : False , "feature_c" : True }
206202 bool_dict_result = open_feature_client .get_object_value (
207203 "test-json-variable" , bool_dict_default , context
208204 )
209205 logger .info (f"Variable Key: test-json-variable (booleans)" )
210206 logger .info (f"Value: { bool_dict_result } " )
211-
207+
212208 logger .info ("\n " + "=" * 60 )
213209 logger .info ("Testing Object Variable - With None Values" )
214210 logger .info ("=" * 60 )
215-
211+
216212 # Test with None values (valid per OpenFeature spec for flat dictionaries)
217213 none_dict_default = {
218214 "optional_field" : None ,
219215 "required_field" : "value" ,
220- "nullable_count" : None
216+ "nullable_count" : None ,
221217 }
222218 none_dict_result = open_feature_client .get_object_value (
223219 "test-json-variable" , none_dict_default , context
224220 )
225221 logger .info (f"Variable Key: test-json-variable (with None)" )
226222 logger .info (f"Value: { none_dict_result } " )
227-
223+
228224 logger .info ("\n " + "=" * 60 )
229225 logger .info ("Testing Non-Existent Variable (Should Return Default)" )
230226 logger .info ("=" * 60 )
231-
227+
232228 # Test non-existent variable to demonstrate default handling
233229 nonexistent_details = open_feature_client .get_string_details (
234230 "doesnt-exist" , "default fallback value" , context
235231 )
236232 logger .info (f"Variable Key: doesnt-exist" )
237233 logger .info (f"Value: { nonexistent_details .value } " )
238234 logger .info (f"Reason: { nonexistent_details .reason } " )
239-
235+
240236 logger .info ("\n " + "=" * 60 )
241237 logger .info ("All tests completed!" )
242238 logger .info ("=" * 60 )
0 commit comments