Dev GuideAPI Reference
Dev GuideAPI ReferenceUser GuideGitHubNuGetDev CommunityDoc feedbackLog In
GitHubNuGetDev CommunityDoc feedback
Hey! These docs are for version 2.0, which is no longer officially supported. Click here for the latest version, 3.0!

Instantiate a client



This topic doesn't apply to most mobile use cases. If you're using the iOS SDK or Android SDK, see Initialize a mobile SDK, which describes getting the datafile and instantiating a client.

Once you have a datafile, you can instantiate an Optimizely client. Any time you retrieve an updated datafile, just re-instantiate the same client.

For simple applications, all you need to provide to instantiate a client is a datafile specifying the project configuration for a given environment. For most advanced implementations, you'll want to customize the client for your specific requirements.

using OptimizelySDK;

// Instantiate an Optimizely client
Optimizely OptimizelyClient = new Optimizely(datafile);
import com.optimizely.ab.Optimizely;

// Instantiate an Optimizely client
Optimizely optimizelyClient = Optimizely.builder(datafile, eventHandler).build();
var optimizely = require('@optimizely/optimizely-sdk');

// Instantiate an Optimizely client
var optimizelyClientInstance = optimizely.createInstance({ datafile: datafile });

/* Alternatively, if you don't use CommonJS or npm, you can install
*  the minified snippet and use the globally exported variable as follows
var optimizelyClientInstance = window.optimizelyClient.createInstance({ datafile: datafile });
// Minimal client
const optimizely = require("@optimizely/optimizely-sdk");
const rp = require("request-promise");

// TODO: replace with your datafile URL
const datafile = await rp({ uri: DATAFILE_URL, json: true });
console.log("Datafile:", datafile);
var optimizelyClient = optimizely.createInstance({
// Use optimizelyClient to run experiments
use Optimizely\Optimizely;

// Instantiate an Optimizely client
$optimizelyClient = new Optimizely($datafile);
from optimizely import optimizely

# Instantiate an Optimizely client
optimizely_client = optimizely.Optimizely(datafile)
require "optimizely"

# Initialize an Optimizely client
optimizely_client =

There are several other optional parameters for configuring the Optimizely client. See the Customize an SDK and the API reference sections.