workos-python icon indicating copy to clipboard operation
workos-python copied to clipboard

Add support for listing feature flags

Open SebastianLoef opened this issue 4 months ago • 1 comments

Add support for listing feature flags. As of now, from what I can see, only cURL, JS and Ruby supports it.

https://workos.com/docs/reference/feature-flags/list-for-organization

SebastianLoef avatar Sep 01 '25 14:09 SebastianLoef

Temporary solution for my fellow python developers:

import requests
from pydantic import BaseModel
from workos import WorkOSClient


class FeatureFlag(BaseModel):
    object: str
    id: str
    name: str
    slug: str
    description: str
    created_at: str
    updated_at: str


def list_org_feature_flags(workos_client: WorkOSClient, org_id: str):
    """WorkOSClient does not yet support listing feature flags for an organization.
    This function will use requests directly to the WorkOS API to list feature flags for an organization.

    Args:
        workos_client (WorkOSClient): WorkOSClient instance
        org_id (str): Organization ID

    Returns:
        list[FeatureFlag]: List of feature flags
    """
    url = f"https://api.workos.com/organizations/{org_id}/feature-flags"
    headers = {
        "Authorization": f"Bearer {workos_client._api_key}",
        "Content-Type": "application/json",
    }
    response = requests.get(url, headers=headers)
    if response.status_code != 200:
        raise Exception(
            f"Failed to list feature flags for organization {org_id}: {response.status_code}: {response.text}"
        )
    return [FeatureFlag(**feature_flag) for feature_flag in response.json()["data"]]

SebastianLoef avatar Sep 01 '25 15:09 SebastianLoef