11 releases

0.2.11 Oct 3, 2024
0.2.10 Oct 3, 2024
0.2.9 Jul 18, 2024
0.2.8 Apr 1, 2024
0.1.0 Feb 20, 2023

#66 in Database implementations

Download history 14/week @ 2024-07-29 142/week @ 2024-09-16 438/week @ 2024-09-23 459/week @ 2024-09-30 270/week @ 2024-10-07 150/week @ 2024-10-14 137/week @ 2024-10-21 140/week @ 2024-10-28 182/week @ 2024-11-04 301/week @ 2024-11-11

761 downloads per month

MIT license

21KB
500 lines

Introduction

Feature flagging should not be so complicated.

Mr Flagly is a decentralized feature flagging system written in Rust with bindings for other languages.

It does not depend on third party services or require you to deploy services and databases to manage.

Supported feature flag definition sources:

  • URL
  • JSON Value
  • Environment Variable

Rust usage

Setup your flag service:

use mrflagly::service::{FlagService, FlagServiceOptions};
let flag_service = FlagService::new(FlagServiceOptions {
    finder_type: mrflagly::service::types::FlagFinderType::URL,
    url: "https://path/to/hosted/json/file",
    refresh_interval: 600,
    data: None,
    env_var: None,
})

Then, to check for feature flag:

if flag_service.enabled("feature_x", false /* default value */, Some(HashMap::from([(String::from("user_id"), String::from("123")),])) /* optional context */) {
    // do something
}

Python support

import mrflagly

flag_service = mrflagly.FlagService(url="https://path/to/hosted/json/file")
if flag_service.enabled("feature_x", default=False, context={"foo": "bar"}):
    # do something

FlagService constructor parameters

  • finder_type: (NULL, URL, JSON, ENVVAR)
  • url: URL to download feature flag json data
  • refresh_interval: How often to poll the feature flag data endpoint
  • data: Instead of hosting feature flag data from URL, you can provide it as a json blob
  • env_var: Provide feature flag data in environment variable

JSON format

JSON format for feature flag data:

{
    "my_feature": {
        "rollout": 100
    },
    "my_feature_with_variants": {
        "rollout": 0,
        "variants" {
            "user_id": ["123"],
            "company_id": ["123"]
        }
    }
}

Example activating for a particular customer

JSON config data:

{
    "feature": {
        "rollout": 0,
        "variants": {
            "customer_id": ["123"]
        }
    }
}

Usage:

import mrflagly
import json

flag_service = mrflagly.FlagService(
    data=json.dumps({"feature": {"rollout": 0, "variants": {"customer_id": ["123"]}}}))

if flag_service.enabled("feature_x", default=False, context={"customer_id": "123"}):
    # do something

Dependencies

~12–25MB
~338K SLoC