Metadata-Version: 2.4
Name: ablift
Version: 0.7.1
Summary: Rigorous A/B test statistics in one CLI, built for agents and pipelines. JSON in, JSON out.
Author-email: Fabio-RibeiroB <bradyfr@proton.me>
License-Expression: MIT
Project-URL: Homepage, https://github.com/Fabio-RibeiroB/ablift
Project-URL: Repository, https://github.com/Fabio-RibeiroB/ablift
Project-URL: Documentation, https://github.com/Fabio-RibeiroB/ablift/tree/v0.7.1/docs
Project-URL: Changelog, https://github.com/Fabio-RibeiroB/ablift/blob/v0.7.1/CHANGELOG.md
Project-URL: Issues, https://github.com/Fabio-RibeiroB/ablift/issues
Keywords: ab-testing,experimentation,bayesian,sequential-testing,cli,statistics
Classifier: Development Status :: 3 - Alpha
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Scientific/Engineering :: Mathematics
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: click>=8.0
Requires-Dist: numpy>=1.22
Requires-Dist: openpyxl>=3.1.0
Dynamic: license-file

<img src="https://raw.githubusercontent.com/Fabio-RibeiroB/ablift/v0.7.1/docs/logo.svg" alt="ablift logo" width="80" align="right">

# ablift

