Registry / testing / growthbook

growthbook

JSON →
library3.0.0pypypi✓ verified 23d ago

GrowthBook is a Python SDK for powerful feature flagging and A/B testing in Python applications. It enables local evaluation of feature flags and experiments, flexible targeting, and integration with existing event tracking systems. The library is lightweight, fast, and supports both synchronous and asynchronous usage. As of version 2.2.0, it is actively maintained with frequent releases.

pip install growthbook
INSTALL
IMPORT
SIG · GROWTHBOOK
G
growthbook
testingpythonv3.0.0
Install
5.0s avg
Import
759ms
Disk
45MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v3.0.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.788s · 45.3MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 5.0s · import 0.730s · 47MB
45MB installed
● package 45MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

GrowthBook
from growthbook import GrowthBook
GrowthBookClient
from growthbook import GrowthBookClient
Recommended for async applications for improved performance and resource utilization.

This quickstart demonstrates how to initialize and use the `GrowthBookClient` for asynchronous applications, fetch feature flags, check feature status, retrieve feature values, and run A/B experiments. It uses environment variables for `client_key` and `api_host` for secure and flexible configuration. The `GrowthBookClient` is recommended for performance and resource utilization in async environments.

import asyncio import os from growthbook import GrowthBookClient, Options, UserContext, FeatureRefreshStrategy async def main(): # Get client key from environment variable for security client_key = os.environ.get("GROWTHBOOK_CLIENT_KEY", "sdk-YOUR_CLIENT_KEY") api_host = os.environ.get("GROWTHBOOK_API_HOST", "https://cdn.growthbook.io") # User attributes for targeting and experimentation attributes = { "id": "user-123", "country": "US", "loggedIn": True } # Configure GrowthBook client options options = Options( api_host=api_host, client_key=client_key, # Optional: Enable real-time feature updates via Server-Sent Events (SSE) refresh_strategy=FeatureRefreshStrategy.SERVER_SENT_EVENTS ) # Create a UserContext instance user_context = UserContext(attributes=attributes) # Create an async GrowthBookClient instance (recommended for async apps) async with GrowthBookClient(options=options, user_context=user_context) as gb: # Load features from the GrowthBook API await gb.load_features() # Simple on/off feature gating if gb.is_on("my-awesome-feature"): # Replace with your feature key print("My awesome feature is ON!") else: print("My awesome feature is OFF.") # Get the value of a feature with a fallback button_color = gb.get_feature_value("button-color-feature", "blue") # Replace with your feature key print(f"Button color feature value: {button_color}") # Example for an experiment # Make sure 'pricing-experiment' and variations are configured in GrowthBook pricing_result = gb.run( { "key": "pricing-experiment", "variations": ["control", "variant-a", "variant-b"] } ) if pricing_result.in_experiment: print(f"User in pricing experiment, assigned variation: {pricing_result.value}") else: print("User not in pricing experiment.") print("GrowthBook client closed.") if __name__ == "__main__": # Set dummy keys for local testing, replace with actual keys or environment variables os.environ["GROWTHBOOK_CLIENT_KEY"] = "sdk-example12345" os.environ["GROWTHBOOK_API_HOST"] = "https://cdn.growthbook.io" asyncio.run(main())
Debug
Known issues
breakingVersion 2.0.0 removed async tracking callback executions, enforcing synchronous execution for reliability. If you previously relied on async callbacks, you will need to adjust your implementation to handle tracking synchronously or implement your own async wrapper.
fix
Migrate `on_experiment_viewed` or `set_event_logger` callbacks to be synchronous, or wrap them with your own asynchronous handling mechanism if needed.
affects: >=2.0.0
gotchaIf 'Secure Attributes' are enabled in your GrowthBook SDK Connection, you must manually hash any `secureString` or `secureString[]` attributes using SHA-256 with your organization's secure attribute salt before passing them to the SDK.
fix
Hash sensitive attributes using `hashlib.sha256(attribute_value + secure_salt).hexdigest()` before including them in the `attributes` dictionary.
affects: All
gotchaTo analyze experiment results in the GrowthBook platform, you must provide an `on_experiment_viewed` callback (for `GrowthBook` class) or configure an event logger via `set_event_logger` (for `GrowthBook` or `GrowthBookClient` from v2.2.0+). Without this callback, feature flags will work, but experiment assignments will not be tracked.
fix
Implement and pass an `on_experiment_viewed` callable to the `GrowthBook` constructor or use `gb.set_event_logger` to record experiment view events to your analytics system.
affects: All
gotchaFor improved performance and better resource utilization, especially in async web applications (e.g., FastAPI, Django Async), the `GrowthBookClient` class is recommended over the synchronous `GrowthBook` class. It's designed to reuse a single client instance.
fix
Use `GrowthBookClient` and its `async with` context manager for async applications, and `await gb.load_features()` for fetching data.
affects: >=1.2.0
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'growthbook'
The 'growthbook' package is not installed in your Python environment.
fix
Run `pip install growthbook` to install the library.
Unknown feature
This warning indicates that the feature being evaluated is defined in the GrowthBook dashboard but is disabled in all environments, so it's not included in the SDK payload.
fix
Ensure the feature is enabled in at least one environment in your GrowthBook dashboard, or explicitly handle the 'unknown' state in your application logic. If you expect a default value, use `gb.get_feature_value('feature-key', 'default_value')`.
Failed to decode feature JSON from GrowthBook API
The GrowthBook SDK received an invalid or malformed JSON response when trying to fetch feature definitions from the API host.
fix
Verify that your `api_host` and `client_key` are correctly configured and that the GrowthBook API is accessible and returning valid JSON. Check for network issues or misconfigurations in your GrowthBook setup.
AttributeError: 'GrowthBook' object has no attribute 'initialize'
This error typically occurs when attempting to call an asynchronous method, like `initialize()`, on a synchronous `GrowthBook` instance, or conversely, using synchronous methods on `GrowthBookClient` without proper `await` calls. The `GrowthBook` class is for synchronous usage, while `GrowthBookClient` is for asynchronous usage.
fix
If using asynchronous code (e.g., with `asyncio`), ensure you are importing and instantiating `GrowthBookClient` and `await`ing its async methods (e.g., `await client.initialize()`). If using synchronous code, stick to the `GrowthBook` class and its synchronous methods (e.g., `gb.load_features()`).
Upgrade
Version history
3.0.0latest on PyPI · released Aug 26, 2026
Audit
Dependencies

No dependency data recorded yet.

Agent activity
9 hits · last 30 days
node
8
Resources
growthbook — pip install growthbook · libregistry