LaunchDarkly Developer Documentation

Get started in under 30 minutes.
Need more help? write us at

Get Started    Documentation

Python SDK Reference

This reference guide documents all of the methods available in our Python SDK, and explains in detail how these methods work. If you want to dig even deeper, our SDKs are open source-- head to our Python SDK GitHub repository to look under the hood.

Getting started

If you haven't taken a look at our Quickstart guide yet, we recommend starting there to see how install our SDK into your Python application.

Once the SDK is installed, you'll want to configure the LaunchDarkly client:

ldclient.sdk_key = "YOUR_SDK_KEY"

Customizing your client


ldclient.config = Config('', 1, 2)

The Config allows you to specify a custom base URL (you probably don't need to do this), as well as customize timeout parameters. In this example, we've set the connection timeout to LaunchDarkly to 1 second, and the read timeout to 2 seconds.


Feature flag targeting and rollouts are all determined by the user you pass to your Toggle calls. In our Python SDK, users are simply dictionaries. Here's an example:

user = {
  "key": "aa0ceb",
  "firstName": "Ernestina",
  "lastName": "Evans",
  "email": "",
  "custom": {
    "groups": ["Google", "Microsoft"]



Besides the key, LaunchDarkly supports the following attributes at the "top level". Remember, all of these are optional:

  • ip: Must be an IP address. If you provide an IP, LaunchDarkly will use a geolocation service to automatically infer a country for the user (unless you've already specified one).
  • firstName: Must be a string. If you provide a first name, you can search for users on the Users page by name.
  • lastName: Must be a string. If you provide a last name, you can search for users on the Users page by name.
  • country: Must be a string representing the country associated with the user.
  • email: Must be a string representing the user's e-mail address. If an avatar URL is not provided, we'll use Gravatar to try to display an avatar for the user on the Users page.
  • avatar: Must be an absolute URL to an avatar image for the user.
  • name: Must be a string. You can search for users on the User page by name
  • anonymous: Must be a boolean. See the section below on anonymous users for more details.

In addition to built-in attributes, you can pass us any of your own user data by passing custom attributes, like the groups attribute in the example above.

A note on types

Most of our built-in attributes (like names and e-mail addresses) expect string values. Custom attribute values can be strings, booleans (like True or False), numbers, or lists of strings, booleans or numbers.



Anonymous users


user = {"key":"aa0ceb", "anonymous": True}




The variation method determines the feature flag value for a specific user.

ldclient.get().variation("your.feature.key", user, False)

toggle calls take the feature flag key, a user, and a default value. variation works by running through the targeting rules first. If a user is specifically included or excluded according to the targeting rules, variation will return True or False accordingly. If none of the targeting rules match, variation will determine whether the user falls into the percent rollout.

The default value will only be returned if the kill switch has been triggered or an error is encountered-- for example, if the feature flag key doesn't exist or the user doesn't have a key specified.




ldclient.get().track("Signed up", user)

You can also attach an extra dictionary containing arbitrary data to your event:

ldclient.get().track("Completed purchase", {"price": 320})


The identify method creates or updates users on LaunchDarkly, making them available for targeting and autocomplete on the dashboard. In most cases, you won't need to call identify-- the toggle call will automatically create users on the dashboard for you. identify can be useful if you want to pre-populate your dashboard before launching any features.


Offline mode


# Initialization:
ldclient.config = Config(offline = True)
ldclient.sdk_key = "YOUR_SDK_KEY"

ldclient.get().variation("any.feature.flag", user, False) # will always return the default value (false)




Note that the flush interval is configurable-- if you need to change the interval, you can do so when configuring your client instance.

Configuring uWSGI

The LaunchDarkly SDK is compatible with uWSGI. However, in uWSGI environments, the SDK requires the enable-threads option to be set.

Python SDK Reference

Suggested Edits are limited on API Reference Pages
