-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Use new sdk instructions instead of hello READMEs #152
Merged
k3llymariee
merged 5 commits into
main
from
kelly/sc-239433/use-new-sdk-instructions-instead-of-example
Apr 9, 2024
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
6d44a39
add python sdk instructions file
k3llymariee e8fe377
Merge branch 'main' into kelly/sc-239433/use-new-sdk-instructions-ins…
k3llymariee b91aec0
change python string replace fns
k3llymariee 32ea4dc
read instruction file when present on sdk
k3llymariee b8d9a36
fix indentation
k3llymariee File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# Set up your application | ||
|
||
If you want to skip ahead, the final code is available in our [GitHub repository](https://github.com/launchdarkly/hello-python). | ||
|
||
|
||
Comment on lines
+1
to
+5
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think maybe when the instructions are all in we might want to pull this intro text out of the markdown file/viewport box |
||
1. Create a new directory: | ||
|
||
```bash | ||
mkdir hello-python && cd hello-python | ||
``` | ||
|
||
2. Next, create a file called `requirements.txt` with the SDK dependency and install it: | ||
|
||
```bash | ||
echo "launchdarkly-server-sdk==9.3.1" >> requirements.txt && pip install -r requirements.txt | ||
``` | ||
|
||
3. Create a file called `test.py` and add the following code: | ||
|
||
```python | ||
# Import the LaunchDarkly client. | ||
import ldclient | ||
from ldclient import Context | ||
from ldclient.config import Config | ||
|
||
# Create a helper function for rendering messages. | ||
def show_message(s): | ||
print("*** {}".format(s)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
print() | ||
|
||
# Initialize the ldclient with your environment-specific SDK key. | ||
if __name__ == "__main__": | ||
ldclient.set_config(Config("1234567890abcdef")) | ||
|
||
# The SDK starts up the first time ldclient.get() is called. | ||
if ldclient.get().is_initialized(): | ||
show_message("SDK successfully initialized!") | ||
else: | ||
show_message("SDK failed to initialize") | ||
exit() | ||
|
||
# Set up the evaluation context. This context should appear on your LaunchDarkly contexts | ||
# dashboard soon after you run the demo. | ||
context = Context.builder('example-user-key').name('Sandy').build() | ||
|
||
# Call LaunchDarkly with the feature flag key you want to evaluate. | ||
flag_value = ldclient.get().variation("my-flag-key", context, False) | ||
|
||
show_message("Feature flag 'my-flag-key' is {} for this user".format(flag_value)) | ||
|
||
# Here we ensure that the SDK shuts down cleanly and has a chance to deliver analytics | ||
# events to LaunchDarkly before the program exits. If analytics events are not delivered, | ||
# the user properties and flag usage statistics will not appear on your dashboard. In a | ||
# normal long-running application, the SDK would continue running and events would be | ||
# delivered automatically in the background. | ||
ldclient.get().close() | ||
``` |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
despite the name of the function we're still sending
fetchedSDKInstructions
message type - figured we can update either the message name or the function name when we stop fetching from the READMEs but this way we can still just handle this one message in theshowSDKInstructionsModel.Update
method.