{"id":4313,"library":"unleashclient","title":"Unleash Python Client SDK","description":"The Unleash Python Client SDK is a server-side client for the Unleash feature management platform, enabling developers to integrate and evaluate feature flags within their Python applications. It connects to an Unleash server (Enterprise or Open Source) to fetch flag configurations and evaluate them locally against an Unleash context. Currently at version 6.7.0, the library maintains an active release cadence with frequent updates and bug fixes.","status":"active","version":"6.7.0","language":"en","source_language":"en","source_url":"https://github.com/Unleash/unleash-python-sdk","tags":["feature-flags","unleash","feature-toggle","configuration","sdk"],"install":[{"cmd":"pip install UnleashClient","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"Used for scheduling background tasks like fetching feature flags and sending metrics.","package":"apscheduler","optional":false},{"reason":"HTTP client for communicating with the Unleash server.","package":"requests","optional":false},{"reason":"The core evaluation engine for feature flag strategies and constraints.","package":"yggdrasil-engine","optional":false},{"reason":"Used for semantic versioning comparisons in constraints.","package":"semver","optional":false}],"imports":[{"note":"The primary class is directly importable from the top-level package. Avoid `import UnleashClient` and then `UnleashClient.UnleashClient()`.","wrong":"import UnleashClient","symbol":"UnleashClient","correct":"from UnleashClient import UnleashClient"}],"quickstart":{"code":"import os\nfrom UnleashClient import UnleashClient\n\nUNLEASH_URL = os.environ.get('UNLEASH_API_URL', 'http://localhost:4242/api')\nUNLEASH_APP_NAME = os.environ.get('UNLEASH_APP_NAME', 'my-python-app')\nUNLEASH_INSTANCE_ID = os.environ.get('UNLEASH_INSTANCE_ID', 'instance-1')\nUNLEASH_API_TOKEN = os.environ.get('UNLEASH_API_TOKEN', 'YOUR_API_TOKEN_HERE') # Typically a server-side token\n\n# Initialize the client\nclient = UnleashClient(\n    url=UNLEASH_URL,\n    app_name=UNLEASH_APP_NAME,\n    instance_id=UNLEASH_INSTANCE_ID,\n    custom_headers={'Authorization': UNLEASH_API_TOKEN}\n)\n\n# Start the client (connects to Unleash server, fetches flags, etc.)\nclient.initialize_client()\n\n# Check if a feature is enabled\nenabled = client.is_enabled(\"my_feature_flag\")\nprint(f\"Feature 'my_feature_flag' is enabled: {enabled}\")\n\n# Check with context\nuser_context = {\n    \"userId\": \"123\",\n    \"sessionId\": \"abc\",\n    \"properties\": {\"region\": \"us-east\"}\n}\nenabled_for_user = client.is_enabled(\"user_specific_feature\", user_context)\nprint(f\"Feature 'user_specific_feature' is enabled for user 123: {enabled_for_user}\")\n\n# Get a variant\nvariant = client.get_variant(\"variant_toggle\", user_context)\nprint(f\"Variant for 'variant_toggle': {variant}\")\n\n# Gracefully shut down the client when no longer needed\nclient.destroy()","lang":"python","description":"This quickstart demonstrates how to initialize the Unleash client, connect to an Unleash server, and evaluate feature flags. It includes examples for checking simple boolean flags, using context for targeted evaluations, and retrieving feature variants. Remember to replace placeholder URLs and API tokens with your actual Unleash server details, ideally through environment variables. The `initialize_client()` method starts background synchronization, and `destroy()` gracefully shuts it down."},"warnings":[{"fix":"Instead of `client.features`, use `client.feature_definitions()` which returns a dictionary of feature flag names, types, and projects. If you relied on the internal structure of feature flag objects, you'll need to refactor your code.","message":"Direct access to `UnleashClient.features` was removed in v6.0.0. The internal representation of feature flags is no longer publicly accessible.","severity":"breaking","affected_versions":">=6.0.0"},{"fix":"Refactor custom strategy classes to remove inheritance from `Strategy` and update the `apply` method signature. The `load_provisioning()` method functionality is now handled directly within the `apply` method using the `parameters` argument. Strategies must be registered as instances, not class objects.","message":"Custom activation strategies require an updated interface in v6.0.0. They no longer inherit from a base class, and the `apply` method's signature changed to `apply(self, parameters: dict, context: dict = None) -> bool`.","severity":"breaking","affected_versions":">=6.0.0"},{"fix":"While still functional, it's recommended to rely on a `fallback_function` for more robust default behavior when a feature flag is not found or cannot be evaluated, especially in resilient applications. If both `default_value` and `fallback_function` are provided, the client will `OR` their results.","message":"The `default_value` argument in the `is_enabled()` method was deprecated in v4.0.0.","severity":"deprecated","affected_versions":">=4.0.0"},{"fix":"To prevent this, consider bootstrapping the client with a local or remote toggle configuration using a `FileCache` (or custom `BaseCache` implementation) and passing it during `UnleashClient` initialization. Alternatively, ensure your application handles the `False` state gracefully during the initial sync period.","message":"Upon initialization, feature flags will evaluate to `False` until the client has successfully synchronized with the Unleash API. This can lead to unexpected behavior during application startup.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure `client.initialize_client()` and `client.destroy()` are called correctly within each worker process's lifecycle (e.g., in a `post_fork` hook for Gunicorn). Refer to the official documentation for specific guidance on running in multi-process setups to prevent issues with thread management and data consistency.","message":"The SDK runs a background thread for fetching feature flags and sending metrics. This requires special consideration in multi-process environments like WSGI servers (e.g., Gunicorn, uWSGI) or Celery workers.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}