abtestify 0.3.1

Deterministic A/B test bucketing with per-experiment hashing, exposure and split control; identical assignments to the abtestify npm package
Documentation
  • Coverage
  • 100%
    29 out of 29 items documented1 out of 13 items with examples
  • Size
  • Source code size: 24.4 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 215.8 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 1s Average build duration of successful builds.
  • all releases: 1s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • pranav2012/abtestify
    1 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • pranav2012

abtestify

Deterministic A/B test bucketing for Rust. Give it an experiment name and a user ID and it returns the same variant for that user every time, with no storage, no network calls and no dependencies.

Assignments are byte-for-byte identical to the abtestify npm package and its Go, Python, Java/Kotlin and Swift ports, so a user lands in the same variant on every platform. Shared test vectors in the repository enforce it.

[dependencies]
abtestify = "0.3"
use abtestify::{get_bucket, Params};

let params = Params::new("checkout-cta", "user123")
    .treatment_split(50.0) // optional, default 50
    .exposure(100.0); // optional, default 100

match get_bucket(&params) {
    Ok(assignment) if assignment.resolved_variant == "treatment" => {
        // show the new checkout button
    }
    Ok(_) => {}
    Err(err) => eprintln!("invalid experiment config: {err}"),
}

Params also takes treatment_variant_name, control_variant_name, ignore_variant_name and legacy_hashing. get_bucket returns an Error when a percentage is not a finite number from 0 to 100 or a required name is empty.

The bucket is the first 8 bytes of SHA-256 of experiment_name:unique_id, mapped to one of 10,000 buckets. Exposure takes the lowest buckets, and the split uses the bucket's last two digits, so raising exposure only adds users and raising treatment_split only moves users from control to treatment.

Licensed under MIT.