Skip to main content

Python (OpenFeature)

OpenFeature is a CNCF standard for feature flag evaluation. quonfig-openfeature is a thin provider that wraps the quonfig native SDK and implements the OpenFeature Python server-side AbstractProvider interface.

Install​

pip install quonfig-openfeature quonfig openfeature-sdk

Initialize​

from openfeature import api
from quonfig_openfeature import QuonfigProvider

provider = QuonfigProvider(
sdk_key="qf_sk_production_...",
)

# openfeature-sdk >=0.10 initializes providers on a background thread, so plain
# set_provider() returns before the provider reaches READY. The first evaluation
# then races init and silently resolves to the OpenFeature default
# (PROVIDER_NOT_READY). set_provider_and_wait() blocks until READY so your first
# read reflects live config.
api.set_provider_and_wait(provider)
client = api.get_client()

If you cannot block at startup, use plain set_provider() and gate your first evaluations on the provider-ready event instead:

from openfeature import api
from openfeature.event import ProviderEvent

api.add_handler(ProviderEvent.PROVIDER_READY, lambda details: on_ready())
api.set_provider(provider) # returns immediately; PROVIDER_READY fires once init completes
If Quonfig is unreachable at startup

Extra keyword arguments to QuonfigProvider(...) go to the native quonfig client, so its startup options pass straight through. Under the default on_init_failure="fail", api.set_provider_and_wait() raises ProviderNotReadyError if no config loads within init_timeout_ms (10s by default). Pass on_init_failure="continue" to start on code defaults instead, or "wait" to block until config loads:

provider = QuonfigProvider(
sdk_key="qf_sk_production_...",
on_init_failure="continue", # default "fail"; or "wait"
init_timeout_ms=10_000,
)

Plain api.set_provider() never raises. Until config loads, evaluations return your default with PROVIDER_NOT_READY, and the provider emits PROVIDER_READY once the client heals. See If Quonfig Is Unreachable at Startup.

Evaluate flags​

# Boolean flag
enabled = client.get_boolean_value("checkout-v2", False)

# String config
welcome = client.get_string_value("welcome-message", "Hello!")

# Integer config
timeout_ms = client.get_integer_value("request-timeout-ms", 5000)

# Float config
upload_limit = client.get_float_value("upload-limit-gb", 1.0)

# Object config (JSON or string_list)
allowed_plans = client.get_object_value("allowed-plans", [])

Values are never coerced: reading a config with the method for another type returns your default with TYPE_MISMATCH, and a value of the right type that does not parse (a stored int "twelve", a malformed duration) returns your default with PARSE_ERROR. The rules come from the native SDK; see Typed Getters, Defaults, and Error Codes.

Evaluation context​

Pass per-request context as the third argument:

from openfeature.evaluation_context import EvaluationContext

is_pro = client.get_boolean_value(
"pro-feature",
False,
EvaluationContext(
targeting_key="user-123", # maps to user.id by default
attributes={
"user.plan": "pro",
"org.tier": "enterprise",
},
),
)

OpenFeature context is flat; Quonfig context is namespace-nested. The provider maps between them using dot-notation:

OpenFeature keyQuonfig namespaceQuonfig property
targeting_keyuserid (configurable)
"user.email"useremail
"org.tier"orgtier
"country" (no dot)"" (default)country
"user.ip.address"userip.address (split on first dot)

Custom targeting_key mapping​

provider = QuonfigProvider(
sdk_key="qf_sk_...",
targeting_key_mapping="account.id",
)

Native SDK escape hatch​

Access the underlying quonfig client for features not available in OpenFeature:

native = provider.get_client()

# Log level integration — pass the full stored key
should_log = native.should_log(
config_key="log-level.auth",
desired_level="DEBUG",
contexts={"user": {"id": "user-123"}},
)

# List all config keys
keys = native.keys()

What you lose vs. the native SDK​

OpenFeature is designed for feature flags, not general configuration. Some Quonfig features require the native quonfig SDK directly:

  1. Log levels -- should_log() is native-only; access via provider.get_client().
  2. string_list configs -- must be accessed via get_object_value() and used as a list[str].
  3. duration configs -- get_string_value() returns the ISO 8601 text exactly as stored (e.g. "PT90S"); use provider.get_client().get_duration() for float seconds. get_float_value() on a duration returns your default with TYPE_MISMATCH.
  4. bytes configs -- not accessible (no binary type in OpenFeature).
  5. keys() and raw config access -- native-only via provider.get_client().
  6. Context keys use dot-notation -- pass "user.email", not nested dicts.
  7. targeting_key maps to user.id by default -- configure targeting_key_mapping if different.