Skip to main content
https://raw.githubusercontent.com/molassesapp/molasses-go/main/logo.png

molasses-python

https://img.shields.io/pypi/v/molasses.svg

A Python SDK for Molasses. It allows you to evaluate user’s status for a feature. It also helps simplify logging events for A/B testing.

Molasses uses server sent events to get instant updates with an option for polling to check if you have updated features. Once initialized, it takes microseconds to evaluate if a user is active.

Install

pip install molasses

Usage

Initialization

Start by initializing the client with an APIKey. This begins the polling for any feature updates. The updates happen every 15 seconds.

from molasses import MolassesClient

client = MolassesClient("test_key")

If you decide not to track analytics events (experiment started, experiment success) you can turn them off by setting the send_events field to False

client = MolassesClient("test_key",  send_events=False)

Check if feature is active

You can call is_active with the key name and optionally a user’s information. The id field is used to determine whether a user is part of a percentage of users. If you have other constraints based on user params you can pass those in the params field.

client.is_active("FOO_TEST", {
  "id":"foo",
  "params":{
    "isBetaUser":"false",
    "isScaredUser":"false"
   }
})

You can check if a feature is active for a user who is anonymous by just calling is_active with the key. You won’t be able to do percentage roll outs or track that user’s behavior.

client.is_active("TEST_FEATURE_FOR_USER")

Experiments

To track an analytics events called the track method.

client.track("Button Clicked",{
   "id":"foo",
   "params":{
     "isBetaUser":"false",
     "isScaredUser":"false"
    }
 },
 {
   "version": "v2.3.0"
})

To track whether an experiment was successful you can call experiment_started. experiment_started takes the feature’s name, any additional parameters for the event and the user.

client.experiment_started("GOOGLE_SSO",{
   "id":"foo",
   "params":{
     "isBetaUser":"false",
     "isScaredUser":"false"
    }
 },
 {
   "version": "v2.3.0"
})

To track whether an experiment was successful you can call experiment_success. experiment_success takes the feature’s name, any additional parameters for the event and the user.

client.experiment_success("GOOGLE_SSO",{
   "id":"foo",
   "params":{
     "isBetaUser":"false",
     "isScaredUser":"false"
    }
 },
 {
   "version": "v2.3.0"
})

Example

from molasses import MolassesClient

client = MolassesClient("test_key")

if client.is_active('NEW_CHECKOUT'):
  print "we are a go"
else:
  print "we are a no go"

Credits

This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.

History

0.1.0 (2020-09-24)

  • First release on PyPI.

Metadata

Release files for molasses 0.3.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for molasses 0.3.1
File Size Uploaded
molasses-0.3.1.tar.gz 14.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for molasses 0.3.1
File Interpreter ABI Platform
molasses-0.3.1-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 20.8 kB

Release files / molasses-0.3.1.tar.gz

Download URL molasses-0.3.1.tar.gz
Size 14.5 kB
Tags Source
SHA-256 checksum
How to use checksums
be3279e071dcf307a1cd108866ab115c31cfcede0ecc9cb38fe035d56caae7bb
BLAKE2b-256 checksum
How to use checksums
58225e96d40ff3ec3509dcbcf47b3d9304e8164eb16affe49bc0f6d0f86f1a0d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.9.1

Release files / molasses-0.3.1-py2.py3-none-any.whl

Download URL molasses-0.3.1-py2.py3-none-any.whl
Size 6.3 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
1ba82ea68dfed0fa16e68dbb35a76db41014d835670645307a0cd798ceb810d4
BLAKE2b-256 checksum
How to use checksums
08e7f01b56c0c84061a703e981681f79cc3dfdda3a831d8c2746ac46768c373e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.9.1

Release history Release notifications | RSS feed

This release

0.3.1 This release

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page