Skip to main content

An OpenFeature provider for the LaunchDarkly Python server SDK

Project description

LaunchDarkly OpenFeature provider for the Server-Side SDK for Python

Quality control checks readthedocs

PyPI PyPI

This provider allows for using LaunchDarkly with the OpenFeature SDK for Python.

This provider is designed primarily for use in multi-user systems such as web servers and applications. It follows the server-side LaunchDarkly model for multi-user contexts. It is not intended for use in desktop and embedded systems applications.

[!WARNING] This is a beta version. The API is not stabilized and may introduce breaking changes.

[!NOTE] This OpenFeature provider uses production versions of the LaunchDarkly SDK, which adhere to our standard versioning policy.

LaunchDarkly overview

LaunchDarkly is a feature management platform that serves trillions of feature flags daily to help teams build better software, faster. Get started using LaunchDarkly today!

Twitter Follow

Supported Python versions

This version of the LaunchDarkly provider works with Python 3.8 and above.

Getting started

Requisites

Install the library via pip

$ pip install launchdarkly-openfeature-server

Usage

from ldclient import Config
from ld_openfeature import LaunchDarklyProvider
from openfeature import api

openfeature_provider = LaunchDarklyProvider(Config("sdk-key"))

api.set_provider(openfeature_provider)

# Refer to OpenFeature documentation for getting a client and performing evaluations.

Refer to the SDK reference guide for instructions on getting started with using the SDK.

For information on using the OpenFeature client please refer to the OpenFeature Documentation.

OpenFeature Specific Considerations

LaunchDarkly evaluates contexts, and it can either evaluate a single-context, or a multi-context. When using OpenFeature both single and multi-contexts must be encoded into a single EvaluationContext. This is accomplished by looking for an attribute named kind in the EvaluationContext.

There are 4 different scenarios related to the kind:

  1. There is no kind attribute. In this case the provider will treat the context as a single context containing a "user" kind.
  2. There is a kind attribute, and the value of that attribute is "multi". This will indicate to the provider that the context is a multi-context.
  3. There is a kind attribute, and the value of that attribute is a string other than "multi". This will indicate to the provider a single context of the kind specified.
  4. There is a kind attribute, and the attribute is not a string. In this case the value of the attribute will be discarded, and the context will be treated as a "user". An error message will be logged.

The kind attribute should be a string containing only contain ASCII letters, numbers, ., _ or -.

The OpenFeature specification allows for an optional targeting key, but LaunchDarkly requires a key for evaluation. A targeting key must be specified for each context being evaluated. It may be specified using either targetingKey, as it is in the OpenFeature specification, or key, which is the typical LaunchDarkly identifier for the targeting key. If a targetingKey and a key are specified, then the targetingKey will take precedence.

There are several other attributes which have special functionality within a single or multi-context.

Examples

A single user context

context = EvaluationContext("the-key")

A single context of kind "organization"

context = EvaluationContext("org-key", {"kind": "organization"});

A multi-context containing a "user" and an "organization"

attributes = {
    "kind": "multi",
    "organization": {
        "name": "the-org-name",
        "targetingKey", "my-org-key",
        "myCustomAttribute", "myAttributeValue"
    },
    "user": {
        "key": "my-user-key",
        "anonymous", true
    }
}
context = EvaluationContext(null, attributes)

Setting private attributes in a single context

attributes = {
    "kind": "organization",
    "myCustomAttribute": "myAttributeValue",
    "privateAttributes": ["myCustomAttribute"]
}

context = EvaluationContext("org-key", attributes)

Setting private attributes in a multi-context

attributes = {
    "kind": "organization",
    "organization": {
        "name": "the-org-name",
        "targetingKey": "my-org-key",
        # This will ONLY apply to the "organization" attributes.
        "privateAttributes": ["myCustomAttribute"],
        # This attribute will be private.
        "myCustomAttribute": "myAttributeValue",
    },
    "user": [
        "key": "my-user-key",
        "anonymous" = > true,
        # This attribute will not be private.
        "myCustomAttribute": "myAttributeValue",
    ]
}

context = EvaluationContext(null, attributes)

Learn more

Check out our documentation for in-depth instructions on configuring and using LaunchDarkly. You can also head straight to the complete reference guide for this SDK.

The authoritative description of all properties and methods is in the python documentation.

Contributing

We encourage pull requests and other contributions from the community. Check out our contributing guidelines for instructions on how to contribute to this SDK.

About LaunchDarkly

  • LaunchDarkly is a continuous delivery platform that provides feature flags as a service and allows developers to iterate quickly and safely. We allow you to easily flag your features and manage them from the LaunchDarkly dashboard. With LaunchDarkly, you can:
    • Roll out a new feature to a subset of your users (like a group of users who opt-in to a beta tester group), gathering feedback and bug reports from real-world use cases.
    • Gradually roll out a feature to an increasing percentage of users, and track the effect that the feature has on key metrics (for instance, how likely is a user to complete a purchase if they have feature A versus feature B?).
    • Turn off a feature that you realize is causing performance problems in production, without needing to re-deploy, or even restart the application with a changed configuration file.
    • Grant access to certain features based on user attributes, like payment plan (eg: users on the ‘gold’ plan get access to more features than users in the ‘silver’ plan). Disable parts of your application to facilitate maintenance, without taking everything offline.
  • LaunchDarkly provides feature flag SDKs for a wide variety of languages and technologies. Check out our documentation for a complete list.
  • Explore LaunchDarkly

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

launchdarkly_openfeature_server-0.3.0.tar.gz (14.5 kB view details)

Uploaded Source

Built Distribution

File details

Details for the file launchdarkly_openfeature_server-0.3.0.tar.gz.

File metadata

File hashes

Hashes for launchdarkly_openfeature_server-0.3.0.tar.gz
Algorithm Hash digest
SHA256 f25fa072605dd9858cd316c9a8544146d5ae82741c4e04e9e36d971aa16bb135
MD5 b7d75278054d69cdad22b9b5fe613a58
BLAKE2b-256 8e9bd13d0eecd333f23ada8cefcb6eb19d00ed58fb4eca236bc1959facd0aebd

See more details on using hashes here.

File details

Details for the file launchdarkly_openfeature_server-0.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for launchdarkly_openfeature_server-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d212f954113759e55e5d5ef1ac96edd350a1658b71aebd81b0e8abf36d6240a6
MD5 1eacb4f7f2cfdbe936f34f1ec755ccf2
BLAKE2b-256 4f9ef217c1f624ef37d91e167beab0abb7efaa579a0c39a228c980f3fe44074f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page