Skip to content

Flagship's OpenFeature Provider ​

The Flagship Provider connects the generic OpenFeature API to the Flagship backend. This allows your application to fetch flag configurations and report evaluation data back to Flagship.

Installation ​

Install the Flagship provider package for your language:

sh
# npm
npm install @flagship/openfeature-provider

# yarn
yarn add @flagship/openfeature-provider

# pnpm
pnpm add @flagship/openfeature-provider

# bun
bun add @flagship/openfeature-provider
sh
pip install flagship-openfeature-provider
sh
go get github.com/with-flagship/flagship-go-provider
xml
<dependency>
  <groupId>com.withflagship</groupId>
  <artifactId>openfeature-provider</artifactId>
  <version>LATEST</version>
</dependency>

Configuration ​

Initialize the provider and set it as the global provider for OpenFeature.

typescript
import { OpenFeature } from '@openfeature/server-sdk';
import { FlagshipProvider } from '@flagship/openfeature-provider';

// Initialize the Flagship provider
const flagshipProvider = new FlagshipProvider({
  sdkKey: process.env.FLAGSHIP_SDK_KEY, // Get this from Flagship Settings > API Keys
  // Optional: Configure caching or other options here
});

// Set Flagship as the provider for OpenFeature
OpenFeature.setProvider(flagshipProvider);

console.log('Flagship OpenFeature Provider initialized!');
python
from openfeature import api
from flagship_openfeature_provider import FlagshipProvider
import os

# Initialize the Flagship provider
flagship_provider = FlagshipProvider(
    sdk_key=os.environ.get("FLAGSHIP_SDK_KEY")
)

# Set Flagship as the provider for OpenFeature
api.set_provider(flagship_provider)
go
import (
    "os"
    "github.com/open-feature/go-sdk/openfeature"
    "github.com/with-flagship/flagship-go-provider"
)

func main() {
    // Initialize the Flagship provider
    provider := flagship.NewProvider(os.Getenv("FLAGSHIP_SDK_KEY"))
    
    // Set Flagship as the provider for OpenFeature
    openfeature.SetProvider(provider)
}
java
import dev.openfeature.sdk.OpenFeatureAPI;
import com.withflagship.openfeature.FlagshipProvider;

// Initialize the Flagship provider
FlagshipProvider provider = new FlagshipProvider(System.getenv("FLAGSHIP_SDK_KEY"));

// Set Flagship as the provider for OpenFeature
OpenFeatureAPI.getInstance().setProvider(provider);

Usage Example ​

Once configured, you can evaluate flags anywhere in your application:

typescript
const client = OpenFeature.getClient();

// The AI detects this new key 'new-checkout-flow' in your PR
// Flagship automatically creates the flag if it doesn't exist
const isNewCheckoutEnabled = await client.getBooleanValue('new-checkout-flow', false, { 
    userId: user.id,
    // Add other context attributes for targeting rules
    email: user.email,
    plan: user.plan
});

if (isNewCheckoutEnabled) {
  return renderNewCheckout();
} else {
  return renderLegacyCheckout();
}
python
client = api.get_client()

# The AI detects this new key 'new-checkout-flow' in your PR
is_new_checkout_enabled = client.get_boolean_value(
    "new-checkout-flow", 
    False, 
    {
        "userId": user.id,
        "email": user.email,
        "plan": user.plan
    }
)

if is_new_checkout_enabled:
    return render_new_checkout()
else:
    return render_legacy_checkout()
go
client := openfeature.NewClient("app")

// The AI detects this new key 'new-checkout-flow' in your PR
evalCtx := openfeature.NewEvaluationContext(
    user.ID,
    map[string]interface{}{
        "email": user.Email,
        "plan":  user.Plan,
    },
)

isNewCheckoutEnabled, _ := client.BooleanValue(
    context.Background(), 
    "new-checkout-flow", 
    false, 
    evalCtx,
)

if isNewCheckoutEnabled {
    return renderNewCheckout()
} else {
    return renderLegacyCheckout()
}
java
Client client = OpenFeatureAPI.getInstance().getClient();

// The AI detects this new key 'new-checkout-flow' in your PR
MutableContext context = new MutableContext(user.getId());
context.add("email", user.getEmail());
context.add("plan", user.getPlan());

Boolean isNewCheckoutEnabled = client.getBooleanValue("new-checkout-flow", false, context);

if (isNewCheckoutEnabled) {
    return renderNewCheckout();
} else {
    return renderLegacyCheckout();
}