{"id":10009,"library":"openfeature-provider-flagsmith","title":"OpenFeature Provider for Flagsmith","description":"The `openfeature-provider-flagsmith` library provides an OpenFeature-compliant provider for Flagsmith. It allows applications to integrate Flagsmith's feature flag capabilities using the OpenFeature SDK, abstracting the underlying feature flagging system. The current version is 0.1.6, with releases typically tied to updates in OpenFeature SDK or Flagsmith SDK, or feature enhancements.","status":"active","version":"0.1.6","language":"en","source_language":"en","source_url":"https://github.com/Flagsmith/openfeature-provider-flagsmith","tags":["feature flags","openfeature","flagsmith","feature management"],"install":[{"cmd":"pip install openfeature-provider-flagsmith","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"Required for interacting with the Flagsmith API.","package":"flagsmith","optional":false},{"reason":"The core OpenFeature SDK for Python, which this provider integrates with.","package":"openfeature-sdk","optional":false}],"imports":[{"note":"The FlagsmithProvider class is directly available at the top level of the package.","wrong":"from openfeature_provider_flagsmith.provider import FlagsmithProvider","symbol":"FlagsmithProvider","correct":"from openfeature_provider_flagsmith import FlagsmithProvider"},{"note":"This is part of the core OpenFeature SDK, not the Flagsmith provider itself.","symbol":"OpenFeatureAPI","correct":"from openfeature import OpenFeatureAPI"}],"quickstart":{"code":"import os\nfrom openfeature import OpenFeatureAPI\nfrom openfeature_provider_flagsmith import FlagsmithProvider\n\n# Ensure you have your Flagsmith Environment Key set as an environment variable\n# Or replace os.environ.get() with your actual key directly (not recommended for production)\nFLAGSMITH_ENVIRONMENT_KEY = os.environ.get(\"FLAGSMITH_ENVIRONMENT_KEY\", \"\")\n\nif not FLAGSMITH_ENVIRONMENT_KEY:\n    print(\"Error: FLAGSMITH_ENVIRONMENT_KEY environment variable not set.\")\n    print(\"Please set it to your Flagsmith Environment Key to run this example.\")\nelse:\n    # 1. Initialize the Flagsmith Provider\n    provider = FlagsmithProvider(environment_key=FLAGSMITH_ENVIRONMENT_KEY)\n\n    # 2. Set the provider globally for OpenFeature\n    OpenFeatureAPI.set_provider(provider)\n\n    # 3. Get an OpenFeature client\n    client = OpenFeatureAPI.get_client()\n\n    # 4. Evaluate a feature flag (assuming 'my_boolean_flag' exists in Flagsmith)\n    # Provide a default value (False) in case the flag is not found or an error occurs\n    is_feature_enabled = client.get_boolean_value(\"my_boolean_flag\", False)\n\n    print(f\"Feature 'my_boolean_flag' is enabled: {is_feature_enabled}\")\n\n    # Example with a string flag\n    welcome_message = client.get_string_value(\"welcome_message\", \"Hello, World!\")\n    print(f\"Welcome message: {welcome_message}\")\n","lang":"python","description":"This quickstart demonstrates how to initialize the `FlagsmithProvider` with your Flagsmith Environment Key, register it with the OpenFeature API, and then use the OpenFeature client to evaluate boolean and string feature flags. Ensure your `FLAGSMITH_ENVIRONMENT_KEY` is set as an environment variable."},"warnings":[{"fix":"Always provide your Flagsmith Environment Key during `FlagsmithProvider` instantiation: `FlagsmithProvider(environment_key=\"YOUR_KEY\")`.","message":"The `environment_key` is a mandatory argument for `FlagsmithProvider`. Failure to provide a valid key will lead to errors during initialization or feature flag evaluation.","severity":"gotcha","affected_versions":"All"},{"fix":"Ensure your application has stable network access to the Flagsmith API. Check your Flagsmith project configuration and API status if you encounter network-related errors. Consider using `OpenFeatureAPI.set_default_value` for robust fallback behavior.","message":"The provider relies on network connectivity to the Flagsmith API. Issues like network timeouts or incorrect API endpoints (if customized) can prevent feature flags from being resolved.","severity":"gotcha","affected_versions":"All"},{"fix":"Always provide a sensible and safe default value that ensures your application can function even if the feature flag cannot be resolved correctly. E.g., `client.get_boolean_value(\"my_flag\", False)`.","message":"The OpenFeature `get_value` methods (e.g., `get_boolean_value`) require a default value. This default is returned if the flag is not found in Flagsmith, if the provider is not configured correctly, or if an error occurs during evaluation.","severity":"gotcha","affected_versions":"All"},{"fix":"Strictly adhere to the `flagsmith` SDK version range specified by `openfeature-provider-flagsmith`'s `install_requires`. Upgrade `openfeature-provider-flagsmith` if you need to use a newer `flagsmith` SDK version.","message":"The `flagsmith` SDK dependency has minimum version `4.0.0` and maximum `5.x.x` (i.e., `<6.0.0`). Newer versions of the `flagsmith` SDK (e.g., `6.x.x`) may introduce breaking changes not yet supported by this provider.","severity":"deprecated","affected_versions":">=0.1.0"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"Run `pip install openfeature-provider-flagsmith`.","cause":"The `openfeature-provider-flagsmith` library has not been installed in the current Python environment.","error":"ModuleNotFoundError: No module named 'openfeature_provider_flagsmith'"},{"fix":"Pass your Flagsmith Environment Key: `provider = FlagsmithProvider(environment_key=\"YOUR_FLAGSMITH_ENVIRONMENT_KEY\")`.","cause":"The `environment_key` argument, which is your Flagsmith environment's unique key, was not provided during the instantiation of `FlagsmithProvider`.","error":"TypeError: FlagsmithProvider.__init__ missing 1 required positional argument: 'environment_key'"},{"fix":"Verify your internet connection, ensure the `environment_key` is correct, and check if the Flagsmith API is reachable. If you're self-hosting Flagsmith, confirm your `api_url` parameter is correctly configured (not shown in quickstart, but an option for `FlagsmithProvider`).","cause":"The `flagsmith` SDK failed to connect to the Flagsmith API due to network issues, an incorrect API key, or an invalid base URL (if customized).","error":"flagsmith.exceptions.FlagsmithAPIError: Network Error ..."}]}