GO Feature Flag Python Provider

raw JSON →
1.0.0 verified Sat May 09 auth: no python

An OpenFeature provider for GO Feature Flag, enabling feature flag evaluation in Python applications. Version 1.0.0 supports OpenFeature 1.x and requires Python >=3.9. Released with monthly cadence.

pip install gofeatureflag-python-provider
error ImportError: cannot import name 'GoFeatureFlagProvider' from 'gofeatureflag_python_provider'
cause Wrong import path: trying to import from package root instead of the provider submodule.
fix
Use: from gofeatureflag_python_provider.provider import GoFeatureFlagProvider
error AttributeError: 'GoFeatureFlagProvider' object has no attribute 'initialize'
cause Using an older OpenFeature SDK (<1.0) where initialize is called differently.
fix
Upgrade openfeature-sdk to >=1.0 and use api.set_provider(provider) instead of provider.initialize().
breaking Provider is not thread-safe: The GoFeatureFlagProvider currently uses a shared HTTP session that is not thread-safe. Avoid sharing a single provider instance across multiple threads without external synchronization.
fix Create a new provider instance per thread or use a threading lock.
deprecated OpenFeature SDK v0.x incompatibility: This provider is designed for OpenFeature SDK v1.x. Using it with v0.x will cause import errors.
fix Ensure openfeature-sdk is version 1.x.
gotcha Provider requires explicit endpoint: The default endpoint is localhost:1031. If your GO Feature Flag relay proxy is elsewhere, you must set the endpoint explicitly via environment variable or constructor argument.
fix Set the GOFEATUREFLAG_ENDPOINT environment variable or pass the endpoint argument.

Initialize the GO Feature Flag provider, set it as the OpenFeature provider, and evaluate a boolean flag.

import os
from openfeature import api
from openfeature.evaluation_context import EvaluationContext
from gofeatureflag_python_provider.provider import GoFeatureFlagProvider

# Set endpoint via environment variable
endpoint = os.environ.get('GOFEATUREFLAG_ENDPOINT', 'http://localhost:1031')
provider = GoFeatureFlagProvider(endpoint=endpoint)
api.set_provider(provider)
client = api.get_client()

# Evaluate a boolean flag
targeting_key = "user-key"
context = EvaluationContext(targeting_key=targeting_key, attributes={"email": "test@example.com"})
flag_value = client.get_boolean_value("my-feature-flag", default=False, evaluation_context=context)
print(f"Flag value: {flag_value}")