Registry / devops / launchdarkly-server-sdk

launchdarkly-server-sdk

JSON →
library9.16.1pypypi✓ verified 25d ago

The LaunchDarkly SDK for Python provides functionality to integrate feature flags into your Python applications. It enables developers to control feature rollouts, perform A/B testing, and manage configurations without redeploying code. The library is actively maintained with frequent minor and patch releases, typically every 1-2 months, to introduce new features, improvements, and bug fixes.

pip install launchdarkly-server-sdk
INSTALL
IMPORT
SIG · LAUNCHDARKLY-SERVE
L
launchdarkly-server-sdk
devopspythonv9.16.1
Install
2.1s avg
Import
390ms
Disk
20MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v9.16.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.400s · 21.4MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 2.1s · import 0.380s · 22MB
20MB installed
● package 20MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

LDClient
from ldclient import LDClient
from launchdarkly_server_sdk import LdClient
Config
from ldclient import Config
from launchdarkly_server_sdk import Config
Context
from ldclient import Context

This quickstart demonstrates how to initialize the LaunchDarkly client, define a user, evaluate a feature flag, and properly shut down the client. It uses an environment variable for the SDK key for security. In production, ensure the client is initialized and shut down gracefully with your application's lifecycle.

import os from launchdarkly_server_sdk import LdClient, Config # Replace with your actual SDK key from LaunchDarkly SDK_KEY = os.environ.get('LAUNCHDARKLY_SDK_KEY', 'YOUR_SDK_KEY_HERE') if not SDK_KEY or SDK_KEY == 'YOUR_SDK_KEY_HERE': print("Warning: LAUNCHDARKLY_SDK_KEY environment variable not set or default used. Client will be in offline mode.") # In a real application, you might raise an error or handle this differently. config = Config(offline=True) else: config = Config() # Initialize the LaunchDarkly client ld_client = LdClient(SDK_KEY, config) # Wait for the client to be initialized (recommended for server-side apps) if ld_client.is_initialized(): print("LaunchDarkly client initialized!") # Define a user for flag evaluation user = { "key": "example-user-key", "name": "Example User", "custom": { "group": "beta_testers" } } # Evaluate a feature flag flag_value = ld_client.variation("my-feature-flag", user, False) print(f"Feature flag 'my-feature-flag' is: {flag_value} for user {user['key']}") # Don't forget to shut down the client when your application exits ld_client.close() print("LaunchDarkly client closed.") else: print("LaunchDarkly client failed to initialize.") # Ensure the client is closed even if initialization fails ld_client.close()
Debug
Known issues
breakingPython 3.9 is no longer supported starting with version 9.15.0.
fix
Upgrade your Python environment to 3.10 or newer. If you must use Python 3.9, pin the SDK version to `<9.15.0` (e.g., `launchdarkly-server-sdk<9.15.0`).
affects: >=9.15.0
breakingPython 3.8 is no longer supported starting with version 9.12.0.
fix
Upgrade your Python environment to 3.9 or newer. If you must use Python 3.8, pin the SDK version to `<9.12.0` (e.g., `launchdarkly-server-sdk<9.12.0`).
affects: >=9.12.0
gotchaThe `ChangeSet` object in the file data source now strictly requires a `Selector` for updates.
fix
If you are using the file data source and directly manipulating `ChangeSet` objects, ensure that every change operation includes a valid `Selector` as specified in the updated API documentation.
affects: >=9.15.0
gotchaSDK key validation was added, which performs a basic format check on initialization. Providing an invalid SDK key format may lead to immediate client initialization failure.
fix
Always use a valid LaunchDarkly SDK key. Validate your SDK key format if you encounter unexpected client initialization issues on versions 9.12.1 or newer. An SDK key usually starts with 'sdk-'
affects: >=9.12.1
gotchaIt is crucial to call `ld_client.close()` when your application is shutting down to ensure all pending events are flushed and resources are released. Failing to do so can lead to lost analytics events or resource leaks.
fix
Integrate `ld_client.close()` into your application's shutdown process, for example, using a `finally` block or a signal handler in web frameworks.
affects: All versions
breakingThe 'launchdarkly-server-sdk' package could not be imported. This typically indicates the package is not installed in the Python environment, or the environment is misconfigured.
fix
Ensure the 'launchdarkly-server-sdk' package is installed in your Python environment. You can usually do this by running 'pip install launchdarkly-server-sdk'. If using a virtual environment, ensure it is activated before running your script.
affects: All versions
Upgrade
Version history
9.16.1latest on PyPI · released Jul 24, 2026
Audit
Dependencies
eventsourcerequiredUsed for streaming updates from the LaunchDarkly service.
Agent activity
10 hits · last 30 days
node
8
Resources