OpenFeature provider for the flagd flag evaluation engine
Project description
flagd Provider for OpenFeature
This provider is designed to use flagd's evaluation protocol, or locally evaluate flags defined in a flagd flag definition via the OpenFeature Python SDK.
Installation
pip install openfeature-provider-flagd
Configuration and Usage
The flagd provider can operate in two modes: RPC (evaluation takes place in flagd, via gRPC calls) or in-process (evaluation takes place in-process, with the provider getting a ruleset from a compliant sync-source).
Remote resolver (RPC)
This is the default mode of operation of the provider.
In this mode, FlagdProvider communicates with flagd via the gRPC protocol.
Flag evaluations take place remotely at the connected flagd instance.
Instantiate a new FlagdProvider instance and configure the OpenFeature SDK to use it:
from openfeature import api
from openfeature.contrib.provider.flagd import FlagdProvider
api.set_provider(FlagdProvider())
In-process resolver
This mode performs flag evaluations locally (in-process). Flag configurations for evaluation are obtained via gRPC protocol using sync protobuf schema service definition.
Consider the following example to create a FlagdProvider with in-process evaluations,
from openfeature import api
from openfeature.contrib.provider.flagd import FlagdProvider
from openfeature.contrib.provider.flagd.config import ResolverType
api.set_provider(FlagdProvider(
resolver_type=ResolverType.IN_PROCESS,
))
In the above example, in-process handlers attempt to connect to a sync service on address localhost:8013 to obtain flag definitions.
File mode
In-process resolvers can also work in an offline mode.
To enable this mode, you should provide a valid flag configuration file with the option offlineFlagSourcePath.
from openfeature import api
from openfeature.contrib.provider.flagd import FlagdProvider
from openfeature.contrib.provider.flagd.config import ResolverType
api.set_provider(FlagdProvider(
resolver_type=ResolverType.FILE,
offline_flag_source_path="my-flag.json",
))
Provider will attempt to detect file changes using polling. Polling happens at 5 second intervals and this is currently unconfigurable. This mode is useful for local development, tests and offline applications.
Configuration options
The default options can be defined in the FlagdProvider constructor.
| Option name | Environment variable name | Type & Values | Default | Compatible resolver |
|---|---|---|---|---|
| resolver_type | FLAGD_RESOLVER | enum - rpc, in-process |
rpc | |
| host | FLAGD_HOST | str | localhost | rpc & in-process |
| port | FLAGD_PORT | int | 8013 (rpc), 8015 (in-process) | rpc & in-process |
| tls | FLAGD_TLS | bool | false | rpc & in-process |
| cert_path | FLAGD_SERVER_CERT_PATH | String | null | rpc & in-process |
| deadline | FLAGD_DEADLINE_MS | int | 500 | rpc & in-process |
| stream_deadline_ms | FLAGD_STREAM_DEADLINE_MS | int | 600000 | rpc & in-process |
| keep_alive_time | FLAGD_KEEP_ALIVE_TIME_MS | int | 0 | rpc & in-process |
| selector | FLAGD_SOURCE_SELECTOR | str | null | in-process |
| cache_type | FLAGD_CACHE | enum - lru, disabled |
lru | rpc |
| max_cache_size | FLAGD_MAX_CACHE_SIZE | int | 1000 | rpc |
| retry_backoff_ms | FLAGD_RETRY_BACKOFF_MS | int | 1000 | rpc |
| offline_flag_source_path | FLAGD_OFFLINE_FLAG_SOURCE_PATH | str | null | in-process |
[!NOTE] The
selectorconfiguration is only used in in-process mode for filtering flag configurations. See Selector Handling for migration guidance.
[!NOTE] Some configurations are only applicable for RPC resolver.
Selector Handling (In-Process Mode Only)
[!IMPORTANT] This section only applies to in-process resolver mode. RPC mode is not affected by selector handling changes.
Current Implementation
As of this SDK version, the selector parameter is passed via both gRPC metadata headers (flagd-selector) and the request body when using in-process mode. This dual approach ensures maximum compatibility with all flagd versions.
Configuration Example:
from openfeature import api
from openfeature.contrib.provider.flagd import FlagdProvider
from openfeature.contrib.provider.flagd.config import ResolverType
api.set_provider(FlagdProvider(
resolver_type=ResolverType.IN_PROCESS,
selector="my-flag-source", # Passed via both header and request body
))
The selector is automatically passed via:
- gRPC metadata header (
flagd-selector) - For flagd v0.11.0+ selector normalization - Request body - For backward compatibility with older flagd versions
Backward Compatibility
This dual transmission approach ensures the Python SDK works seamlessly with all flagd service versions:
- Older flagd versions read the selector from the request body
- Newer flagd versions (v0.11.0+) prefer the selector from the gRPC metadata header
- Both approaches are supported simultaneously for maximum compatibility
Related Resources:
- Upstream issue: open-feature/flagd#1814
- Selector normalization affects in-process evaluations that filter flag configurations by source
Reconnection
Reconnection is supported by the underlying gRPC connections. If the connection to flagd is lost, it will reconnect automatically. A failure to connect will result in an error event from the provider, though it will attempt to reconnect indefinitely.
Deadlines
Deadlines are used to define how long the provider waits to complete initialization or flag evaluations. They behave differently based on the resolver type.
Deadlines with Remote resolver (RPC)
If the remote evaluation call is not completed within this deadline, the gRPC call is terminated with the error DEADLINE_EXCEEDED
and the evaluation will default.
TLS
TLS is available in situations where flagd is running on another host.
You may optionally supply an X.509 certificate in PEM format. Otherwise, the default certificate store will be used.
from openfeature import api
from openfeature.contrib.provider.flagd import FlagdProvider
api.set_provider(FlagdProvider(
tls=True, # use TLS
cert_path="etc/cert/ca.crt" # PEM cert
))
License
Apache 2.0 - See LICENSE for more information.
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_flagd-0.2.7.tar.gz.
File metadata
- Download URL: openfeature_provider_flagd-0.2.7.tar.gz
- Upload date:
- Size: 64.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ee6dee7551e9fd479ec00aa78de84d1f53d4bb8a5d1ce93e5ca9c67bf879fea7
|
|
| MD5 |
97c114929116c38bda7ed5596d8538de
|
|
| BLAKE2b-256 |
51f502c0c03ffcdf740737dabca096256e78afb3711168e3e44f486288cdb860
|
Provenance
The following attestation bundles were made for openfeature_provider_flagd-0.2.7.tar.gz:
Publisher:
release.yml on open-feature/python-sdk-contrib
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
openfeature_provider_flagd-0.2.7.tar.gz -
Subject digest:
ee6dee7551e9fd479ec00aa78de84d1f53d4bb8a5d1ce93e5ca9c67bf879fea7 - Sigstore transparency entry: 910145998
- Sigstore integration time:
-
Permalink:
open-feature/python-sdk-contrib@a345ef9f1ea3333e49a173553a9098f5db6746a7 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/open-feature
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@a345ef9f1ea3333e49a173553a9098f5db6746a7 -
Trigger Event:
push
-
Statement type:
File details
Details for the file openfeature_provider_flagd-0.2.7-py3-none-any.whl.
File metadata
- Download URL: openfeature_provider_flagd-0.2.7-py3-none-any.whl
- Upload date:
- Size: 58.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
645aabbafae932df1c98257763b8afbbd874ff2aa70088249f45314cf5009dda
|
|
| MD5 |
07388b1e0deda396c31f2f2d4e4b0cb2
|
|
| BLAKE2b-256 |
354da296df991f7fbbb3652f3f0125ad6de31fa7fe366e640a2b50ba80f78637
|
Provenance
The following attestation bundles were made for openfeature_provider_flagd-0.2.7-py3-none-any.whl:
Publisher:
release.yml on open-feature/python-sdk-contrib
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
openfeature_provider_flagd-0.2.7-py3-none-any.whl -
Subject digest:
645aabbafae932df1c98257763b8afbbd874ff2aa70088249f45314cf5009dda - Sigstore transparency entry: 910146043
- Sigstore integration time:
-
Permalink:
open-feature/python-sdk-contrib@a345ef9f1ea3333e49a173553a9098f5db6746a7 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/open-feature
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@a345ef9f1ea3333e49a173553a9098f5db6746a7 -
Trigger Event:
push
-
Statement type: