{"id":8678,"library":"splitio-client","title":"Split.io Python Client","description":"Split.io Python Client (splitio-client) is the official Python SDK for the Split Feature Delivery Platform. It enables developers to implement feature flags, conduct controlled rollouts, and perform data-driven experiments to manage the customer experience. The library is actively maintained by Split (now part of Harness) with frequent updates that include bug fixes and new feature support, such as rule-based segments and feature flag prerequisites. It is compatible with Python 3.7 and higher.","status":"active","version":"10.6.0","language":"en","source_language":"en","source_url":"https://github.com/splitio/python-client","tags":["feature flag","a/b testing","split testing","experimentation","rollout","harness"],"install":[{"cmd":"pip install splitio-client","lang":"bash","label":"Standard installation"},{"cmd":"pip install 'splitio-client[cpphash,asyncio]' ","lang":"bash","label":"With C++ hashing and asyncio support"}],"dependencies":[{"reason":"Required if using the Redis storage backend for multi-process environments.","package":"redis","optional":true}],"imports":[{"symbol":"get_factory","correct":"from splitio import get_factory"},{"symbol":"TimeoutException","correct":"from splitio.exceptions import TimeoutException"},{"note":"For asynchronous (asyncio) factory initialization.","symbol":"get_factory_async","correct":"from splitio import get_factory_async"}],"quickstart":{"code":"import os\nfrom splitio import get_factory\nfrom splitio.exceptions import TimeoutException\n\n# Get your SDK API key from environment variables for security\nSPLIT_API_KEY = os.environ.get('SPLIT_SDK_API_KEY', 'YOUR_SDK_TYPE_API_KEY')\nCUSTOMER_ID = 'test_user_123'\nFEATURE_FLAG_NAME = 'my_new_feature'\n\n# Initialize the Split factory\n# For production, ensure config is properly set up, e.g., for logging, storage, etc.\nfactory = get_factory(SPLIT_API_KEY)\n\ntry:\n    # Wait up to 5 seconds for the SDK to be ready and download definitions\n    factory.block_until_ready(5)\n    split_client = factory.client()\n\n    # Get treatment for the customer\n    treatment = split_client.get_treatment(CUSTOMER_ID, FEATURE_FLAG_NAME)\n\n    if treatment == 'on':\n        print(f\"Feature '{FEATURE_FLAG_NAME}' is ON for user '{CUSTOMER_ID}'.\")\n        # Code to show 'on' treatment\n    elif treatment == 'off':\n        print(f\"Feature '{FEATURE_FLAG_NAME}' is OFF for user '{CUSTOMER_ID}'.\")\n        # Code to show 'off' treatment\n    else:\n        # 'control' or any other undefined treatment\n        print(f\"Feature '{FEATURE_FLAG_NAME}' is in CONTROL for user '{CUSTOMER_ID}'.\")\n        # Code for default/control treatment\n\nexcept TimeoutException:\n    print(\"Split SDK timed out while initializing. Falling back to control.\")\n    # Handle timeout gracefully, e.g., log and proceed with default experience\nexcept Exception as e:\n    print(f\"An error occurred: {e}\")\nfinally:\n    # It's important to destroy the factory when the application shuts down\n    # to ensure all queued impressions/events are sent and resources are released.\n    factory.destroy()","lang":"python","description":"This quickstart demonstrates how to initialize the Split.io Python SDK, wait for it to be ready, and retrieve a treatment for a specific feature flag and user key. It also includes basic error handling for timeouts and ensures proper shutdown of the SDK factory."},"warnings":[{"fix":"Call `factory.block_until_ready(timeout_seconds)` after `get_factory()` and handle `TimeoutException`.","message":"The SDK might return 'control' for treatments if it's not fully initialized or if a feature flag is not found. Always use `factory.block_until_ready()` with a timeout to ensure data is loaded before evaluation.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Upgrade Python to 3.7.16 or later if using `asyncio` features. Ensure `get_factory_async` is used for async initialization.","message":"Asynchronous (asyncio) support was introduced in v10.0.0 and requires Python 3.7.16 or later. Previous Python 3.x versions might experience issues with asyncio-specific functionalities.","severity":"breaking","affected_versions":">=10.0.0"},{"fix":"Remove `redisErrors` from your SDK configuration if present. Refer to `redis-py` documentation for equivalent error handling if needed.","message":"The configuration parameter `redisErrors` was deprecated in v10.5.0 as it was removed from the underlying `redis-py` library since v6.0.0.","severity":"deprecated","affected_versions":">=10.5.0"},{"fix":"Ensure `factory.destroy()` is called only during application shutdown. Do not use the client object after the factory has been destroyed.","message":"Using the client after calling `factory.destroy()` will result in 'Client has already been destroyed' errors, and all `getTreatment` calls will return 'control' or map of controls.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Upgrade to `splitio-client` v10.4.0 or later to correctly evaluate rule-based segments.","message":"Rule-based segments are only fully supported from SDK versions 10.4.0 and above. Older SDK versions will return the 'control' treatment for flags configured with rule-based segments and log a specific impression label.","severity":"gotcha","affected_versions":"<10.4.0"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"While `splitio-client` primarily supports Python 3.7+, if encountered in a constrained Python 2.7 environment, ensure `enum34` is version 1.1.5 or above: `pip install 'enum34>=1.1.5'`.","cause":"This error typically occurs in older Python 2.7 environments due to issues with the `enum34` dependency being an outdated version.","error":"TypeError: type() argument 1 must be string, not unicode"},{"fix":"Try `pip install splitio-client` without the `[cpphash]` extra, as the pure Python hashing implementation might work. Alternatively, update your Xcode Command Line Tools or try a different Python environment manager (like Conda) that provides its own compiler toolchain.","cause":"This is often due to an outdated or incompatible C++ compiler (g++) or issues with `libstdc++` on older macOS versions (e.g., Mojave) when building the `splitmmh3` dependency.","error":"pip install 'splitio-client[cpphash]' fails with 'command 'g++' failed with exit status 1' on macOS"},{"fix":"Provide a valid, non-empty SDK API key from your Split.io account. Ensure environment variables or configuration files are correctly populated.","cause":"The SDK was initialized with an empty or `None` API key string.","error":"factory instantiation: you passed an empty api_key, api_key must be a non-empty string."}]}