@@ -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,66 @@ 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 (
223+ " Flag structure: 'test-flag-dependency' depends on 'beta-feature' being enabled"
224+ )
225+ print ("" )
226+ print ("๐ Required setup (if 'test-flag-dependency' doesn't exist):" )
227+ print (" 1. Create feature flag 'beta-feature':" )
228+ print (" - Condition: email contains '@example.com'" )
229+ print (" - Rollout: 100%" )
230+ print (" 2. Create feature flag 'test-flag-dependency':" )
231+ print (" - Condition: flag 'beta-feature' is enabled" )
232+ print (" - Rollout: 100%" )
233+ print ("" )
234+
235+ posthog .debug = True
236+
237+ # Test @example.com user (should satisfy dependency if flags exist)
238+ result1 = posthog .feature_enabled (
239+ "test-flag-dependency" ,
240+ "example_user" ,
241+ person_properties = {
"email" :
"[email protected] " },
242+ only_evaluate_locally = True ,
243+ )
244+ print (f"โ
@example.com user (test-flag-dependency): { result1 } " )
245+
246+ # Test non-example.com user (dependency should not be satisfied)
247+ result2 = posthog .feature_enabled (
248+ "test-flag-dependency" ,
249+ "regular_user" ,
250+ person_properties = {
"email" :
"[email protected] " },
251+ only_evaluate_locally = True ,
252+ )
253+ print (f"โ Regular user (test-flag-dependency): { result2 } " )
254+
255+ # Test beta-feature directly for comparison
256+ beta1 = posthog .feature_enabled (
257+ "beta-feature" ,
258+ "example_user" ,
259+ person_properties = {
"email" :
"[email protected] " },
260+ only_evaluate_locally = True ,
261+ )
262+ beta2 = posthog .feature_enabled (
263+ "beta-feature" ,
264+ "regular_user" ,
265+ person_properties = {
"email" :
"[email protected] " },
266+ only_evaluate_locally = True ,
267+ )
268+ print (f"๐ Beta feature comparison - @example.com: { beta1 } , regular: { beta2 } " )
269+
270+ print ("\n ๐ฏ Results Summary:" )
271+ print (
272+ f" - Flag dependencies evaluated locally: { 'โ
YES' if result1 != result2 else 'โ NO' } "
273+ )
274+ print (" - Zero API calls needed: โ
YES (all evaluated locally)" )
275+ print (" - Python SDK supports flag dependencies: โ
YES" )
276+
277+ elif choice == "5" :
217278 print ("\n " + "=" * 60 )
218279 print ("CONTEXT MANAGEMENT AND TAGGING EXAMPLES" )
219280 print ("=" * 60 )
@@ -274,7 +335,7 @@ def process_payment(payment_id):
274335 process_order ("12345" )
275336 process_payment ("67890" )
276337
277- elif choice == "5 " :
338+ elif choice == "6 " :
278339 print ("\n ๐ Running all examples..." )
279340
280341 # Run example 1
@@ -308,20 +369,37 @@ def process_payment(payment_id):
308369 print (f"Payload: { posthog .get_feature_flag_payload ('beta-feature' , 'distinct_id' )} " )
309370
310371 # Run example 4
372+ print (f"\n { '๐ธ' * 20 } FLAG DEPENDENCIES { '๐ธ' * 20 } " )
373+ print ("๐ Testing flag dependencies..." )
374+ result1 = posthog .feature_enabled (
375+ "test-flag-dependency" ,
376+ "demo_user" ,
377+ person_properties = {
"email" :
"[email protected] " },
378+ only_evaluate_locally = True ,
379+ )
380+ result2 = posthog .feature_enabled (
381+ "test-flag-dependency" ,
382+ "demo_user2" ,
383+ person_properties = {
"email" :
"[email protected] " },
384+ only_evaluate_locally = True ,
385+ )
386+ print (f"โ
@example.com user: { result1 } , regular user: { result2 } " )
387+
388+ # Run example 5
311389 print (f"\n { '๐ธ' * 20 } CONTEXT MANAGEMENT { '๐ธ' * 20 } " )
312390 print ("๐ท๏ธ Testing context management..." )
313391 with posthog .new_context ():
314392 posthog .tag ("demo_run" , "all_examples" )
315393 posthog .capture ("demo_completed" )
316394 print ("โ
Demo completed with context tags" )
317395
318- elif choice == "6 " :
396+ elif choice == "7 " :
319397 print ("๐ Goodbye!" )
320398 posthog .shutdown ()
321399 exit ()
322400
323401else :
324- print ("โ Invalid choice. Please run again and select 1-6 ." )
402+ print ("โ Invalid choice. Please run again and select 1-7 ." )
325403 posthog .shutdown ()
326404 exit ()
327405
0 commit comments