https://github.com/dancrew32/ab
A/B Testing Framework for Python (with optional Multi-armed bandit implementation)
https://github.com/dancrew32/ab
ab-testing deterministic multi-armed-bandit no-dependencies python python3
Last synced: 29 days ago
JSON representation
A/B Testing Framework for Python (with optional Multi-armed bandit implementation)
- Host: GitHub
- URL: https://github.com/dancrew32/ab
- Owner: dancrew32
- License: unlicense
- Created: 2019-06-03T06:29:12.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-08-18T00:09:51.000Z (over 6 years ago)
- Last Synced: 2025-09-27T02:26:26.861Z (5 months ago)
- Topics: ab-testing, deterministic, multi-armed-bandit, no-dependencies, python, python3
- Language: Python
- Homepage: https://pypi.org/project/ab/
- Size: 33.2 KB
- Stars: 3
- Watchers: 3
- Forks: 3
- Open Issues: 11
-
Metadata Files:
- Readme: readme.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# A/B Testing for Python
Without the need for a database, deterministically bucket users into A/B tests.
## Build Status:
[](https://travis-ci.org/dancrew32/ab)
## Install:
```
pip install ab
```
Thanks to Delvian for graciously donating the pip module name at https://pypi.org/project/ab/!
## Example A/B Usage:
```python
from ab import ab
# Define test & buckets
TEST_NAME = 'MY_TEST_V1'
TEST_BUCKET_TO_COLOR = {
'control': 'green',
'variant1': 'red',
'variant2': 'blue',
}
# Implemention
def get_button_color(user_id):
buckets = TEST_BUCKET_TO_COLOR.keys()
bucket = ab.get_bucket(user_id, test=TEST_NAME, buckets=buckets)
return TEST_BUCKET_TO_COLOR[bucket]
```
Thanks to Alexander Ejbekov for the allocation technique:
https://stackoverflow.com/a/23846715/61410
## Example Multi-Armed Bandit Usage:
https://en.wikipedia.org/wiki/Multi-armed bandit
```python
from ab import mab
# Define test & buckets
TEST_NAME = 'MY_TEST_V2'
TEST_BUCKET_TO_COLOR = {
'control': 'green',
'variant1': 'red',
'variant2': 'blue',
}
# Implemention
def get_button_color():
buckets = TEST_BUCKET_TO_COLOR.keys()
bucket = mab.get_bucket(test=TEST_NAME, buckets=buckets)
return TEST_BUCKET_TO_COLOR[bucket]
# Record success
def button_clicked(bucket):
mab.success(test=TEST_NAME, bucket=bucket)
```
## Demo MAB app:
You'll need `Docker` running and `docker-compose`.
* Install Docker: https://docs.docker.com/install/
* Install docker-compose: https://docs.docker.com/compose/install/
```bash
git clone https://github.com/dancrew32/ab.git ab
cd ab
make up
```
Then visit http://localhost:5000
## Development
Ensure you have python3 and virtualenv installed:
```
sudo apt install python3.7 python3-venv python3.7-venv
```
Then make the virtualenv, install any dependencies (there aren't any at the moment), and run the unit tests.
```bash
make venv deps test
```
## Publish new version to PyPI
```
make setup
```