Skip to main content

No project description provided

Project description

Py AB Testing

AB testing library supporting multi-variance testing with a deterministic algorithm not requiring any complex backend or database.

The segmentation logic is maintained in the AB testing client and based itself on a centralized configuration. The cohort assignment logic is deterministic and follows a simple hash pattern based on the crc32c algorithm (crc32c(userId, crc32c(experimentName)) % 100)

Installation

pip install py-ab-testing
# or
pipenv install py-ab-testing

Usage

Note: The config variable holds an dict with configuration file format that documented here.

from ABTesting import ABTestingController

user_profile = {
    'persona': user.persona,
    'employee': user.isEmployee,
}

controller = ABTestingController(config, user.id, user_profile)
cohort = controller.get_cohort('experiment-name')

if cohort == 'blue':
    do_something()
elif cohort == 'red':
    do_something_else()
else:
    do_default_behavior()

Protecting Private Information

Similar to the Javascript SDKs, the package comes with an optional util for hashing private information with sha256.

Prepare config file BEFORE make it public

from ABTesting.utils import hash_dict

config['salt'] = salt
for experiment in config['experiments']:
    for cohort in experiment['cohorts']:
        cohort['force_include'] = hash_dict(cohort['force_include'], salt)

In runtime

from ABTesting.utils import hash_dict

hashed_user_profile = hash_dict(
    {
        'persona': user.persona,
        'employee': user.isEmployee,
    },
    salt
)

# Make sure config is hashed with the same salt
controller = ABTestingController(config, user.id, hashed_user_profile)

Credits

Made with ❤️ by Zhang Tao and Simon Boudrias from the App Annie Beijing office.

Available for public use under the MIT license.

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

py-ab-testing-1.1.1.tar.gz (3.5 kB view hashes)

Uploaded Source

Built Distribution

py_ab_testing-1.1.1-py3-none-any.whl (3.6 kB view hashes)

Uploaded Python 3

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