Created
June 20, 2023 22:12
-
-
Save eefret/36cb122eb84402b873b43bc979cc7434 to your computer and use it in GitHub Desktop.
LaunchDarkly Testing script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from ldclient.config import Config | |
from ldclient import LDClient | |
import time | |
# Set the SDK key you get from your LaunchDarkly environment | |
sdk_key = "API_KEY" | |
# Create a configuration object | |
config = Config(sdk_key=sdk_key) | |
# Initialize the LaunchDarkly client with the configuration object | |
ld_client = LDClient(config=config) | |
# Specify a user to test the feature flag with | |
user = { | |
"key": "17915b6d0e1970f6c607c9323a84bda8", # Unique key for the user | |
} | |
# The key of the feature flag you want to test | |
feature_flag_key = "cloud-subscriptions" | |
# Check the state of the feature flag for the specified user | |
flag_value = ld_client.variation(feature_flag_key, user, False) | |
# Output the result | |
print(f"Feature flag '{feature_flag_key}' is {'enabled' if flag_value else 'disabled'} for user {user['key']}.") | |
# It’s important to shut down the client when your application terminates; this ensures that the client releases any resources it is using | |
ld_client.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment