Skip to content

Instantly share code, notes, and snippets.

@eefret
Created June 20, 2023 22:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eefret/36cb122eb84402b873b43bc979cc7434 to your computer and use it in GitHub Desktop.
Save eefret/36cb122eb84402b873b43bc979cc7434 to your computer and use it in GitHub Desktop.
LaunchDarkly Testing script
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