Skip to main content
Join the official 2020 Python Developers SurveyStart the survey!

Utilities for randomizing A/B tests

Project description


CI Actions Status PyPI version codecov

GetCohorts provides an endpoint that will randomly determine a cohort for a user in an A/B test, and is gauranteed to always assign the same user to the same cohort for the same experiment.

>>> import requests
>>> resp = requests.get('', json={
...    'identifier': 'user1',
...    'experiment': 'homepage-test'
... })
>>> print(resp.json()['cohort'])

More details on using the service are available on the documentation site.


GetCohorts provides a web service at that you can use for testing. But that service runs on Heroku's free tier, and can occasionally have slow response times. So we recommend that you deploy GetCohorts yourself.

Deploy with Docker

docker run --publish 8000:8000 tjwaterman99/getcohorts

Deploy to Heroku

You can also deploy to Heroku directly with the button below.


Deploy from PyPI

You can also download the Python package from PyPI and deploy yourself. For instructions, see the docs section on deploying with pypi.


Clone this repo.

git clone

Install the package's dependencies. This will also install getcohorts in editable mode.

pip install -r requirements.txt

Run the uvicorn server locally in development mode.

uvicorn getcohorts.web:app --host --port 8000 --reload


Run the tests with pytest. Note that the tests assume the webserver is running locally on port 8000, and they will fail if you have not started the webserver.


You can run the github CI workflows locally if you have act installed.



Build the docs with mkdocs. The site is available at

mkdocs serve

Project details

Download files

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

Files for getcohorts, version 1.0.0
Filename, size File type Python version Upload date Hashes
Filename, size getcohorts-1.0.0-py3-none-any.whl (4.9 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size getcohorts-1.0.0.tar.gz (3.7 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page