# LaunchDarkly OpenFeature provider for the Server-Side SDK for Python
[](https://github.com/launchdarkly/openfeature-python-server/actions/workflows/ci.yml)
[](https://launchdarkly-openfeature-python-sdk.readthedocs.io/en/latest/)
[](https://pypi.python.org/pypi/launchdarkly-openfeature-server)
[](https://pypi.python.org/pypi/launchdarkly-openfeature-server)
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](https://docs.launchdarkly.com/sdk/concepts/versioning).
# LaunchDarkly overview
[LaunchDarkly](https://www.launchdarkly.com) is a feature management platform that serves trillions of feature flags daily to help teams build better software, faster. [Get started](https://docs.launchdarkly.com/home/getting-started) using LaunchDarkly today!
[](https://twitter.com/intent/follow?screen_name=launchdarkly)
## Supported Python versions
This version of the LaunchDarkly provider works with Python 3.8 and above.
## Getting started
### Requisites
Install the library via pip
```shell
$ pip install launchdarkly-openfeature-server
```
### Usage
```python
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](https://docs.launchdarkly.com/sdk/server-side/python) for instructions on getting started with using the SDK.
For information on using the OpenFeature client please refer to the [OpenFeature Documentation](https://docs.openfeature.dev/docs/reference/concepts/evaluation-api/).
## 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.
- A key of `privateAttributes`. Must be an array of string values. [Equivalent to the 'private' builder method in the SDK.](https://launchdarkly-python-sdk.readthedocs.io/en/latest/api-main.html#ldclient.ContextBuilder.private)
- A key of `anonymous`. Must be a boolean value. [Equivalent to the 'anonymous' builder method in the SDK.](https://launchdarkly-python-sdk.readthedocs.io/en/latest/api-main.html#ldclient.ContextBuilder.anonymous)
- A key of `name`. Must be a string. [Equivalent to the 'name' builder method in the SDK.](https://launchdarkly-python-sdk.readthedocs.io/en/latest/api-main.html#ldclient.ContextBuilder.name)
### Examples
#### A single user context
```python
context = EvaluationContext("the-key")
```
#### A single context of kind "organization"
```python
context = EvaluationContext("org-key", {"kind": "organization"});
```
#### A multi-context containing a "user" and an "organization"
```python
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
```python
attributes = {
"kind": "organization",
"myCustomAttribute": "myAttributeValue",
"privateAttributes": ["myCustomAttribute"]
}
context = EvaluationContext("org-key", attributes)
```
#### Setting private attributes in a multi-context
```python
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](http://docs.launchdarkly.com) for in-depth instructions on configuring and using LaunchDarkly. You can also head straight to the [complete reference guide for this SDK](https://docs.launchdarkly.com/sdk/server-side/python).
The authoritative description of all properties and methods is in the [python documentation](https://launchdarkly.github.io/python-server-sdk/).
## Contributing
We encourage pull requests and other contributions from the community. Check out our [contributing guidelines](CONTRIBUTING.md) 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](https://docs.launchdarkly.com/sdk) for a complete list.
* Explore LaunchDarkly
* [launchdarkly.com](https://www.launchdarkly.com/ "LaunchDarkly Main Website") for more information
* [docs.launchdarkly.com](https://docs.launchdarkly.com/ "LaunchDarkly Documentation") for our documentation and SDK reference guides
* [apidocs.launchdarkly.com](https://apidocs.launchdarkly.com/ "LaunchDarkly API Documentation") for our API documentation
* [blog.launchdarkly.com](https://blog.launchdarkly.com/ "LaunchDarkly Blog Documentation") for the latest product updates
Raw data
{
"_id": null,
"home_page": "https://github.com/launchdarkly/openfeature-python-server",
"name": "launchdarkly-openfeature-server",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0,>=3.8",
"maintainer_email": null,
"keywords": null,
"author": "LaunchDarkly",
"author_email": "dev@launchdarkly.com",
"download_url": "https://files.pythonhosted.org/packages/8e/9b/d13d0eecd333f23ada8cefcb6eb19d00ed58fb4eca236bc1959facd0aebd/launchdarkly_openfeature_server-0.3.0.tar.gz",
"platform": null,
"description": "# LaunchDarkly OpenFeature provider for the Server-Side SDK for Python\n\n[](https://github.com/launchdarkly/openfeature-python-server/actions/workflows/ci.yml)\n[](https://launchdarkly-openfeature-python-sdk.readthedocs.io/en/latest/)\n\n[](https://pypi.python.org/pypi/launchdarkly-openfeature-server)\n[](https://pypi.python.org/pypi/launchdarkly-openfeature-server)\n\nThis provider allows for using LaunchDarkly with the OpenFeature SDK for Python.\n\nThis 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.\n\n> [!WARNING]\n> This is a beta version. The API is not stabilized and may introduce breaking changes.\n\n> [!NOTE]\n> This OpenFeature provider uses production versions of the LaunchDarkly SDK, which adhere to our standard [versioning policy](https://docs.launchdarkly.com/sdk/concepts/versioning).\n\n# LaunchDarkly overview\n\n[LaunchDarkly](https://www.launchdarkly.com) is a feature management platform that serves trillions of feature flags daily to help teams build better software, faster. [Get started](https://docs.launchdarkly.com/home/getting-started) using LaunchDarkly today!\n\n[](https://twitter.com/intent/follow?screen_name=launchdarkly)\n\n## Supported Python versions\n\nThis version of the LaunchDarkly provider works with Python 3.8 and above.\n\n## Getting started\n\n### Requisites\n\nInstall the library via pip\n\n```shell\n$ pip install launchdarkly-openfeature-server\n```\n\n### Usage\n\n```python\nfrom ldclient import Config\nfrom ld_openfeature import LaunchDarklyProvider\nfrom openfeature import api\n\nopenfeature_provider = LaunchDarklyProvider(Config(\"sdk-key\"))\n\napi.set_provider(openfeature_provider)\n\n# Refer to OpenFeature documentation for getting a client and performing evaluations.\n```\n\nRefer to the [SDK reference guide](https://docs.launchdarkly.com/sdk/server-side/python) for instructions on getting started with using the SDK.\n\nFor information on using the OpenFeature client please refer to the [OpenFeature Documentation](https://docs.openfeature.dev/docs/reference/concepts/evaluation-api/).\n\n## OpenFeature Specific Considerations\n\nLaunchDarkly 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`.\n\nThere are 4 different scenarios related to the `kind`:\n1. There is no `kind` attribute. In this case the provider will treat the context as a single context containing a \"user\" kind.\n2. 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.\n3. 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.\n4. 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.\n\nThe `kind` attribute should be a string containing only contain ASCII letters, numbers, `.`, `_` or `-`.\n\nThe 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.\n\nThere are several other attributes which have special functionality within a single or multi-context.\n- A key of `privateAttributes`. Must be an array of string values. [Equivalent to the 'private' builder method in the SDK.](https://launchdarkly-python-sdk.readthedocs.io/en/latest/api-main.html#ldclient.ContextBuilder.private)\n- A key of `anonymous`. Must be a boolean value. [Equivalent to the 'anonymous' builder method in the SDK.](https://launchdarkly-python-sdk.readthedocs.io/en/latest/api-main.html#ldclient.ContextBuilder.anonymous)\n- A key of `name`. Must be a string. [Equivalent to the 'name' builder method in the SDK.](https://launchdarkly-python-sdk.readthedocs.io/en/latest/api-main.html#ldclient.ContextBuilder.name)\n\n### Examples\n\n#### A single user context\n\n```python\ncontext = EvaluationContext(\"the-key\")\n```\n\n#### A single context of kind \"organization\"\n\n```python\ncontext = EvaluationContext(\"org-key\", {\"kind\": \"organization\"});\n```\n\n#### A multi-context containing a \"user\" and an \"organization\"\n\n```python\nattributes = {\n \"kind\": \"multi\",\n \"organization\": {\n \"name\": \"the-org-name\",\n \"targetingKey\", \"my-org-key\",\n \"myCustomAttribute\", \"myAttributeValue\"\n },\n \"user\": {\n \"key\": \"my-user-key\",\n \"anonymous\", true\n }\n}\ncontext = EvaluationContext(null, attributes)\n```\n\n#### Setting private attributes in a single context\n\n```python\nattributes = {\n \"kind\": \"organization\",\n \"myCustomAttribute\": \"myAttributeValue\",\n \"privateAttributes\": [\"myCustomAttribute\"]\n}\n\ncontext = EvaluationContext(\"org-key\", attributes)\n```\n\n#### Setting private attributes in a multi-context\n\n```python\nattributes = {\n \"kind\": \"organization\",\n \"organization\": {\n \"name\": \"the-org-name\",\n \"targetingKey\": \"my-org-key\",\n # This will ONLY apply to the \"organization\" attributes.\n \"privateAttributes\": [\"myCustomAttribute\"],\n # This attribute will be private.\n \"myCustomAttribute\": \"myAttributeValue\",\n },\n \"user\": [\n \"key\": \"my-user-key\",\n \"anonymous\" = > true,\n # This attribute will not be private.\n \"myCustomAttribute\": \"myAttributeValue\",\n ]\n}\n\ncontext = EvaluationContext(null, attributes)\n```\n\n## Learn more\n\nCheck out our [documentation](http://docs.launchdarkly.com) for in-depth instructions on configuring and using LaunchDarkly. You can also head straight to the [complete reference guide for this SDK](https://docs.launchdarkly.com/sdk/server-side/python).\n\nThe authoritative description of all properties and methods is in the [python documentation](https://launchdarkly.github.io/python-server-sdk/).\n\n## Contributing\n\nWe encourage pull requests and other contributions from the community. Check out our [contributing guidelines](CONTRIBUTING.md) for instructions on how to contribute to this SDK.\n\n## About LaunchDarkly\n\n* 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:\n * 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.\n * 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?).\n * 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.\n * Grant access to certain features based on user attributes, like payment plan (eg: users on the \u2018gold\u2019 plan get access to more features than users in the \u2018silver\u2019 plan). Disable parts of your application to facilitate maintenance, without taking everything offline.\n* LaunchDarkly provides feature flag SDKs for a wide variety of languages and technologies. Check out [our documentation](https://docs.launchdarkly.com/sdk) for a complete list.\n* Explore LaunchDarkly\n * [launchdarkly.com](https://www.launchdarkly.com/ \"LaunchDarkly Main Website\") for more information\n * [docs.launchdarkly.com](https://docs.launchdarkly.com/ \"LaunchDarkly Documentation\") for our documentation and SDK reference guides\n * [apidocs.launchdarkly.com](https://apidocs.launchdarkly.com/ \"LaunchDarkly API Documentation\") for our API documentation\n * [blog.launchdarkly.com](https://blog.launchdarkly.com/ \"LaunchDarkly Blog Documentation\") for the latest product updates\n\n",
"bugtrack_url": null,
"license": "Apache-2.0",
"summary": "An OpenFeature provider for the LaunchDarkly Python server SDK",
"version": "0.3.0",
"project_urls": {
"Documentation": "https://launchdarkly-openfeature-python-sdk.readthedocs.io/en/latest/",
"Homepage": "https://github.com/launchdarkly/openfeature-python-server",
"Repository": "https://github.com/launchdarkly/openfeature-python-server"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "4f9ef217c1f624ef37d91e167beab0abb7efaa579a0c39a228c980f3fe44074f",
"md5": "1eacb4f7f2cfdbe936f34f1ec755ccf2",
"sha256": "d212f954113759e55e5d5ef1ac96edd350a1658b71aebd81b0e8abf36d6240a6"
},
"downloads": -1,
"filename": "launchdarkly_openfeature_server-0.3.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "1eacb4f7f2cfdbe936f34f1ec755ccf2",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.8",
"size": 14928,
"upload_time": "2024-10-04T19:41:38",
"upload_time_iso_8601": "2024-10-04T19:41:38.391253Z",
"url": "https://files.pythonhosted.org/packages/4f/9e/f217c1f624ef37d91e167beab0abb7efaa579a0c39a228c980f3fe44074f/launchdarkly_openfeature_server-0.3.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "8e9bd13d0eecd333f23ada8cefcb6eb19d00ed58fb4eca236bc1959facd0aebd",
"md5": "b7d75278054d69cdad22b9b5fe613a58",
"sha256": "f25fa072605dd9858cd316c9a8544146d5ae82741c4e04e9e36d971aa16bb135"
},
"downloads": -1,
"filename": "launchdarkly_openfeature_server-0.3.0.tar.gz",
"has_sig": false,
"md5_digest": "b7d75278054d69cdad22b9b5fe613a58",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.8",
"size": 14549,
"upload_time": "2024-10-04T19:41:40",
"upload_time_iso_8601": "2024-10-04T19:41:40.191273Z",
"url": "https://files.pythonhosted.org/packages/8e/9b/d13d0eecd333f23ada8cefcb6eb19d00ed58fb4eca236bc1959facd0aebd/launchdarkly_openfeature_server-0.3.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-10-04 19:41:40",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "launchdarkly",
"github_project": "openfeature-python-server",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "launchdarkly-openfeature-server"
}