-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
27 lines (21 loc) · 974 Bytes
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
from openfeature import api
from openfeature.evaluation_context import EvaluationContext
from ldclient import Config
from ld_openfeature import LaunchDarklyProvider
from os import getenv
sdk_key = getenv("LAUNCHDARKLY_SDK_KEY", "")
flag_key = getenv("LAUNCHDARKLY_FLAG_KEY", "")
if sdk_key == "":
print("*** Set the 'LAUNCHDARKLY_SDK_KEY' environment variable before running this script")
exit(1)
elif flag_key == "":
print("*** Set the 'LAUNCHDARKLY_FLAG_KEY' environment variable before running this script")
exit(1)
provider = LaunchDarklyProvider(Config(sdk_key))
api.set_provider(provider)
client = api.get_client()
# Set up the evaluation context. This context should appear on your LaunchDarkly
# contexts dashboard soon after you run the demo.
context = EvaluationContext("example-user-key", {"name": "Sandy"})
flag_value = client.get_boolean_value(flag_key, False, context)
print(f"*** The {flag_key} feature flag evaluates to {flag_value}.")