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
-
choose_all( context: Mapping[str, JsonValue], bucketing_field_filter: Optional[str] = None ) -> Dict[str, Decision]
choose()
examples:
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)
choose_all()
examples:
from rust_decider import Decider
from rust_decider import DeciderException
from rust_decider import DeciderInitException
try:
decider = Decider("../cfg.json")
except DeciderInitException as e:
print(e)
decisions = decider.choose_all(context={"user_id": "3", "app_name": "ios"}, bucketing_field_filter="user_id")
assert dict(decisions["exp_67"]) == {
"variant": "variant_0",
"value": None,
"feature_id": 3125,
"feature_name": "exp_67",
"feature_version": 4,
"events": [
"0::::3125::::exp_67::::4::::variant_0::::3::::user_id::::37173982::::2147483648::::test"
]
}
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
Use conventional commit format in PR titles to trigger releases via release-please
task in drone pipeline.
chore:
&build:
commits don't trigger releases (used for changes like updating config files or documentation)fix:
bumps the patch versionfeat:
bumps the minor versionfeat!:
bumps the major version
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.29.tar.gz
(52.1 kB
view hashes)
Built Distributions
Close
Hashes for reddit_decider-1.2.29-cp37-abi3-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a9280dc0568813896aca310a8256824e9a026f6c355401600284027e2080fc9a |
|
MD5 | 78d9412851ad5d42e06a3f5de58a8bb6 |
|
BLAKE2b-256 | 380b5b31e6d4627cbf55c5871f52d98139a1005234ce9572ed8647ebb12eb86d |
Close
Hashes for reddit_decider-1.2.29-cp37-abi3-manylinux_2_28_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 25cfe35d7313cdd9235bc23b54b19c35d3203a7e1d3b17fd4b65de4f01ef361a |
|
MD5 | 7733d39fa7a92eddb5f9c5059c3449b2 |
|
BLAKE2b-256 | d571bcaacbc74e9a7164b5379145cb2cd4dba67cc5b51494756e60c8e8c55c7f |
Close
Hashes for reddit_decider-1.2.29-cp37-abi3-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c8e8b6450659231552172397855073d34ad08e0bb7cacebfa55442e68c79d7a2 |
|
MD5 | 42e683d83b81f8bddbb5b45701038dae |
|
BLAKE2b-256 | 7079710cb242d287d28a755e34411491e453146e8404cb3efd15b5360c1adf43 |
Close
Hashes for reddit_decider-1.2.29-cp37-abi3-macosx_10_7_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dc4d8f12e8b8e81bdb4728963d919c2e95d6aa888ebf694e5c2ae394f32e8155 |
|
MD5 | 48c1c64470e555e41e289e6d3385b000 |
|
BLAKE2b-256 | 7325b4b9e71a06953abff9f2a096d8a5ff6606f845f8cf7d304fcca2be1933c8 |