LaunchDarkly Developer Documentation

Get started in under 30 minutes.
LaunchDarkly provides feature flags as a service for Java · Python · Ruby · Go · Node.js · PHP · .NET. Control feature launches -- who sees what and when -- without multiple code deploys. Easy dashboard for phased rollouts, targeting and segmenting.
Need more help? write us at support@launchdarkly.com

Get Started    

Looking for LaunchDarkly's v1 docs?

You are currently viewing the docs for LaunchDarkly v2. If you are still using our v1 SDKs, then please see the v.1 documentation.

If you have any questions, feel free to email us support@launchdarkly.com

Setting up LaunchDarkly to control your first feature flag takes only a few minutes. First, add the SDK to your project:

<dependency>
  <groupId>com.launchdarkly</groupId>
  <artifactId>launchdarkly-client</artifactId>
  <version>2.3.1</version>
</dependency>
pip install ldclient-py
gem install ldclient-rb --prerelease

# Note: The --prerelease flag is there to satisfy the dependency of celluloid 0.18pre which we have tested extensively and have found stable in our use case. Unfortunately, the upstream provider has not promoted this version to stable yet. See here, https://github.com/celluloid/celluloid/issues/762. This is not required for use in a Gemfile.
go get gopkg.in/launchdarkly/go-client.v2
npm install ldclient-node --save
php composer.phar require launchdarkly/launchdarkly-php
Install-Package LaunchDarkly.Client
pod `LaunchDarkly`
compile 'com.launchdarkly:launchdarkly-android-client:2.0.5'

Now import the LaunchDarkly client in your application code:

import com.launchdarkly.client.*;
import ldclient
require 'ldclient-rb'
import ld "gopkg.in/launchdarkly/go-client.v2"
var LaunchDarkly = require('ldclient-node');
require 'vendor/autoload.php';
using LaunchDarkly.Client;
#import "LDClient.h"
import com.launchdarkly.android.LDClient;
import com.launchdarkly.android.LDConfig;
import com.launchdarkly.android.LDUser;

Next, configure the LaunchDarkly Client with your SDK or Mobile key and create the client.

LDClient ldClient = new LDClient(YOUR_SDK_KEY);
ldclient.set_sdk_key("YOUR_SDK_KEY")
ld_client = ldclient.get()
ld_client = LaunchDarkly::LDClient.new(YOUR_SDK_KEY)
ld_client := ld.MakeClient(YOUR_SDK_KEY, 5*time.Second)
ldclient = LaunchDarkly.init(YOUR_SDK_KEY)
$client = new LaunchDarkly\LDClient(YOUR_SDK_KEY);
LdClient ldClient = new LdClient("YOUR_SDK_KEY");
LDConfig *config = [[LDConfig alloc] initWithMobileKey: @"YOUR_MOBILE_KEY"];
LDConfig ldConfig = new LDConfig.Builder().setMobileKey("YOUR_MOBILE_KEY").build();

Finally, create a feature flag on your dashboard. When you create a flag, you specify a unique feature key-- you'll use this key in your application code to check which variation of a feature flag a user will receive by calling the variation method (or boolVariation in typed languages):

LDUser user = new LDUser("user@test.com");
boolean showFeature = ldClient.boolVariation("your.feature.key", user, false);
if (showFeature) {
  // application code to show the feature 
}
else {
  // the code to run if the feature is off
}
show_feature = ld_client.variation("your.flag.key", {"key": "user@test.com"}, False)
if show_feature:
    # application code to show the feature
else:
    # the code to run if the feature is off
show_feature = ld_client.variation("your.flag.key", {:key => "user@test.com"}, false)
if show_feature
    # application code to show the feature
else
    # the code to run if the feature is off
key := "user@test.com"
show_feature := ld_client.BoolVariation("your.flag.key", ld.User{Key: &key,}, false)
if (show_feature) {
    # application code to show the feature
} else {
    # the code to run if the feature is off 
}
ldclient.once('ready', function() {
    ldclient.variation("your.flag.key", {"key": "user@test.com"}, false,
     function(err, showFeature) {
        if (showFeature) {
          // application code to show the feature
        } else {
          // the code to run if the feature is off
        }
     });
});
$user = new LaunchDarkly\LDUser("user@test.com");
if ($client->variation("your.flag.key", $user)) {
    # application code to show the feature
} else {
    # the code to run if the feature is off
}
User user = User.WithKey(username);
bool showFeature = ldClient.BoolVariation("your.feature.key", user, false);
if (showFeature) {
  // application code to show the feature 
}
else {
  // the code to run if the feature is off
}
LDUserBuilder *user = [[LDUserBuilder alloc] init];
user.key = @"aa0ceb";

[[LDClient sharedInstance] start:config withUserBuilder:user];

BOOL showFeature = [[LDClient sharedInstance] boolVariation:@"YOUR_FLAG_KEY" fallback:NO];
if (showFeature) {
        NSLog(@"Showing feature for %@", user.key);
} else {
        NSLog(@"Not showing feature for user %@", user.key);
}
LDConfig ldConfig = new LDConfig.Builder()
        .setMobileKey("MOBILE_KEY")
        .build();

LDUser user = new LDUser.Builder("user key")
        .email("fake@example.com")
        .build();

LDClient client = LDClient.init(getApplication(), ldConfig, user, 5);

if (client.boolVariation(FLAG_KEY, false)) {
    Log.i(TAG, "Showing feature");
} else {
    Log.i(TAG, "Not Showing feature");
}

The second argument to variation is the user object. The only mandatory property is the user key-- this is what LaunchDarkly uses to identify each user. The key does need to be unique to each user-- a database key, an e-mail address, or a hash of an email address usually works.

Identifying users

You don't have to send users to LaunchDarkly in advance. Just set up your users in variation calls and you're all set.

However, if you want to pre-populate your dashboard with users, you can bulk import them via our REST API.

Once you're ready to test your integration, head over to the dev console to get a real-time view of your feature flag requests as they're received.

That's it! Now you can manage the feature on your dashboard-- read on to see how to target users or do controlled rollouts and A/B tests without re-deploying your application!

To see the advanced configuration options available for your platform's SDK, see the Reference guides section.

Setup