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.
Tracking
The provider supports the OpenFeature tracking API, which lets you associate user actions with feature flag evaluations for experimentation.
Tracking requires pipeline analytics to be enabled on the Flagsmith client (available from flagsmith version 5.2.0). The provider acts as a thin delegate — all buffering and flushing is managed by the client.
from flagsmith import Flagsmith, PipelineAnalyticsConfig
from openfeature import api
from openfeature.evaluation_context import EvaluationContext
from openfeature.track import TrackingEventDetails
from openfeature_flagsmith.provider import FlagsmithProvider
# Enable pipeline analytics on the Flagsmith client
client = Flagsmith(
environment_key="your-environment-key",
pipeline_analytics_config=PipelineAnalyticsConfig(
analytics_server_url="https://analytics-collector.flagsmith.com/",
max_buffer_items=1000, # optional, default 1000
flush_interval_seconds=10, # optional, default 10s
),
)
api.set_provider(FlagsmithProvider(client=client))
of_client = api.get_client()
# Flag evaluations are tracked automatically — no extra code needed
variant = of_client.get_string_value(
"checkout-variant",
"control",
evaluation_context=EvaluationContext(targeting_key="user-123"),
)
# Track a custom event explicitly
of_client.track(
"purchase",
evaluation_context=EvaluationContext(
targeting_key="user-123",
attributes={"plan": "premium"},
),
tracking_event_details=TrackingEventDetails(
value=99.77,
attributes={"currency": "USD"},
),
)
If pipeline_analytics_config is not set on the Flagsmith client, calls to track() are silently ignored.
Evaluation Context
The evaluation context supports traits in two ways:
- Flat top-level attributes
- 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file openfeature_provider_flagsmith-0.2.0.tar.gz.
File metadata
- Download URL: openfeature_provider_flagsmith-0.2.0.tar.gz
- Upload date:
- Size: 5.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b5411613fa24efde96356d987b15c3efbb0455c4771306c26d73d526a0021a73
|
|
| MD5 |
f603e9223b01e723ce346c9f1c1b6cca
|
|
| BLAKE2b-256 |
67983db0f72e19114a9e259889ab4ed425899a2448cc839e949b977e56581010
|
Provenance
The following attestation bundles were made for openfeature_provider_flagsmith-0.2.0.tar.gz:
Publisher:
publish.yml on Flagsmith/flagsmith-openfeature-provider-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
openfeature_provider_flagsmith-0.2.0.tar.gz -
Subject digest:
b5411613fa24efde96356d987b15c3efbb0455c4771306c26d73d526a0021a73 - Sigstore transparency entry: 1409172402
- Sigstore integration time:
-
Permalink:
Flagsmith/flagsmith-openfeature-provider-python@20c9f20f902cfa3306b15246ba1c7e72c768fa1c -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/Flagsmith
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@20c9f20f902cfa3306b15246ba1c7e72c768fa1c -
Trigger Event:
push
-
Statement type:
File details
Details for the file openfeature_provider_flagsmith-0.2.0-py3-none-any.whl.
File metadata
- Download URL: openfeature_provider_flagsmith-0.2.0-py3-none-any.whl
- Upload date:
- Size: 6.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5a87df0ddaf0efaa664f0a71a9422733ac4ab7bd47782503039022c9c3206d8e
|
|
| MD5 |
1b54f09c333c11e8a8da7fc41c5de765
|
|
| BLAKE2b-256 |
15d712486d65e1ff168b5485dba850f55732d77c370a321a5d64a8d0d3937d60
|
Provenance
The following attestation bundles were made for openfeature_provider_flagsmith-0.2.0-py3-none-any.whl:
Publisher:
publish.yml on Flagsmith/flagsmith-openfeature-provider-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
openfeature_provider_flagsmith-0.2.0-py3-none-any.whl -
Subject digest:
5a87df0ddaf0efaa664f0a71a9422733ac4ab7bd47782503039022c9c3206d8e - Sigstore transparency entry: 1409172408
- Sigstore integration time:
-
Permalink:
Flagsmith/flagsmith-openfeature-provider-python@20c9f20f902cfa3306b15246ba1c7e72c768fa1c -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/Flagsmith
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@20c9f20f902cfa3306b15246ba1c7e72c768fa1c -
Trigger Event:
push
-
Statement type: