Skip to main content

abtestwise

A lightweight Python toolkit for frequentist and Bayesian binary A/B testing.

ABTestWise accepts aggregate counts, raw binary samples, or DataFrame-like experiment data while providing the same statistical analysis through a simple, consistent API.

Install

Install from PyPI:

pip install abtestwise

Development install

To work on the package locally (with the test dependencies):

pip install -e ".[dev]"

Quickstart

Aggregate counts

Use from_counts() when your experiment data is already aggregated:

from abtestwise import BinaryABTest

test = BinaryABTest.from_counts(
    control_successes=120,
    control_total=1000,
    treatment_successes=145,
    treatment_total=1000,
    seed=42,
)

result = test.run()

print(result.summary())
print(result.prob_lift_above(0.01))

Raw samples

Use from_samples() when you already have separate control and treatment observations:

import numpy as np

from abtestwise import BinaryABTest

control = np.array([0, 1, 0, 1, 0, 0, 1])
treatment = np.array([1, 1, 0, 1, 0, 1, 1])

test = BinaryABTest.from_samples(
    control=control,
    treatment=treatment,
    seed=42,
)

result = test.run()

Samples must contain binary 0/1 values. Boolean values are also accepted.

DataFrame input

Use from_dataframe() when your experiment is stored in a tabular dataset:

import pandas as pd

from abtestwise import BinaryABTest

df = pd.DataFrame(
    {
        "variant": ["control", "control", "treatment", "treatment"],
        "converted": [0, 1, 1, 1],
    }
)

test = BinaryABTest.from_dataframe(
    df,
    group_col="variant",
    outcome_col="converted",
    control="control",
    treatment="treatment",
    seed=42,
)

result = test.run()

from_dataframe() does not require pandas as an ABTestWise runtime dependency. If you pass a pandas DataFrame, pandas must be installed in your environment. The method works with DataFrame-like objects that support column access.

All three constructors reduce to the same underlying binary A/B test, so equivalent data produces equivalent statistical results.

prob_lift_above(0.01) gives the posterior probability that Treatment B improves the metric by more than 1 percentage point.

Do-no-harm checks

prob_no_harm(margin) gives the posterior probability that Treatment B is not worse than Control A by more than margin (in raw decimal units, so 0.005 means 0.5 percentage points). prob_harm_above(margin) is its complement.

result.prob_no_harm(0.005)     # P(lift >= -0.005): B is not worse by more than 0.5pp
result.prob_harm_above(0.005)  # P(lift <  -0.005): B is worse by more than 0.5pp

Raw result values are also available:

result.to_dict()

Plotting

import matplotlib.pyplot as plt

result.plot_lift_distribution()
result.plot_probability_bar()

plt.show()

The lift distribution plot shows posterior lift in percentage points.

The probability bar plot shows:

P(Treatment B > Control A)
P(Control A > Treatment B)

Groups and sign convention

In product A/B testing terms:

  • Control (A) is the baseline group.
  • Treatment (B) is the test group or variant B.
  • Lift is always Treatment B - Control A.
  • Positive lift means Treatment B is better than Control A.
  • Negative lift means Control A is better than Treatment B.

Scope

Current package scope:

  • Binary proportions.
  • Aggregate counts, raw binary samples, and DataFrame-like experiment data.
  • Two-group comparisons.
  • Frequentist: two-sided pooled two-proportion z-test.
  • Bayesian: Beta-Binomial posterior simulation with default prior Beta(1, 1).
  • Equal-tailed credible intervals.
  • Expected loss.
  • Practical lift thresholds.
  • Do-no-harm probabilities using a user-defined harm margin.
  • Simple plots.

Development

Run tests with:

python -m pytest -q

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

abtestwise-0.2.0.tar.gz (13.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

abtestwise-0.2.0-py3-none-any.whl (11.7 kB view details)

Uploaded Python 3

File details

Details for the file abtestwise-0.2.0.tar.gz.

File metadata

  • Download URL: abtestwise-0.2.0.tar.gz
  • Upload date:
  • Size: 13.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.3

File hashes

Hashes for abtestwise-0.2.0.tar.gz
Algorithm Hash digest
SHA256 2f482e8d297e9c2ebb9162647342b7932d9187b631f964ea5383906a9af5d9c5
MD5 1442cf7b7eac9f87782281e5ef58b24b
BLAKE2b-256 d4f503dd5b81387b069909ae9cfc52dac1e9b4f81ce65c92c5a4bb1fe7bbcbd1

See more details on using hashes here.

File details

Details for the file abtestwise-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: abtestwise-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 11.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.3

File hashes

Hashes for abtestwise-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cfeda1181d54da32214bb821194a470842bf368509bef185b936726d9845e956
MD5 6d942a0a9313c0a5425c0c523d7fdd0d
BLAKE2b-256 98a338ec8b579d8cde4f89e74a7264c8a35391f66afec0f123bcb9253c830822

See more details on using hashes here.

Release history Release notifications | RSS feed

0.3.0

2 files

This release

0.2.0 This release

2 files

0.1.1

2 files

0.1.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page