Set up Python SDK

LaunchDarkly onboarding is not available in federal environments
To learn more, read LaunchDarkly in federal environments.

Install the package

pip
$pip3 install launchdarkly-server-sdk

Initialize the SDK

Python SDK initialization
1import os
2import ldclient
3from ldclient import Context
4from ldclient.config import Config
5
6if __name__ == '__main__':
7 # This is your LaunchDarkly SDK key.
8 # Never hardcode your SDK key in production.
9 ldclient.set_config(Config('YOUR_SDK_KEY'))
10
11 if not ldclient.get().is_initialized():
12 print('SDK failed to initialize')
13 exit()
14
15 # For onboarding purposes only we flush events as soon as
16 # possible so we quickly detect your connection.
17 # You don't have to do this in practice because events are automatically flushed.
18 ldclient.get().flush()
19 print('SDK successfully initialized')

You can find your server-side SDK key, client-side ID, and mobile key in the “Resources” section of the help menu. Click the help icon at the bottom left corner of the LaunchDarkly UI, then choose SDK keys:

The SDK keys option in the help menu.

The SDK keys option in the help menu.

To learn more, read Initialize the client in the Python SDK reference guide.