Sync metrics and fact tables to GrowthBook
Project description
gbsync
Sync artifacts to GrowthBook using a version-controlled YAML configuration. gbsync manages your experiment infrastructure as code, enabling reproducible deployments and safe collaboration.
Currently supports:
- Fact Tables
- Fact Table Filters
- Fact Metrics
- Environments
Features
- Infrastructure as Code: Define growthbook artifacts in YAML so that it can be version controlled
- Dry-Run Planning: See what will change before applying
- Safe Syncing: Automatic conflict detection and validation
- API-Managed Resources: Mark resources to prevent manual UI edits
- External File Includes: Organize SQL in separate files
Installation
From PyPI
pip install gbsync
From Source
git clone https://github.com/growthbook/gbsync.git
cd gbsync
pip install -e .
Requirements
- Python 3.12 or higher
- GrowthBook account with API access
Quick Start
1. Get Your API Credentials
- Log into GrowthBook
- Go to Settings → API Keys
- Create a new API key (or copy existing)
- Note the API URL (e.g.,
https://api.growthbook.io)
2. Set Environment Variables
export GB_API_KEY="your_api_key"
export GB_API_URL="https://api.growthbook.io"
3. Create Configuration
Copy the example configuration:
cp examples/gbsync.yaml gbsync.yaml
Edit gbsync.yaml with your datasource ID, SQL, and metrics:
factTables:
- id: fact_events
data:
name: Events
datasource: ds_YOUR_DATASOURCE_ID
userIdTypes: [user_id]
sql: !include fact_tables/events.sql
factMetrics:
- id: metric_conversion_rate
data:
name: Conversion Rate
metricType: ratio
numerator:
factTableId: fact_events
column: conversions
denominator:
factTableId: fact_events
column: total_events
4. Plan Changes
See what will be created/updated/deleted:
gbsync plan
Output:
GrowthBook: Planning changes...
Tables:
✓ Create: Events
Metrics:
✓ Create: Conversion Rate
Ready to apply 2 changes
5. Apply Changes
gbsync apply
Output:
GrowthBook: Planning changes...
Tables:
✓ Create: Events
Metrics:
✓ Create: Conversion Rate
Ready to apply 2 changes
Proceed with apply? [y/N]: y
✓ Applied successfully
Commands
plan
Preview changes without applying them.
gbsync plan [OPTIONS]
Options:
--config, -c: Path to configuration file (default:gbsync.yaml)--api-key: GrowthBook API key (orGB_API_KEYenv var)--api-url: GrowthBook API URL (orGB_API_URLenv var)
Example:
gbsync plan --config ./metrics/prod.yaml
gbsync plan --api-key "sdk-abc123..."
apply
Apply changes to GrowthBook.
gbsync apply [OPTIONS]
Options:
--config, -c: Path to configuration file (default:gbsync.yaml)--api-key: GrowthBook API key (orGB_API_KEYenv var)--api-url: GrowthBook API URL (orGB_API_URLenv var)--auto-approve: Skip confirmation prompt (use with caution)
Example:
gbsync apply
gbsync apply --auto-approve # Dangerous: skips confirmation
Configuration
Basic Structure
projects:
- id: proj_analytics
data:
name: Analytics
description: Analytics project
factTables:
- id: fact_table_id
data:
name: Table Name
datasource: ds_123
userIdTypes: [user_id]
sql: SELECT ... FROM ...
factTableFilters:
- id: filter_id
factTableId: fact_table_id
data:
name: Filter Name
value: "WHERE clause"
factMetrics:
- id: metric_id
data:
name: Metric Name
metricType: ratio
numerator:
factTableId: fact_table_id
column: column_name
Key Concepts
Fact Tables: SQL queries that define event data
factTables:
- id: fact_events
data:
name: Events
datasource: ds_abc123
userIdTypes: [user_id, anonymous_id]
sql: |
SELECT
user_id,
anonymous_id,
event_date,
event_type
FROM events
WHERE event_date >= '{{ startDate }}'
AND event_date < '{{ endDate }}'
Filters: Reusable WHERE clause conditions
factTableFilters:
- id: filter_production
factTableId: fact_events
data:
name: Production Only
value: "environment = 'production'"
Metrics: Aggregations computed from fact tables
factMetrics:
- id: metric_conversion_rate
data:
name: Conversion Rate
metricType: ratio
numerator:
factTableId: fact_conversions
column: conversions
filters: [filter_production]
denominator:
factTableId: fact_events
column: null
filters: [filter_production]
Metric Types:
proportion: Numerator / total eventsratio: Numerator / denominatormean: Average of column valuesquantile: Percentile valuedailyParticipation: Daily participation rate
See docs/CONFIG.md for complete schema reference.
API-Managed Resources:
Mark resources with managedBy: api to allow deletion:
factTables:
- id: fact_events
data:
managedBy: api
# ... other fields
Resources created by the API get managedBy: "api". Manual resources (created in UI) are never deleted, only updated if config changes.
Template Variables
Preserve GrowthBook template variables in SQL:
sql: |
SELECT *
FROM events
WHERE date >= '{{ startDate }}'
AND date < '{{ endDate }}'
AND experiment_id = '{{ experimentId }}'
These variables are preserved during config rendering and evaluated at runtime by GrowthBook.
Step 4: Verify in GrowthBook
- Log into GrowthBook
- Check Metrics section
- Verify "Paid Conversion Rate" metric exists
- Use in experiments
Advanced Usage
Multiple Environments
Use separate configs for different environments:
gbsync plan --config gbsync.prod.yaml
gbsync apply --config gbsync.dev.yaml
Each config file can reference different datasources and environments.
Including External Files
Organize SQL in separate files:
factTables:
- id: fact_events
data:
name: Events
sql: !include fact_tables/events.sql
- id: fact_conversions
data:
name: Conversions
sql: !include fact_tables/conversions.sql
Documentation
- CONFIG.md - Complete configuration schema reference
- API.md - GrowthBook API details
- TROUBLESHOOTING.md - Common issues and solutions
- CONTRIBUTING.md - Development setup and guidelines
- examples/ - Reference configurations
Requirements
- Python 3.12+
- GrowthBook account with API access
- Supported data warehouses:
- Snowflake
- BigQuery
- PostgreSQL
- MySQL
- Redshift
- Athena
- ClickHouse
- MongoDB
Limitations
- API rate limits: 60 requests/min, 10,000 requests/hour
- SQL queries validated at GrowthBook (not locally)
- Some features may require GrowthBook Pro/Enterprise
- Manual edits in GrowthBook UI can cause conflicts
Getting Help
- Documentation: See docs/ directory
- Examples: See examples/ for reference configs
- Issues: https://github.com/growthbook/gbsync/issues
- GrowthBook Docs: https://docs.growthbook.io/
- GrowthBook Community: https://join.slack.com/t/growthbook-community/
License
This project is licensed under the MIT License. See LICENSE file for details.
Changelog
See CHANGELOG.md for version history and changes.
Next Steps
- Copy examples/gbsync.yaml to get started
- Read docs/CONFIG.md for configuration reference
- Check examples/ for reference configurations
- Run
gbsync planto preview changes - Run
gbsync applyto deploy metrics
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file gbsync-1.0.0.tar.gz.
File metadata
- Download URL: gbsync-1.0.0.tar.gz
- Upload date:
- Size: 17.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.14 {"installer":{"name":"uv","version":"0.11.14","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6078d9c8dcd717275b6698b6ddbc8a497420de539b967d41d43c5ba850cdac82
|
|
| MD5 |
199a772647d2c49445761cd206d63acc
|
|
| BLAKE2b-256 |
59077e68b0712032d6b98665e56153c3e48fac430ec8a4fb2b7b8d5ff2061144
|
File details
Details for the file gbsync-1.0.0-py3-none-any.whl.
File metadata
- Download URL: gbsync-1.0.0-py3-none-any.whl
- Upload date:
- Size: 15.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.14 {"installer":{"name":"uv","version":"0.11.14","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d08f23b6c092fbc5cb821cc2902f0b60fbe38d32068e483f6c48edcb8b8d0736
|
|
| MD5 |
226ea50ca0ec4f3b08f08a41a7423290
|
|
| BLAKE2b-256 |
b9c44cd1ff0ee112d284a102ab7816074fe2a958552d14f095e5ea75e5b20c51
|