Closed radj closed 5 years ago
Hi, thanks for asking about this. Unfortunately, it's not something we can add to the existing Python SDK.
The reason is that this SDK is specifically for server-side use, and the LaunchDarkly service works very differently for server-side versus client-side SDKs. Each of the SDKs is written specifically to use one or the other of these modes. Here's some background on that, and then I have a possible interim solution.
In server-side mode, the SDK downloads the entirety of your feature flag definitions (targets, rules, etc.), and then evaluates flag variations within the SDK based on the user properties (so you can evaluate flags for many users concurrently). Since feature flag definitions can contain sensitive information such as lists of user emails, you would not want a desktop app or script to be able to download all of that.
In client-side mode, the SDK sends the user properties to LaunchDarkly and receives back only the flag variations, not the flag definitions. The mobile key (and, for browsers, the environment ID) can only be used for that type of request. There is an assumption that the SDK only has one current user at a time, hence the API for evaluating flags is somewhat different.
The entire design of the Python SDK is geared toward server-side use in a long-running application. It sounds like what you would like to have is something much simpler. If your script only needs to get the flags once per execution, here is one workaround you could use:
Make an HTTP request with the following properties:
REPORT
https://app.launchdarkly.com/msdk/evalx/user
Authorization: YOUR_MOBILE_KEY
user
parameter in the SDK)The response will be a JSON object that looks like this:
{
"feature-flag-1-key": {
"value": "the flag variation value for this user"
// some other properties you can ignore
}
"feature-flag-2-key": { ... etc... }
}
What this will not do is generate any analytics events (i.e. the data that causes users and flag statistics to show up on your dashboard). If that information is important to you, there is a second HTTP request you would need to make. That's a bit lengthy so let me know if you'd like to know about it.
Your use case isn't one we've seen before but it does make sense, so I will put it down as a feature request that we might develop as a separate mini-SDK.
Thanks for the detailed response and placing it in your backlog.
I'll close the issue for now, but if we do develop the issue we'll add a comment here so you'll be notified.
Is your feature request related to a problem? Please describe. I would like to have support of mobile key in the Python SDK.
Describe the solution you'd like The Python SDK can reach access the LD server using the mobile key for client side Python scripts.
Describe alternatives you've considered Creating another project to dump "unsecure" flags in and use the SDK key of this project. If ever the key is compromised, they only see the "unsecure" flags.
Additional context I tried using mobile key with Python SDK but initialization fails.