Set up Python SDK

Install and initialize the LaunchDarkly Python SDK to start evaluating feature flags in your application.

Install the package

pip
pip3 install launchdarkly-server-sdk

Initialize the SDK

Python SDK initialization
import os
import ldclient
from ldclient import Context
from ldclient.config import Config
if __name__ == '__main__':
# This is your LaunchDarkly SDK key.
# Never hardcode your SDK key in production.
ldclient.set_config(Config('YOUR_SDK_KEY'))
if not ldclient.get().is_initialized():
print('SDK failed to initialize')
exit()
# For onboarding purposes only we flush events as soon as
# possible so we quickly detect your connection.
# You don't have to do this in practice because events are automatically flushed.
ldclient.get().flush()
print('SDK successfully initialized')

You can find your server-side SDK keys, mobile keys, and client-side ID on the SDK keys page under Settings.

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