feat(flags): add flag_keys as an option to send_feature_flags config#295
feat(flags): add flag_keys as an option to send_feature_flags config#295
flag_keys as an option to send_feature_flags config#295Conversation
There was a problem hiding this comment.
Greptile Summary
This PR adds support for filtering feature flags by specific keys when using send_feature_flags in the Python SDK, bringing it into parity with the Node.js SDK. The enhancement allows developers to specify which feature flags should be evaluated and included in capture events rather than evaluating all available flags.
The implementation adds a flag_keys parameter to the SendFeatureFlagsOptions TypedDict in types.py, enabling users to pass a list of specific flag keys to evaluate. The core logic is updated in client.py where:
- The
get_all_flagsandget_all_flags_and_payloadsmethods now accept and pass through theflag_keysparameter - Local evaluation in
_get_all_flags_and_payloads_locallyfilters flags during evaluation using a set-based approach for efficient lookup - Remote evaluation results are filtered post-response when
flag_keysis provided - The
_parse_send_feature_flagsmethod handles the new parameter extraction
This change integrates seamlessly with the existing feature flag evaluation pipeline, supporting both local and remote evaluation modes. The filtering occurs at the appropriate points - during local evaluation to avoid unnecessary computation, and after remote evaluation to reduce payload size. The implementation maintains backward compatibility as flag_keys is optional and defaults to None.
Confidence score: 4/5
• This PR is safe to merge with proper functionality and comprehensive test coverage
• The implementation follows established patterns and maintains backward compatibility well
• The test coverage in test_client.py needs minor attention for edge cases around empty flag_keys lists
4 files reviewed, no comments
Summary
This PR adds support for filtering feature flags by specific keys when using
send_feature_flagsin the Python SDK, matching the functionality recently added to the Node.js SDK inPostHog/posthog-js-lite#576.
Changes
flag_keysparameter toSendFeatureFlagsOptionsTypedDictget_all_flagsandget_all_flags_and_payloadsmethods to accept and pass throughflag_keys_get_all_flags_and_payloads_locallyto filter flags by the provided keys during local evaluationflag_keysis specified_parse_send_feature_flagsmethod to handle the new parameterUsage
Testing
Added comprehensive test coverage for: