Skip to content

Api reference

components.feature_flags_context.public.api

DataAccessors

Bases: TypedDict

Type definition for data accessor functions.

All keys are optional to allow partial provision of accessors.

member_account_ids instance-attribute

member_account_ids

Function that takes company IDs and returns a list of unique account IDs

get_feature_flags_context_for_user

get_feature_flags_context_for_user(
    user, data_accessors=None
)

Get LaunchDarkly context data for a user.

This function extracts relevant information for feature flagging purposes using country-agnostic components to avoid dependencies between be/fr/es/ca.

Parameters:

Name Type Description Default
user BaseUser

The user object (can be from any country)

required
data_accessors Optional[DataAccessors]

Optional typed dictionary of accessor functions. See DataAccessors type for supported keys and signatures. Currently supported: - "member_account_ids": Function(company_ids: Iterable[str]) -> list[str]

None

Returns:

Type Description
dict[str, Any]

A dictionary containing LaunchDarkly context data with:

dict[str, Any]
  • email: User's email from global profile
dict[str, Any]
  • country: Country extracted from current app context
dict[str, Any]
  • companyIds: List of company IDs where the user is currently employed
dict[str, Any]
  • memberAccountIds: List of account IDs (only if data_accessors["member_account_ids"] provided)
Source code in components/feature_flags_context/public/api.py
def get_feature_flags_context_for_user(
    user: BaseUser, data_accessors: Optional[DataAccessors] = None
) -> dict[str, Any]:
    """
    Get LaunchDarkly context data for a user.

    This function extracts relevant information for feature flagging purposes
    using country-agnostic components to avoid dependencies between be/fr/es/ca.

    Args:
        user: The user object (can be from any country)
        data_accessors: Optional typed dictionary of accessor functions.
                       See DataAccessors type for supported keys and signatures.
                       Currently supported:
                       - "member_account_ids": Function(company_ids: Iterable[str]) -> list[str]

    Returns:
        A dictionary containing LaunchDarkly context data with:
        - email: User's email from global profile
        - country: Country extracted from current app context
        - companyIds: List of company IDs where the user is currently employed
        - memberAccountIds: List of account IDs (only if data_accessors["member_account_ids"] provided)
    """
    from components.feature_flags_context.internal.business_logic.context_extractor import (
        extract_user_context,
    )

    return extract_user_context(user, data_accessors)