SDK Quickstart
Get GrowthBook running in your application in minutes.
The SDK Overview covers how SDKs work and helps you choose the right one for your use case.
- React
- JavaScript
- Node.js
- Python
- 22+ More SDKs
Get your SDK Client Key
Go to SDK Configuration, create a new SDK Connection, and copy the Client Key (starts with sdk-).
Install the SDK
- npm
- Yarn
- pnpm
- Bun
npm install @growthbook/growthbook-react @growthbook/growthbook
yarn add @growthbook/growthbook-react @growthbook/growthbook
pnpm add @growthbook/growthbook-react @growthbook/growthbook
bun add @growthbook/growthbook-react @growthbook/growthbook
Wrap your app with GrowthBookProvider
import { GrowthBook, GrowthBookProvider } from "@growthbook/growthbook-react";
import { thirdPartyTrackingPlugin, autoAttributesPlugin } from "@growthbook/growthbook/plugins";
// Create a GrowthBook instance
const gb = new GrowthBook({
apiHost: "https://cdn.growthbook.io",
clientKey: "sdk-abc123", // Your SDK client key
enableDevMode: true,
plugins: [
thirdPartyTrackingPlugin(), // Optional, sends "Experiment Viewed" events via GrowthBook Managed Warehouse, Google Analytics, Google Tag Manager, and Segment.
autoAttributesPlugin(), // Optional, sets common attributes (browser, session_id, etc.)
],
});
// Load feature definitions from the GrowthBook API
gb.init();
export default function App() {
return (
<GrowthBookProvider growthbook={gb}>
<MyApp />
</GrowthBookProvider>
);
}
Use feature flags
import { useFeatureIsOn, useFeatureValue } from "@growthbook/growthbook-react";
function MyApp() {
const showNewFeature = useFeatureIsOn("new-feature");
const buttonColor = useFeatureValue("button-color", "blue");
return (
<div>
{showNewFeature && <NewFeature />}
<button style={{ backgroundColor: buttonColor }}>Click me</button>
</div>
);
}
Next steps: - See the example Next.js app - See the React SDK docs
Get your SDK Client Key
Go to SDK Configuration, create a new SDK Connection, and copy the Client Key (starts with sdk-).
Install the SDK
- npm
- Yarn
- pnpm
- Bun
npm install @growthbook/growthbook
yarn add @growthbook/growthbook
pnpm add @growthbook/growthbook
bun add @growthbook/growthbook
Initialize GrowthBook
import { GrowthBook } from "@growthbook/growthbook";
import { thirdPartyTrackingPlugin, autoAttributesPlugin } from "@growthbook/growthbook/plugins";
const gb = new GrowthBook({
apiHost: "https://cdn.growthbook.io",
clientKey: "sdk-abc123",
plugins: [
thirdPartyTrackingPlugin(), // Optional, sends "Experiment Viewed" events via GrowthBook Managed Warehouse, Google Analytics, Google Tag Manager, and Segment.
autoAttributesPlugin(), // Optional, sets common attributes (browser, session_id, etc.)
],
});
await gb.init();
Use feature flags
if (gb.isOn("new-feature")) {
showNewFeature();
}
const color = gb.getFeatureValue("button-color", "blue");
Next steps: - See the JavaScript SDK docs for TypeScript, plugins, and more. - See an example Typescript app
Get your SDK Client Key
Go to SDK Configuration, create a new SDK Connection, and copy the Client Key (starts with sdk-).
Install the SDK
- npm
- Yarn
- pnpm
- Bun
npm install @growthbook/growthbook
yarn add @growthbook/growthbook
pnpm add @growthbook/growthbook
bun add @growthbook/growthbook
Initialize GrowthBook
import { GrowthBookClient } from "@growthbook/growthbook";
const gbClient = new GrowthBookClient({
apiHost: "https://cdn.growthbook.io",
clientKey: "sdk-abc123",
trackingCallback: (experiment, result, userContext) => {
const userId = userContext.attributes.id;
// Required for A/B testing
// TODO: Replace with your own tracking implementation
console.log("Viewed Experiment", userId, {
experimentId: experiment.key,
variationId: result.key
});
}
});
await gbClient.init({timeout: 3000});
Use feature flags
// User context with attributes that feature flags can use for targeting
const userContext = {
attributes: {
id: "123",
country: "US",
// ... other attributes ...
}
}
// Boolean on/off flags
if (gbClient.isOn("my-feature", userContext)) {
console.log("My feature is on!");
}
// String, Number, or JSON flags
const value = gbClient.getFeatureValue("my-string-feature", "fallback", userContext);
console.log(value);
Next steps: - See the full Node.js SDK docs - Use the SDK in Express middleware
Get your SDK Client Key
Go to SDK Configuration, create a new SDK Connection, and copy the Client Key (starts with sdk-).
Install the SDK
pip install growthbook
Initialize GrowthBook
from growthbook import GrowthBookClient, Options, UserContext
def on_experiment_viewed(experiment, result):
# TODO: track in your analytics system
print(f"Experiment: {experiment.key}, Variation: {result.key}")
# Create and initialize client
client = GrowthBookClient(
Options(
api_host="https://cdn.growthbook.io",
client_key="sdk-abc123",
on_experiment_viewed=on_experiment_viewed,
)
)
await client.initialize()
# Create user context for targeting
user = UserContext(
attributes={
"id": "user-123",
"country": "US",
}
)
Use feature flags
if await client.is_on("new-feature", user):
show_new_feature()
color = await client.get_feature_value("button-color", "blue", user)
Next steps: - See the full Python SDK docs - See the how to integrate with FastAPI example.
Verify your setup
After setting up your SDK, verify it's working by following these steps:
- Create a feature flag called
test-flagin your GrowthBook - Set its value to
trueand enable it for your environment - Check that
isOn("test-flag")returnstruein your app - Toggle the flag off and verify the change is reflected
Use the GrowthBook DevTools browser extension to inspect and test feature flags in development.