OpenFeature (Python)
Contents
PostHog provides an official OpenFeature provider for Python, so you can evaluate PostHog feature flags through the standard OpenFeature API.
- Package:
openfeature-provider-posthog - Import path:
openfeature.contrib.provider.posthog
Installation
This installs posthog and openfeature-sdk as dependencies.
Usage
Construct and configure a PostHog client, then register the provider with the OpenFeature SDK:
You own the PostHog client lifecycle — call client.shutdown() when your app exits.
Evaluation context
The OpenFeature evaluation context maps to PostHog's flag evaluation inputs:
If no targeting_key is present and no default_distinct_id is configured, the provider returns your default value with error_code = TARGETING_KEY_MISSING.
Supported flag types
Calling a typed getter on an incompatible flag (for example get_string_value on a boolean flag) returns your default value with error_code = TYPE_MISMATCH, per the OpenFeature spec.
Options
PostHogProvider(client, *, default_distinct_id=None, send_feature_flag_events=True)
default_distinct_id— distinct ID used when the context has notargeting_key. Defaults toNone(raiseTARGETING_KEY_MISSING).send_feature_flag_events— whether to emit$feature_flag_calledevents on each evaluation. Defaults toTrue.






