Skip to content

Expose get_feature_flag_result at the module level #270

@ordehi

Description

@ordehi

Is your feature request related to a problem?

Currently, get_feature_flag_result is only available through the direct Client interface but not at the module level. This means users who want to access extended feature flag information (payload, reason, etc.) are forced to use multiple SDK methods get_feature_flag and get_feature_flag_payload or use the Client interface, even though the module-level API is the recommended approach for most use cases.

This creates a suboptimal experience where users need to:

  1. Make multiple API calls to get all flag information
  2. Or switch to the Client interface just to access this consolidated method

Describe the solution you'd like

Expose get_feature_flag_result at the module level to provide a single method that returns all flag information in one call. This would maintain the benefits of the module-level API while providing a more efficient way to access complete flag information.

Example desired usage:

import posthog

posthog.api_key = 'api-key'
result = posthog.get_feature_flag_result('flag-key', 'user-123')
if result:
    print(f"Enabled: {result.enabled}")
    print(f"Variant: {result.variant}")
    print(f"Payload: {result.payload}")
    print(f"Reason: {result.reason}")

This would reduce the number of API calls needed when both flag state and payload information are required.

Describe alternatives you've considered

  1. Continue using separate get_feature_flag and get_feature_flag_payload calls
  2. Use get_all_flags_and_payloads and filter, expensive!
  3. Use the Client interface when consolidated information is needed
  4. Create a new module-level method with a different name that combines the functionality

Additional context

https://posthoghelp.zendesk.com/agent/tickets/32975

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions