Skip to content

cloudflare/flagship

Repository files navigation

Cloudflare Flagship

npm version PyPI version Go Reference license

Flagship is Cloudflare's feature flag platform. This repository contains the official Flagship SDKs for application developers who want to evaluate feature flags through OpenFeature.

The TypeScript SDK is recommended for most use cases. It supports HTTP evaluation, browser-side caching, and the native Flagship Workers binding — which skips HTTP entirely and requires no auth token configuration. If you are building on Cloudflare Workers, use the TypeScript SDK with the Workers binding. The Python and Go SDKs are available for server-side applications and support HTTP evaluation only.

SDKs

SDK Package Runtime Evaluation modes Docs
TypeScript @cloudflare/flagship Node.js, Cloudflare Workers, browsers Workers binding, HTTP, browser prefetch cache sdks/typescript
Python cloudflare-flagship Python server applications HTTP sdks/python
Go github.com/cloudflare/flagship/sdks/go Go server applications HTTP sdks/go

TypeScript

Install the SDK with the OpenFeature package for your runtime:

npm install @cloudflare/flagship @openfeature/server-sdk

Cloudflare Workers should use the Flagship binding when possible. It avoids HTTP overhead and does not require application-managed auth tokens.

import { OpenFeature } from '@openfeature/server-sdk';
import { FlagshipServerProvider, type FlagshipBinding } from '@cloudflare/flagship/server';

export default {
	async fetch(request: Request, env: { FLAGS: FlagshipBinding }) {
		await OpenFeature.setProviderAndWait(new FlagshipServerProvider({ binding: env.FLAGS }));

		const client = OpenFeature.getClient();
		const enabled = await client.getBooleanValue('dark-mode', false, {
			targetingKey: 'user-123',
		});

		return Response.json({ enabled });
	},
};

For Node.js or other server environments, use HTTP mode:

import { OpenFeature } from '@openfeature/server-sdk';
import { FlagshipServerProvider } from '@cloudflare/flagship/server';

await OpenFeature.setProviderAndWait(
	new FlagshipServerProvider({
		appId: 'your-app-id',
		accountId: 'your-account-id',
		authToken: 'your-token',
	}),
);

const client = OpenFeature.getClient();
const enabled = await client.getBooleanValue('dark-mode', false, {
	targetingKey: 'user-123',
	plan: 'premium',
});

Python

Install with uv or pip:

uv add cloudflare-flagship
# or
pip install cloudflare-flagship
from openfeature import api
from openfeature.evaluation_context import EvaluationContext
from flagship import FlagshipServerProvider

api.set_provider(
	FlagshipServerProvider(
		app_id='your-app-id',
		account_id='your-account-id',
		auth_token='your-token',
	)
)

client = api.get_client()
enabled = client.get_boolean_value(
	'dark-mode',
	False,
	EvaluationContext(targeting_key='user-123', attributes={'plan': 'premium'}),
)

The Python SDK supports HTTP evaluation only.

Go

Install with go get:

go get github.com/cloudflare/flagship/sdks/go
package main

import (
	"context"

	flagship "github.com/cloudflare/flagship/sdks/go"
	"github.com/open-feature/go-sdk/openfeature"
)

func main() {
	provider, err := flagship.NewProvider(flagship.Options{
		AppID:     "your-app-id",
		AccountID: "your-account-id",
		AuthToken: "your-token",
	})
	if err != nil {
		panic(err)
	}

	if err := openfeature.SetProviderAndWait(provider); err != nil {
		panic(err)
	}
	defer openfeature.Shutdown()

	client := openfeature.NewDefaultClient()
	enabled, err := client.BooleanValue(
		context.Background(),
		"dark-mode",
		false,
		openfeature.NewEvaluationContext("user-123", map[string]any{"plan": "premium"}),
	)
	if err != nil {
		panic(err)
	}
	_ = enabled
}

The Go SDK supports HTTP evaluation only.

Repository Layout

Path Description
sdks/typescript TypeScript SDK source, tests, examples, and package metadata
sdks/python Python SDK source, tests, examples, and package metadata
sdks/go Go SDK source, tests, examples, and module metadata
.changeset Release intent files and Changesets configuration
.github/workflows Pull request checks and publish workflows

Development

This is a pnpm monorepo. Node.js 22+ and pnpm 10+ are required.

pnpm install
pnpm run check

Links

License

Apache-2.0

About

OpenFeature compliant provider for Cloudflare's low-latency feature flag platform.

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

48 stars

Watchers

0 watching

Forks

Contributors