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 DeciderFeatureNotFoundException
from rust_decider import DeciderInitException
# initialize Decider instance
try:
decider = Decider("../cfg.json")
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
# (`DeciderFeatureNotFoundException` is a subclass of `DeciderException`)
try:
decision = decider.choose(feature_name="not_here", context={"user_id": "1"})
except DeciderFeatureNotFoundException 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.26.tar.gz
(49.0 kB
view hashes)
Built Distributions
Close
Hashes for reddit_decider-1.2.26-cp37-abi3-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d15903abc956f3a9099f48e301078f8c92828208536d785e02fd9c087a6fa66a |
|
MD5 | caa1999e5672a6ecdd61f05de927f48b |
|
BLAKE2b-256 | 1b025ee264d75ad1e8cd725e9ce414608a981807aa79f0f553d43bda48dcd6d0 |
Close
Hashes for reddit_decider-1.2.26-cp37-abi3-manylinux_2_28_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5cea2625f4dd606bb1fee0b98c3508586cace6b5df4747f4089c75909b2299e2 |
|
MD5 | d57b0243b9c615333e3b8bf8293fc208 |
|
BLAKE2b-256 | 78a4f470476bdc5a0c6046f17b13d71eaf80890c285702d47aa1740b9757a620 |
Close
Hashes for reddit_decider-1.2.26-cp37-abi3-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 77ca6b240a70402cfbeecb7962d048c41967f3c2a4a6e8714a0addf77e8c3d07 |
|
MD5 | d5d28f074d82700c54881abad6a59d9a |
|
BLAKE2b-256 | e5cb4519ee60461b131384f750cc1f9c84822d1e70fdf1e3960447fb39328fb6 |
Close
Hashes for reddit_decider-1.2.26-cp37-abi3-macosx_10_7_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 343effa1cf7cdefad458e0cde9daea4613cfb08b5132026ba8f4ec3fba7bbd68 |
|
MD5 | 6e006a5123f888df09def03c775cad66 |
|
BLAKE2b-256 | 2fad327ee13edf252b11357dab959374592d3fcbf64f8165504b7394da4a889c |