Skip to main content

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.25.tar.gz (48.4 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

reddit_decider-1.2.25-cp37-abi3-musllinux_1_1_x86_64.whl (476.8 kB view details)

Uploaded CPython 3.7+musllinux: musl 1.1+ x86-64

reddit_decider-1.2.25-cp37-abi3-manylinux_2_28_x86_64.whl (444.3 kB view details)

Uploaded CPython 3.7+manylinux: glibc 2.28+ x86-64

reddit_decider-1.2.25-cp37-abi3-macosx_11_0_arm64.whl (394.5 kB view details)

Uploaded CPython 3.7+macOS 11.0+ ARM64

reddit_decider-1.2.25-cp37-abi3-macosx_10_7_x86_64.whl (424.8 kB view details)

Uploaded CPython 3.7+macOS 10.7+ x86-64

File details

Details for the file reddit_decider-1.2.25.tar.gz.

File metadata

  • Download URL: reddit_decider-1.2.25.tar.gz
  • Upload date:
  • Size: 48.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.8

File hashes

Hashes for reddit_decider-1.2.25.tar.gz
Algorithm Hash digest
SHA256 eb9846911517f6ec39bdc4fa55b41d99a6a81c37099f8a5c06b6b9333df392ff
MD5 a7d308478baa08fc62791bd9605ff908
BLAKE2b-256 fc5f40e31a56d81f8e1501a131809547d386b8f718702e396dfc12a135b49435

See more details on using hashes here.

File details

Details for the file reddit_decider-1.2.25-cp37-abi3-musllinux_1_1_x86_64.whl.

File metadata

  • Download URL: reddit_decider-1.2.25-cp37-abi3-musllinux_1_1_x86_64.whl
  • Upload date:
  • Size: 476.8 kB
  • Tags: CPython 3.7+, musllinux: musl 1.1+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.8

File hashes

Hashes for reddit_decider-1.2.25-cp37-abi3-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 bbd4ee5e4d1086b7889ea926f575beb325cadeb637b93f7bba3ce6389c6e5bfa
MD5 49bf876f5ae55275aa9930556b15a882
BLAKE2b-256 8c0c1aa88765746b9ebac6330452748c91dc7b2ac735832828f3ca2551f2366f

See more details on using hashes here.

File details

Details for the file reddit_decider-1.2.25-cp37-abi3-manylinux_2_28_x86_64.whl.

File metadata

  • Download URL: reddit_decider-1.2.25-cp37-abi3-manylinux_2_28_x86_64.whl
  • Upload date:
  • Size: 444.3 kB
  • Tags: CPython 3.7+, manylinux: glibc 2.28+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.8

File hashes

Hashes for reddit_decider-1.2.25-cp37-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 6d0dd99fe900d9a1d36a1b92fbd52f2fb86ec30b744eb8d84914820bbfc5afad
MD5 6a24789d6a78d3714efa43f27e5980e4
BLAKE2b-256 270245bab826de29972145c89791288c7eee4b637e908db019b4a78cdfbca101

See more details on using hashes here.

File details

Details for the file reddit_decider-1.2.25-cp37-abi3-macosx_11_0_arm64.whl.

File metadata

  • Download URL: reddit_decider-1.2.25-cp37-abi3-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 394.5 kB
  • Tags: CPython 3.7+, macOS 11.0+ ARM64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.8

File hashes

Hashes for reddit_decider-1.2.25-cp37-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 56d94c5095e5f4230f0879786f39fd6e3dd3eca65c8a8f4e1c971ee9caa89cf9
MD5 f71179dfe19a2e2e6c88f38a7a3029a7
BLAKE2b-256 884337e030116b9c7c1f396bb661c4d38351f7788921f6a307214860c239ee59

See more details on using hashes here.

File details

Details for the file reddit_decider-1.2.25-cp37-abi3-macosx_10_7_x86_64.whl.

File metadata

  • Download URL: reddit_decider-1.2.25-cp37-abi3-macosx_10_7_x86_64.whl
  • Upload date:
  • Size: 424.8 kB
  • Tags: CPython 3.7+, macOS 10.7+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.8

File hashes

Hashes for reddit_decider-1.2.25-cp37-abi3-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 2aaaad8048c834f9a83b2415e277cf0203b95b86157ec3f5cbdbbe3ca094491f
MD5 fb5588ea4a36c2e38a8e8daac143a5ec
BLAKE2b-256 009537b3cf7bbbd32c9809bcc0dfcd5ad617cf18f701ecfa9b09427cd19748bf

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page