GTM Experimentation Tool (gxt) - CLI for SQL-based experiment assignments
Project description
GTM Experimentation Tool (gxt)
GTM Experimentation Tool (gxt) is a small command-line utility for managing and running A/B experiments stored in a simple project layout. It provides tools to compile experiment manifests, qualify data source references, build deterministic assignment SQL, and optionally execute assignment upserts into a data warehouse. A BigQuery adapter is included to run assignment MERGE operations.
Contents
- Features
- Quick start
- Project layout
- CLI reference and examples
- BigQuery adapter details and requirements
- Developer notes and testing
- License
Features
- Compile experiment manifests and rewrite
source(...)references to fully qualified table identifiers. - Generate deterministic assignment SQL using hashing (BigQuery:
FARM_FINGERPRINT+MOD). - Dry-run mode prints compiled SQL and prevents writes.
- Optional execution against BigQuery with
--no-dry-run; supports an opt-in--create-assignments-tablehelper. - Pluggable adapter model —
BigQueryAdapterprovided as a concrete example.
Quick start
Prerequisites
- Python 3.10+.
- Recommended: create and activate a virtual environment.
Install dependencies:
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
If you will run against Google BigQuery, install the BigQuery client as well:
pip install google-cloud-bigquery
Set Google credentials (if using BigQuery):
- Set
GOOGLE_APPLICATION_CREDENTIALSto a service account JSON with BigQuery permissions, or use Application Default Credentials. - Ensure billing is enabled for the GCP project if you will run DML operations (MERGE/INSERT).
Project layout
Repository expects projects in projects/ with this structure:
gxt_project.yml— project configurationprofiles.yml— profiles mapping (project/dataset/credentials)experiments/<experiment_name>/— each experiment contains:audience.sql— SQL that yields the set of units to assignconfig.yml— experiment config (variants, randomization_unit, assignments table, etc.)
target/— compiled manifests are written here bycompile
CLI reference
Run the CLI via module invocation or a packaged entry point:
python -m src.gxt.main <command> [args]
# or if installed as `gxt`:
gxt <command> [args]
Commands
init— scaffold a project from templatesnew-experiment <name>— create a new experiment scaffoldcompile [EXPERIMENT] --project-path <path>— compile manifests for the project or a single experimentlist --project-path <path>— list experimentsvalidate --project-path <path>— validate experiment configs and SQLrun <EXPERIMENT> --project-path <path> [--no-dry-run] [--adapter ADAPTER_NAME] [--create-assignments-table]— build and optionally execute assignment upserts
Run command notes
- Default behavior is a dry-run (prints SQL). Use
--no-dry-runto execute. --create-assignments-tableinstructs the BigQuery adapter to create the assignments table if it is missing. This is opt-in and requires BigQuery client + permissions.
Examples
Dry-run compile + run for demo_exp:
python -m src.gxt.main compile demo_exp --project-path projects/demo
python -m src.gxt.main run demo_exp --project-path projects/demo
Real run against BigQuery (ensure credentials and billing enabled):
python -m src.gxt.main run dummy_experiment2 --project-path projects/test_project2 --no-dry-run --create-assignments-table
BigQuery adapter details
Behavior
- The included
BigQueryAdapterattempts to construct agoogle.cloud.bigquery.Clientwhengoogle-cloud-bigqueryis installed and the profile supplies a project (and credentials via env var or ADC). - If the client is not available, adapter methods fall back to printing SQL and returning empty results — safe for dry-run.
Provided methods
execute(sql)— runs a query and returns rows (or prints SQL when client unavailable)insert_rows(table, rows)— inserts rows usinginsert_rows_jsonwhen availableensure_table_exists(table, schema, location)— create table with default schema if missingupsert_from_select(target_table, src_select_sql, key_columns)— MERGE FROM (SELECT ...) that inserts rows which don't yet exist (insert-only upsert)hash_bucket_sql(column, salt, precision)— returns an expression usingFARM_FINGERPRINTandMODto compute a deterministic bucket in [0,1)
Important notes
- Confirm billing on your GCP project before running non-dry-run: DML operations require billing.
- The default assignments schema used by the adapter is:
experiment_id STRING, unit STRING, variant STRING, assigned_at TIMESTAMP. You can override by callingensure_table_existswith an explicit schema.
Configuration and profiles
Example projects/<project>/profiles.yml:
default:
project: my-gcp-project
dataset: my_dataset
The tool resolves adapter/profile configuration using gxt_project.yml in each project folder when not provided via CLI flags.
Developer notes
- CLI implementation:
src/gxt/main.py(Typer) - Commands:
src/gxt/commands/(compile, run, init, list, validate, new_experiment) - Parser and manifest compilation:
src/gxt/parser/manifest.py - Adapters:
src/gxt/adapters/ - Templates:
src/gxt/templates/
Testing
- There are no unit tests in this snapshot. Recommended tests:
- Unit tests for
BigQueryAdapter.upsert_from_select(mock client) - Tests for
manifest.compile_manifestand_qualify_sources_in_sql
- Unit tests for
Maintenance and next improvements
- Replace transient state
adapter._last_insert_columnsby passing insert columns explicitly toupsert_from_select. - Add unit tests and CI pipeline.
- Add more adapters (Redshift, Snowflake) as needed.
License
See the LICENSE file in the repository.
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 gtm_experiments_tool-0.1.0.tar.gz.
File metadata
- Download URL: gtm_experiments_tool-0.1.0.tar.gz
- Upload date:
- Size: 30.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
28ab2319bc1ee503002dc63f5ebe0be44d6de03992f5a61e302c929000f0a8e4
|
|
| MD5 |
4a2f74f8cb46dcf5bdc16fe3da9e484e
|
|
| BLAKE2b-256 |
939dc032481047c7bb12e6b1542d908c9539e83a8ec288608a32e9bd6bddac1c
|
File details
Details for the file gtm_experiments_tool-0.1.0-py3-none-any.whl.
File metadata
- Download URL: gtm_experiments_tool-0.1.0-py3-none-any.whl
- Upload date:
- Size: 32.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a47291ec25fdf7123f104f72dcb700c9fab4524071cbbe4bc22c965b0ef148e3
|
|
| MD5 |
1b73c890419a4498e05f58493285cf15
|
|
| BLAKE2b-256 |
14088de5fdd2f85bbc5f4d10b9538efa768a702c7ce5c7bc30faaaf67929cca2
|