No project description provided
Project description
rust_decider
Rust implementation of bucketing, targeting, overrides, and dynamic config logic.
Usage
class Decider
A class used to expose these APIs:
choose(feature_name: str, context: Mapping[str, JsonValue]) -> Decision
example:
from rust_decider import Decider
from rust_decider import DeciderException
from rust_decider import FeatureNotFoundException
from rust_decider import DeciderInitException
from rust_decider import PartialLoadException
# initialize Decider instance
try:
decider = Decider("../cfg.json")
except PartialLoadException as e:
# log errors of misconfigured features
print(f"{e.args[0]}: {e.args[2]}")
# use partially initialized Decider instance
decider = e.args[1]
except DeciderInitException as e:
print(e)
# get a Decision for a feature via choose()
try:
decision = decider.choose(feature_name="exp_1", context={"user_id": "3", "app_name": "ios"})
except DeciderException as e:
print(e)
assert dict(decision) == {
"variant": "variant_0",
"feature_id": 3246,
"feature_name": "exp_1",
"feature_version": 2,
"events": [
"0::::3246::::exp_1::::2::::variant_0::::3::::user_id::::37173982::::2147483648::::test"
]
}
# `user_id` targeting not satisfied so "variant" is `None` in the returned Decision
try:
decision = decider.choose(feature_name="exp_1", context={"user_id": "1"})
except DeciderException as e:
print(e)
assert dict(decision) == {
"variant": None,
"feature_id": 3246,
"feature_name": "exp_1",
"feature_version": 2,
"events": []
}
# handle "feature not found" exception
# (`FeatureNotFoundException` is a subclass of `DeciderException`)
try:
decision = decider.choose(feature_name="not_here", context={"user_id": "1"})
except FeatureNotFoundException as e:
print("handle feature not found exception:")
print(e)
except DeciderException as e:
print(e)
python bindings used in Decider
class
import rust_decider
# Init decider
decider = rust_decider.init("darkmode overrides targeting holdout mutex_group fractional_availability value", "../cfg.json")
# Bucketing needs a context
ctx = rust_decider.make_ctx({"user_id": "7"})
# Get a decision
choice = decider.choose("exp_1", ctx)
assert choice.err() is None # check for errors
choice.decision() # get the variant
# Get a dynamic config value
dc = decider.get_map("dc_map", ctx) # fetch a map DC
assert dc.err() is None # check for errors
dc.val() # get the actual map itself
Development
Updating package with latest src/lib.rs
changes
# In a virtualenv, python >= 3.7
$ cd decider-py
$ pip install -r requirements-dev.txt
$ maturin develop
Running tests
$ pytest decider-py/test/
Publishing
Package is automatically published on merge to master to https://pypi.org/project/reddit-decider/ via drone pipeline.
Formatting / Linting
$ cargo fmt --manifest-path decider-py/test/Cargo.toml
$ cargo clippy --manifest-path decider-py/test/Cargo.toml
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
reddit_decider-1.2.28.tar.gz
(50.1 kB
view hashes)
Built Distributions
Close
Hashes for reddit_decider-1.2.28-cp37-abi3-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 309bb982a448d2616a58921d898fa4e68291632c9bedb484a3c0c59fb9859672 |
|
MD5 | 8f08ef4d8482d36318c0ada3cfe05fd1 |
|
BLAKE2b-256 | 1a16ee78c5473f8948747180ca1b42f667da326ab2d3ed520eff24b08251a097 |
Close
Hashes for reddit_decider-1.2.28-cp37-abi3-manylinux_2_28_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6e274a85887ebec9d8efa25bf23f88085c8b662e68545d135daa3cc586b24af3 |
|
MD5 | 95a8fd6ad8974b8fe02745db7b41ca79 |
|
BLAKE2b-256 | c51214de7417adae8963dfeb5bb10266856dba9feb7452d9f041e30b6bfd8da1 |
Close
Hashes for reddit_decider-1.2.28-cp37-abi3-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fb7d179b2b04b096f4d7b750d96f14c8a2922250b4c6beaffde50aebf93b593a |
|
MD5 | 203fdca622a13e1b5fe5492a65381d30 |
|
BLAKE2b-256 | 33198e89ed9ddaca742ecf8a24e1139d704e9b96ebd945c608d27ced0d834df8 |
Close
Hashes for reddit_decider-1.2.28-cp37-abi3-macosx_10_7_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ff8abbe9579e9f808d54faa7370f756d0efdb6966b5437616d21cc91a245ade7 |
|
MD5 | 1bfd2eb6504b7c56c185cfcadb7a8608 |
|
BLAKE2b-256 | 316791c9dd2aad1152c9b10bbe893cb57043f868eee1b981d57dbd6b86cf2ef1 |