[![PyPI](https://img.shields.io/pypi/v/ablift?label=PyPI)](https://pypi.org/project/ablift/)
[![CI](https://github.com/Fabio-RibeiroB/ablift/actions/workflows/ci.yml/badge.svg)](https://github.com/Fabio-RibeiroB/ablift/actions/workflows/ci.yml)
[![Python](https://img.shields.io/pypi/pyversions/ablift)](https://pypi.org/project/ablift/)
[![License: MIT](https://img.shields.io/badge/license-MIT-blue)](https://github.com/Fabio-RibeiroB/ablift/blob/v0.7.1/LICENSE)
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
[![uv](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/uv/main/assets/badge/v0.json)](https://github.com/astral-sh/uv)

**Rigorous A/B test statistics in one CLI, built for agents and pipelines. JSON in, JSON out.**

Bayesian, sequential (mSPRT) and fixed-horizon analysis, geo and switchback tests, power, sample size and data-quality checks. ablift computes the numbers (lifts, intervals, posterior probabilities, e-values, p-values, power) so your agent can make decisions against its own requirements. It never forces a verdict; a rule-based recommendation is opt-in.

![ablift computing lifts, intervals and win probabilities for a three-variant test, then the smallest lift a planned test can detect](https://raw.githubusercontent.com/Fabio-RibeiroB/ablift/v0.7.1/docs/demo.svg)

> **Alpha.** The statistics are tested against reference implementations, but the CLI and output format may still change before 1.0.

## Why ablift

- **Rigorous estimates, not a black box.** Computes lifts, intervals, Bayesian posteriors (probability to beat control, expected loss, `probability_best`), always-valid sequential e-values (mSPRT), and fixed-horizon p-values. Pass `--recommend` when you also want an opt-in rule-based recommendation.
- **Look at results as often as you like.** Sequential mode uses mSPRT with always-valid confidence intervals, so checking daily does not inflate false positives. `--state checkout.state.json` records every look, rejects a look whose counts went down or whose settings changed, and keeps a crossed threshold significant ([how](https://github.com/Fabio-RibeiroB/ablift/blob/v0.7.1/docs/methods.md#sequential-looks---state)).
- **Catches bad data automatically.** Sample ratio mismatch, sparse conversion counts, whale-dominated revenue, and pre-experiment covariate imbalance are always checked and reported in top-level `risk_flags`.
- **Built for agents and pipelines.** JSON in, JSON out, published JSON Schemas, stdin support, clean errors, and stable exit codes.

## Install

```bash
uv tool install ablift   # or: pip install ablift
```

## Quickstart

<!-- docs-test: run -->
```bash
# Analyze a starter JSON experiment (Bayesian by default)
ablift example-input | ablift analyze -

# Pipe in a CSV and run a sequential test you can re-check every day
printf 'variant,visitors,conversions\ncontrol,30000,1200\nnew_checkout,30000,1410\n' \
  | ablift analyze - --method sequential

# Plan how long a sequential test needs to run (duration and power need --method)
ablift duration --method sequential --baseline-rate 0.04 --relative-mde 0.05 --daily-traffic 50000

# Power analysis: what lift can 10,000 users per variant detect in a single-look test?
ablift power --method fixed --baseline-rate 0.08 --n-per-variant 10000
```

Add `--report report.md` to any `analyze` run for a human-readable Markdown summary (or `--report - --output result.json` to print the Markdown report to stdout).

## What it supports

| Method (`--method`) | Conversion rate | ARPU (revenue per visitor) | Ratio (e.g. CTR, AOV) |
|---|:---:|:---:|:---:|
| `bayesian`: probability to beat control, expected loss | ✅ | ✅ | ✅ |
| `sequential`: mSPRT, always-valid, safe to peek | ✅ | ✅ | ✅ |
| `fixed`: z / Welch t / Fisher exact, one planned look | ✅ | ✅ | ✅ |

Also included:

- **A/B/n tests** with Bonferroni, Holm, Benjamini-Hochberg or e-BH correction (`--correction`), or joint `probability_best` in Bayesian mode
- **Stratified analysis & interaction tests** (`--stratum-column`, `--columns ...,stratum=...`, or JSON `strata`): per-stratum SRM & lifts, stratum-weighted overall effects, Cochran's Q heterogeneity test, and pairwise interaction contrasts ([details](https://github.com/Fabio-RibeiroB/ablift/blob/v0.7.1/docs/methods.md#stratified-analysis-and-interaction-tests))
- **CUPED & CUPAC variance reduction** using one or more pre-experiment covariates (`--covariate-column x1,x2`, optional K-fold cross-fitting via `--cuped-folds 5`, or aggregated Gram-matrix sufficient statistics in JSON) — or pass an external ML model's pre-experiment baseline prediction as a covariate for CUPAC without adding ML dependencies ([details](https://github.com/Fabio-RibeiroB/ablift/blob/v0.7.1/docs/methods.md#cuped-and-cupac-variance-reduction))
- **Guardrail and secondary metrics** evaluated per variant
- **Scale-aware Bayesian decisions:** `--max-relative-expected-loss 0.01` caps expected loss at 1% of the control value, so one policy fits a 0.03% funnel and a $120 ARPU ([details](https://github.com/Fabio-RibeiroB/ablift/blob/v0.7.1/docs/methods.md#expected-loss-thresholds))
- **SRM checks** with custom traffic splits (`--expected-split 90,10`), inside every analysis or standalone from visitor counts (`ablift srm --visitors 50000,48500`)
- **Geo and switchback tests** (`ablift did`): difference-in-differences with cluster-robust standard errors and a pre-trend check ([details](https://github.com/Fabio-RibeiroB/ablift/blob/v0.7.1/docs/methods.md#difference-in-differences-for-geo-and-switchback-panels))
- **Heavy-tailed revenue handling** with pooled winsorization and bootstrap intervals
- **Duration planning and power analysis** for conversion rate and ARPU, with optional CUPED variance-reduction scaling (`--cuped-r-squared`): sample size and days (`duration`), or power and minimum detectable effect for a given sample size (`power`)
- **Input** from JSON, CSV, XLSX or stdin, with **output** as JSON and an optional Markdown report. Wide warehouse exports work as they are: `--columns variant=arm,visitors=users,conversions=orders` picks the columns by header and ignores the rest

## Commands

| Command | What it does |
|---|---|
| `ablift analyze` | Analyze an experiment from JSON, CSV, XLSX or stdin |
| `ablift duration` | Estimate the sample size and days a test needs |
| `ablift power` | Power for a given sample size, or the smallest lift it can detect |
| `ablift did` | Difference-in-differences for geo and switchback tests, from a unit x period panel |
| `ablift schema` | Print the JSON Schema for inputs and outputs |
| `ablift srm` | Check visitor counts for a sample ratio mismatch, without a full analysis |
| `ablift example-input` | Print a starter JSON input |
| `ablift doctor` | Check the environment as JSON (`--strict` fails CI on problems, `--text` for humans) |

Run `ablift <command> --help` for every option.

## Documentation

- [Inputs](https://github.com/Fabio-RibeiroB/ablift/blob/v0.7.1/docs/inputs.md): choosing a metric, the JSON contract, CSV/XLSX layouts, named columns for wide exports (`--columns`), stdin and `pyproject.toml` defaults
- [Reference SQL](https://github.com/Fabio-RibeiroB/ablift/blob/v0.7.1/docs/sql.md): ANSI SQL query for turning raw exposure and event tables into aggregated CSV or CUPED JSON input
- [Statistical methods](https://github.com/Fabio-RibeiroB/ablift/blob/v0.7.1/docs/methods.md): what each method computes and how multiple variants are handled
- [Duration and power](https://github.com/Fabio-RibeiroB/ablift/blob/v0.7.1/docs/duration.md): sample size, runtime, power and minimum detectable effect
- [Agents and automation](https://github.com/Fabio-RibeiroB/ablift/blob/v0.7.1/docs/agents.md): schemas, a step-by-step playbook, exit codes and every output field
- [Agent skill (`SKILL.md`)](https://github.com/Fabio-RibeiroB/ablift/blob/v0.7.1/skills/ablift/SKILL.md): thin operational skill for AI agents covering method choice, SRM checks, `--columns`, and common sharp edges
- [End-to-end pipeline example](https://github.com/Fabio-RibeiroB/ablift/blob/v0.7.1/docs/pipeline-example.md): dbt model to S3 CSV, LangGraph workflow with SRM checks, sequential analysis, audit reports and human approval
- [Changelog](https://github.com/Fabio-RibeiroB/ablift/blob/v0.7.1/CHANGELOG.md)

## Limitations

- `recommendation` is `null` by default across all methods (including `bayesian`) until opted in via `--recommend` or `decision_policy.enabled = true`.
- `ablift analyze` inputs are snapshots without a time dimension (novelty effects and time trends are not modeled); for repeated looks over cumulative snapshots, use `--method sequential --state`. Only `ablift did` reads a time panel, and it rejects staggered rollouts.
- Aggregated ARPU inputs cannot be winsorized after aggregation (only a CV-based `heavy_tailed_revenue` warning is emitted); pass row-level revenue with `--winsorize Q` (and optionally `--bootstrap-samples N`) when whale outliers are present.
- CUPED variance reduction currently supports `conversion_rate` and `arpu` primary metrics (not `ratio`).

## Development

```bash
uv sync                  # installs the test and lint groups
uv run pytest -n auto    # test suite in parallel, including the docs checks
make lint                # ruff and ty
make demo                # run every bundled example into examples/out/
make docs                # re-render docs/demo.svg after changing CLI output
```

See [CONTRIBUTING.md](https://github.com/Fabio-RibeiroB/ablift/blob/v0.7.1/CONTRIBUTING.md) for how changes are checked and released.

## License

MIT. See [LICENSE](https://github.com/Fabio-RibeiroB/ablift/blob/v0.7.1/LICENSE).
