Skip to main content

Openfeature provider for Flagsmith

Project description

flagsmith-openfeature-provider-python

The Flagsmith provider allows you to connect to your Flagsmith instance through the OpenFeature SDK

Python SDK usage

Install dependencies

First, you'll need to install the OpenFeature SDK and the Flagsmith Provider.

pip install openfeature-sdk openfeature-provider-flagsmith

Using the Flagsmith Provider with the OpenFeature SDK

To create a Flagsmith provider you will need to provide a number of arguments. These are shown and described below. See the Flagsmith docs for further information on the configuration options available for the Flagsmith python client.

from flagsmith import Flagsmith
from openfeature_flagsmith.provider import FlagsmithProvider

provider = FlagsmithProvider(
    # Provide an instance of the Flagsmith python client.
    # Required: True
    client=Flagsmith(...),
    
    # By enabling the use_flagsmith_defaults setting, you can instruct the OpenFeature SDK to use
    # the default logic included in the Flagsmith client as per the docs here: 
    # https://docs.flagsmith.com/clients/server-side#managing-default-flags. This will override the 
    # default provided at evaluation time in the OpenFeature SDK in most cases (excluding those where 
    # an unexpected exception happens in the Flagsmith client itself).
    # Required: False
    # Default: False
    use_flagsmith_defaults=False,
    
    # By default, when evaluating the boolean value of a feature in the OpenFeature SDK, the Flagsmith 
    # OpenFeature Provider will use the 'Enabled' state of the feature as defined in Flagsmith. This 
    # behaviour can be changed to use the 'value' field defined in the Flagsmith feature instead by 
    # enabling the use_boolean_config_value setting. 
    # Note: this relies on the value being defined as a Boolean in Flagsmith. If the value is not a 
    # Boolean, an error will occur and the default value provided as part of the evaluation will be 
    # returned instead.  
    # Required: False
    # Default: False
    use_boolean_config_value=False,
    
    # By default, the Flagsmith OpenFeature Provider will raise an exception (triggering the 
    # OpenFeature SDK to return the provided default value) if the flag is disabled. This behaviour
    # can be configured by enabling this flag so that the Flagsmith OpenFeature provider ignores
    # the enabled state of a flag when returning a value.
    # Required: False
    # Default: False
    return_value_for_disabled_flags=False,
)

The provider can then be used with the OpenFeature client as per the documentation.

Evaluation Context

The evaluation context supports traits in two ways:

  1. Flat top-level attributes
  2. A nested traits object

The two forms are merged and sent to Flagsmith, with the traits object taking precedence if keys conflict.

context = EvaluationContext( # Traits are: {"abc":"def", "foo": "bar2"}
    targeting_key="user",
    attributes={
        "foo": "bar", 
        "abc": "def", 
        "traits": {"foo": "bar2"}
    },
)

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

openfeature_provider_flagsmith-0.1.6.tar.gz (4.1 kB view details)

Uploaded Source

File details

Details for the file openfeature_provider_flagsmith-0.1.6.tar.gz.

File metadata

File hashes

Hashes for openfeature_provider_flagsmith-0.1.6.tar.gz
Algorithm Hash digest
SHA256 49fe9f779dd83f3e73ce1480dd16e8a2cd332e237e48a4d08e200282a4c3f206
MD5 2e18d790a4869815b8435ecde4aa0635
BLAKE2b-256 9d59990d5b04655befe576b456591a520e1e88a21aa41a4968159584a12d27f8

See more details on using hashes here.

Provenance

The following attestation bundles were made for openfeature_provider_flagsmith-0.1.6.tar.gz:

Publisher: publish.yml on Flagsmith/flagsmith-openfeature-provider-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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