Last active
December 3, 2024 20:52
-
-
Save RobSpectre/81ef5bca642ce98b6014ff87f0bbc11a to your computer and use it in GitHub Desktop.
This file contains 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
import ldclient | |
from ldclient.config import Config | |
from ldclient import Context | |
# Import your application | |
from yourapp import App | |
# Instantiate your application | |
app = App() | |
# Authenticate your LaunchDarkly client | |
ldclient.set_config(Config('sdk-copy-your-key-here')) | |
# Instantiate your LaunchDarkly client | |
client = ldclient.get() | |
# Define a route for your application | |
@app.route("/") | |
def root(): | |
# Build the context of your user | |
context = Context.builder('user-id-123abc').kind('user').name('Sandy').set('email', '[email protected]').build() | |
# Retrieve your feature flag | |
flag_value = client.variation("my-first-feature-flag", context, False) | |
# If the flag is true, user gets new template. If not, fallback to previous template. | |
if flag_value == True: | |
# Our feature flag is true, deploy the new template. | |
return "new_template.html" | |
else: | |
# Our feature flag is true, deploy the old template. | |
return "old_template.html" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment