@@ -82,10 +82,11 @@ def load_env_file():
8282print ("1. Identify and capture examples" )
8383print ("2. Feature flag local evaluation examples" )
8484print ("3. Feature flag payload examples" )
85- print ("4. Context management and tagging examples" )
86- print ("5. Run all examples" )
87- print ("6. Exit" )
88- choice = input ("\n Enter your choice (1-6): " ).strip ()
85+ print ("4. Flag dependencies examples" )
86+ print ("5. Context management and tagging examples" )
87+ print ("6. Run all examples" )
88+ print ("7. Exit" )
89+ choice = input ("\n Enter your choice (1-7): " ).strip ()
8990
9091if choice == "1" :
9192 print ("\n " + "=" * 60 )
@@ -214,6 +215,62 @@ def load_env_file():
214215 print (f"Value (variant or enabled): { result .get_value ()} " )
215216
216217elif choice == "4" :
218+ print ("\n " + "=" * 60 )
219+ print ("FLAG DEPENDENCIES EXAMPLES" )
220+ print ("=" * 60 )
221+ print ("๐ Testing flag dependencies with local evaluation..." )
222+ print (" Flag structure: 'test-flag-dependency' depends on 'beta-feature' being enabled" )
223+ print ("" )
224+ print ("๐ Required setup (if 'test-flag-dependency' doesn't exist):" )
225+ print (" 1. Create feature flag 'beta-feature':" )
226+ print (" - Condition: email contains '@example.com'" )
227+ print (" - Rollout: 100%" )
228+ print (" 2. Create feature flag 'test-flag-dependency':" )
229+ print (" - Condition: flag 'beta-feature' is enabled" )
230+ print (" - Rollout: 100%" )
231+ print ("" )
232+
233+ posthog .debug = True
234+
235+ # Test @example.com user (should satisfy dependency if flags exist)
236+ result1 = posthog .feature_enabled (
237+ "test-flag-dependency" ,
238+ "example_user" ,
239+ person_properties = {
"email" :
"[email protected] " },
240+ only_evaluate_locally = True ,
241+ )
242+ print (f"โ
@example.com user (test-flag-dependency): { result1 } " )
243+
244+ # Test non-example.com user (dependency should not be satisfied)
245+ result2 = posthog .feature_enabled (
246+ "test-flag-dependency" ,
247+ "regular_user" ,
248+ person_properties = {
"email" :
"[email protected] " },
249+ only_evaluate_locally = True ,
250+ )
251+ print (f"โ Regular user (test-flag-dependency): { result2 } " )
252+
253+ # Test beta-feature directly for comparison
254+ beta1 = posthog .feature_enabled (
255+ "beta-feature" ,
256+ "example_user" ,
257+ person_properties = {
"email" :
"[email protected] " },
258+ only_evaluate_locally = True ,
259+ )
260+ beta2 = posthog .feature_enabled (
261+ "beta-feature" ,
262+ "regular_user" ,
263+ person_properties = {
"email" :
"[email protected] " },
264+ only_evaluate_locally = True ,
265+ )
266+ print (f"๐ Beta feature comparison - @example.com: { beta1 } , regular: { beta2 } " )
267+
268+ print ("\n ๐ฏ Results Summary:" )
269+ print (f" - Flag dependencies evaluated locally: { 'โ
YES' if result1 != result2 else 'โ NO' } " )
270+ print (" - Zero API calls needed: โ
YES (all evaluated locally)" )
271+ print (" - Python SDK supports flag dependencies: โ
YES" )
272+
273+ elif choice == "5" :
217274 print ("\n " + "=" * 60 )
218275 print ("CONTEXT MANAGEMENT AND TAGGING EXAMPLES" )
219276 print ("=" * 60 )
@@ -274,7 +331,7 @@ def process_payment(payment_id):
274331 process_order ("12345" )
275332 process_payment ("67890" )
276333
277- elif choice == "5 " :
334+ elif choice == "6 " :
278335 print ("\n ๐ Running all examples..." )
279336
280337 # Run example 1
@@ -308,20 +365,37 @@ def process_payment(payment_id):
308365 print (f"Payload: { posthog .get_feature_flag_payload ('beta-feature' , 'distinct_id' )} " )
309366
310367 # Run example 4
368+ print (f"\n { '๐ธ' * 20 } FLAG DEPENDENCIES { '๐ธ' * 20 } " )
369+ print ("๐ Testing flag dependencies..." )
370+ result1 = posthog .feature_enabled (
371+ "test-flag-dependency" ,
372+ "demo_user" ,
373+ person_properties = {
"email" :
"[email protected] " },
374+ only_evaluate_locally = True ,
375+ )
376+ result2 = posthog .feature_enabled (
377+ "test-flag-dependency" ,
378+ "demo_user2" ,
379+ person_properties = {
"email" :
"[email protected] " },
380+ only_evaluate_locally = True ,
381+ )
382+ print (f"โ
@example.com user: { result1 } , regular user: { result2 } " )
383+
384+ # Run example 5
311385 print (f"\n { '๐ธ' * 20 } CONTEXT MANAGEMENT { '๐ธ' * 20 } " )
312386 print ("๐ท๏ธ Testing context management..." )
313387 with posthog .new_context ():
314388 posthog .tag ("demo_run" , "all_examples" )
315389 posthog .capture ("demo_completed" )
316390 print ("โ
Demo completed with context tags" )
317391
318- elif choice == "6 " :
392+ elif choice == "7 " :
319393 print ("๐ Goodbye!" )
320394 posthog .shutdown ()
321395 exit ()
322396
323397else :
324- print ("โ Invalid choice. Please run again and select 1-6 ." )
398+ print ("โ Invalid choice. Please run again and select 1-7 ." )
325399 posthog .shutdown ()
326400 exit ()
327401
0 commit comments