Skip to main content

AB Test Framework for Python

Project description

Contributors Forks Stargazers Issues MIT License LinkedIn


Logo

pyabtesting

An awesome README template to jumpstart your projects!
Explore the docs »

View Demo · Report Bug · Request Feature

Table of Contents
  1. About The Project
  2. Getting Started
  3. Usage

About The Project

This library provides tools for AB Testing, very useful when working with marketing data

(back to top)

Implementation

import datetime

import pandas as pd

from abtestools.audiences import Audience
from abtestools.campaign import Campaign
from abtestools.test import Metric, Test

data = pd.read_csv("tests/cookie_cats.txt", delimiter=",")
data["version"] = data["version"].map({"gate_30": "control", "gate_40": "test"})
print(data.groupby("version")["retention_1"].sum())

audience = Audience(
    users=data["userid"], group_mapping=dict(zip(data["userid"], data["version"]))
)

campaign = Campaign(
    audience=audience,
    metrics=[
        Metric(name="retention_1", type="discrete"),
        Metric(name="retention_7", type="discrete"),
    ],
    date_range=[
        datetime.datetime.today() - datetime.timedelta(days=x) for x in range(10)
    ],
)


def extract_data(date, metric_column: str, convert_bool: bool = True) -> dict:
    if convert_bool:
        data[metric_column] = data[metric_column].astype(int)
    return dict(zip(data["userid"], data[metric_column]))


for res in campaign.backfill(
    metric=Metric(name="retention_1", type="discrete"),
    extract_data=extract_data,
    metric_column="retention_1",
):
    print(res)

Getting Started

Prerequisites

To develop on this project, you will need to create a poetry environment with the needed dependencies

  • install with Poetry
    poetry install
    

Installation

  1. git clone https://github.com/pablominue/pyabtesting.git
    

    or

    pip install abtestools
    
  2. Import main modules

    from abtestools import audience, test
    

(back to top)

Usage

Use this space to show useful examples of how a project can be used. Additional screenshots, code examples and demos work well in this space. You may also link to more resources.

For more examples, please refer to the Documentation

(back to top)

Project details


Download files

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

Source Distribution

abtestools-1.1.0.tar.gz (24.2 kB view details)

Uploaded Source

Built Distribution

abtestools-1.1.0-py3-none-any.whl (23.5 kB view details)

Uploaded Python 3

File details

Details for the file abtestools-1.1.0.tar.gz.

File metadata

  • Download URL: abtestools-1.1.0.tar.gz
  • Upload date:
  • Size: 24.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.0 CPython/3.11.5 Darwin/24.0.0

File hashes

Hashes for abtestools-1.1.0.tar.gz
Algorithm Hash digest
SHA256 36e1305b8d34f162c07d2e86d7e375b90ae2d6c966d380a9675f01f060874ce1
MD5 4b2df49fd01ccfb13fe021d9d4b27923
BLAKE2b-256 5525e368910036c38eb9962d4490652f9754e99526ba1c97791788b5d1d6d59f

See more details on using hashes here.

File details

Details for the file abtestools-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: abtestools-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 23.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.0 CPython/3.11.5 Darwin/24.0.0

File hashes

Hashes for abtestools-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3e335811e832ab8254ceba621f4c70658a7be7cab9d804680468b54446699a8c
MD5 a90a75150fb1a8dd87c8919b07d46b22
BLAKE2b-256 89976c15a6decf4e2b2ec0aa4fb61a5f0912c69c5453376b019b14214dc5d3cc

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page