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 growthbookVerified import paths — ran on the pinned version, not inferred.
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.
Migrate `on_experiment_viewed` or `set_event_logger` callbacks to be synchronous, or wrap them with your own asynchronous handling mechanism if needed.
Hash sensitive attributes using `hashlib.sha256(attribute_value + secure_salt).hexdigest()` before including them in the `attributes` dictionary.
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.
Use `GrowthBookClient` and its `async with` context manager for async applications, and `await gb.load_features()` for fetching data.
Run `pip install growthbook` to install the library.
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')`.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.
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()`).
No dependency data recorded yet.