{"id":9654,"library":"devcycle-python-server-sdk","title":"DevCycle Python Server SDK","description":"The DevCycle Python Server SDK provides real-time feature flag delivery and experimentation capabilities for Python applications. It allows developers to define, manage, and evaluate feature flags and A/B tests to deliver personalized experiences. The SDK fetches configurations, evaluates variables, and tracks events. The current version is 3.13.7, with frequent releases addressing bug fixes and minor feature enhancements.","status":"active","version":"3.13.7","language":"en","source_language":"en","source_url":"https://github.com/devcycleHQ/python-server-sdk","tags":["feature flags","experimentation","devops","sdk","asyncio","server-side"],"install":[{"cmd":"pip install devcycle-python-server-sdk","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"Used for OpenFeature integration and standardizing feature flag evaluation interfaces. Required for functionality.","package":"openfeature-sdk","optional":false}],"imports":[{"symbol":"DevCycleClient","correct":"from devcycle_python_sdk import DevCycleClient"},{"symbol":"DevCycleOptions","correct":"from devcycle_python_sdk import DevCycleOptions"},{"symbol":"DevCycleUser","correct":"from devcycle_python_sdk import DevCycleUser"},{"note":"Required for local bucketing (WASM) mode, instead of cloud bucketing.","symbol":"DevCycleLocalBucketingOptions","correct":"from devcycle_python_sdk import DevCycleLocalBucketingOptions"}],"quickstart":{"code":"import os\nimport asyncio\nfrom devcycle_python_sdk import DevCycleClient, DevCycleOptions, DevCycleUser\n\nDEVCYCLE_SERVER_SDK_KEY = os.environ.get('DEVCYCLE_SERVER_SDK_KEY', '')\n\nasync def main():\n    if not DEVCYCLE_SERVER_SDK_KEY:\n        print(\"Error: DEVCYCLE_SERVER_SDK_KEY environment variable not set.\")\n        return\n\n    # Configure options, e.g., enable cloud bucketing for server-side evaluation\n    # By default, local bucketing (WASM) is used if not specified\n    options = DevCycleOptions(enable_cloud_bucketing=True)\n    client = DevCycleClient(DEVCYCLE_SERVER_SDK_KEY, options)\n\n    try:\n        # Wait for the client to be initialized and fetch configurations\n        await client.on_initialized()\n        print(\"DevCycle client initialized.\")\n\n        # Define a user for feature evaluation\n        user = DevCycleUser(\n            user_id=\"example-user\",\n            email=\"test@example.com\",\n            country=\"US\"\n        )\n\n        # Evaluate a boolean variable\n        feature_enabled = await client.variable(user, \"my-feature\", False)\n        if feature_enabled.value:\n            print(\"Feature 'my-feature' is ON for the user.\")\n        else:\n            print(\"Feature 'my-feature' is OFF for the user.\")\n\n        # Evaluate a string variable\n        welcome_message = await client.variable(user, \"welcome-text\", \"Hello!\")\n        print(f\"Welcome message for user: {welcome_message.value}\")\n\n    except Exception as e:\n        print(f\"An error occurred during DevCycle operations: {e}\")\n    finally:\n        # Ensure the client is closed to release resources\n        await client.close()\n        print(\"DevCycle client closed.\")\n\nif __name__ == '__main__':\n    asyncio.run(main())\n","lang":"python","description":"Initializes the DevCycle client, waits for it to fetch configurations, defines a user, and evaluates a boolean and a string variable. It uses an environment variable for the SDK key and demonstrates asynchronous usage, which is mandatory for this SDK."},"warnings":[{"fix":"Migrate existing code to use `DevCycleClient` and adapt to the `async`/`await` pattern. Ensure all SDK operations are awaited and handled within an `asyncio` event loop. Consult the official v3 migration guide if available or the latest README.","message":"Version 3.0.0 introduced significant breaking changes, including a complete rewrite of the SDK. The `DevCycle` class was replaced with `DevCycleClient`, and the SDK shifted to an asynchronous (`asyncio`) programming model. Method signatures for initialization and variable evaluation changed substantially.","severity":"breaking","affected_versions":"<3.0.0 to 3.0.0+"},{"fix":"Always `await` calls to `client.on_initialized()`, `client.variable()`, `client.close()`, and other asynchronous methods. Ensure your application's entry point correctly uses `asyncio.run()` or manages the event loop for SDK operations.","message":"The SDK is built on `asyncio`. Attempting to use `DevCycleClient` methods without `await` or outside a running `asyncio` event loop will lead to `RuntimeError` or unexpected behavior (e.g., tasks not completing).","severity":"gotcha","affected_versions":"3.0.0+"},{"fix":"Double-check that your `DEVCYCLE_SERVER_SDK_KEY` is valid, has the correct permissions (server-side, not client-side), and is passed correctly during `DevCycleClient` initialization. Monitor application logs for HTTP 401/403 errors from the DevCycle API that indicate an invalid key.","message":"Incorrect or expired DevCycle Server SDK keys can lead to the SDK failing to fetch configurations or stopping polling for updates. This often results in default variable values being used or evaluation errors, without clear immediate indication in variable calls.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Explicitly set `enable_cloud_bucketing` in `DevCycleOptions` based on your requirements. For optimal performance and offline capabilities, set `enable_cloud_bucketing=False` and consider `DevCycleLocalBucketingOptions`. For simpler server-side integration that relies on DevCycle's cloud, set `enable_cloud_bucketing=True`.","message":"The SDK offers both local bucketing (WASM) and cloud bucketing modes, controlled by `DevCycleOptions`. The default behavior for `enable_cloud_bucketing` can affect performance, network usage, and consistency if not explicitly configured.","severity":"gotcha","affected_versions":"3.0.0+"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"Ensure you `await client.on_initialized()` before making any calls to `client.variable()` or other evaluation methods. Handle potential exceptions during initialization.","cause":"Attempting to evaluate variables or perform other operations before the SDK has finished its asynchronous initialization process (fetching initial configurations).","error":"RuntimeError: DevCycleClient not initialized."},{"fix":"Refactor your code to use `DevCycleClient` and its `async` methods. For example, replace `client.variable()` with `await client.variable()` on the new `DevCycleClient` instance.","cause":"This error often occurs when upgrading from pre-v3.0.0 SDK versions without updating client initialization and method calls. The `DevCycle` class no longer exists; it's `DevCycleClient`.","error":"AttributeError: 'DevCycle' object has no attribute 'variable'"},{"fix":"Ensure `await client.close()` is called before your application's `asyncio` event loop terminates. This cleans up internal resources and prevents warnings related to unclosed connections.","cause":"This warning, often accompanied by `ResourceWarning: unclosed client session`, indicates that SDK resources (like HTTP sessions or background tasks) were not properly shut down before the application exited.","error":"RuntimeWarning: Enable tracemalloc to get the object allocation traceback"},{"fix":"Only `await` specific asynchronous methods of the `DevCycleClient` object, such as `await client.on_initialized()` or `await client.variable(user, 'key', default_value)`.","cause":"This occurs when you try to `await` the `DevCycleClient` instance itself, rather than one of its asynchronous methods (e.g., `on_initialized()`, `variable()`, `close()`).","error":"TypeError: object DevCycleClient can't be used in 'await' expression"}]}