Skip to main content

Quickstart

The Eppo Java SDK enables feature flags and experiments in your Java applications with only a few lines of code.

Installation

You can install the SDK using Gradle or Maven:

implementation 'cloud.eppo:eppo-server-sdk:5.0.0'

Feature Flags

Initialize the SDK

Create an SDK key if you don't already have one.

Initialize the SDK with your key:

EppoClient eppoClient = EppoClient.builder(sdkKey).buildAndInit();

Assign a variant

After initialization, you can access the client with EppoClient.getInstance(). The SDK supports different types of assignments:

String assignedVariation = eppoClient.getStringAssignment(
"flagKey",
"subjectKey",
"defaultValue"
);

// With subject attributes
Attributes subjectAttributes = new Attributes(
Map.of(
"country", EppoValue.valueOf("FR"),
"age", EppoValue.valueOf(60)
)
);

String assignedVariation = eppoClient.getStringAssignment(
"flagKey",
"subjectKey",
subjectAttributes,
"defaultValue"
);

Assignment Types

The SDK provides different assignment functions based on the type of value you need:

FunctionReturn Type
getStringAssignment()String
getBooleanAssignment()Boolean
getJSONAssignment()JSON object
getIntegerAssignment()Integer
getDoubleAssignment()Double

Experiments

For experiments, you'll need to add an assignment logger (see AssignmentLogger) when initializing the SDK:

EppoClient.builder(sdkKey)
.assignmentLogger(assignmentLogData -> {
// TODO: Send assignment event data to data warehouse
System.out.println(assignmentLogData);
})
.buildAndInit();

After that, you can make assignments the same way as with feature flags.

Contextual Bandits

For bandits, you'll need both an assignment logger and a bandit logger:

EppoClient.builder(sdkKey)
.assignmentLogger(assignmentLogData -> {
// TODO: Send assignment event data to data warehouse
System.out.println(assignmentLogData);
})
.banditLogger(banditLogData -> {
// TODO: Send bandit event data to data warehouse
System.out.println(banditLogData);
})
.buildAndInit();

Query the bandit for actions

String flagKey = "shoe-bandit";
String subjectKey = "user123";
DiscriminableAttributes subjectAttributes = new Attributes(
Map.of(
"age", EppoValue.valueOf(25),
"country", EppoValue.valueOf("BG")
)
);

Actions actions = new BanditActions(
Map.of(
"nike",
new Attributes(
Map.of(
"brandAffinity", EppoValue.valueOf(2.3),
"previouslyPurchased", EppoValue.valueOf(true)
)
),
"adidas",
new Attributes(
Map.of(
"brandAffinity", EppoValue.valueOf(0.2),
"previouslyPurchased", EppoValue.valueOf(false)
)
)
)
);

String defaultValue = "control";

BanditResult banditResult = eppoClient.getBanditAction(
flagKey,
subjectKey,
subjectAttributes,
actions,
defaultValue
);

if (banditResult.getAction() != null) {
renderShoeAd(banditResult.getAction());
} else {
renderDefaultShoeAd();
}