Giter Club home page Giter Club logo

unleash-django's Introduction

unleash-django

This library is a wrapper for Unleash.io's python

It can wrap views and methods to run if only feature is enabled and return a fallback function otherwise.

Installation

$ pip install unleash-django-util

Setting:

set following values in your settings:

* UNLEASH_API_TOKEN = 'your project token',default is 'default:development. unleash-insecure-api-token'
* UNLEASH_URL = 'the project url', default is 'https://app.unleash-hosted.com/demo/api/'
* UNLEASH_APP_NAME = 'the app name', default is 'miare'

Use in Test Env:

set UNLEASH_FAKE_INITIALIZE = True in settings if no initialization is needed. By doing so no request is sent to Unleash server, neither for fetching flag status nor submitting metrics.

Wrappers:

Using view wrapper:

from unleash_django.decorators.view_flag import view_flag


def fallback_func(self):
    """some code goes here"""


@view_flag('feature_name', fallback_func)
def get(self):
    """some code here"""

Using method wrapper:

from unleash_django.decorators.method_flag import method_flag


def fallback_func():
    """ some code goes here """


@method_flag('feature_name', user_id=123)
def method():
    """ some code goes here """

if a method feature flag is going to have a user based strategy, user_id should be provided

Methods:

is_enabled:

from unleash_django.api.method import is_enabled

is_enabled('feature_name', context={'userId': '123'})

if feature flag is on, True will be returned, otherwise False unless default is set to True.

get_variant:

from unleash_django.api.method import get_variant

get_variant('feature_name', context={'userId': '123'})

the result should be like:

 {
   "name": "variant1",
   "payload": {
       "type": "string",
       "value": "val1"
       },
   "enabled": True
}

with_feature_flag:

from unleash_django.api.method import with_feature_flag


def enabled_func():
    """some code goes here"""


def disabled_func():
    """some code goes here"""


with_feature_flag('feature_name', enabled_function=enabled_func, disabled_function=disabled_func)

It runs enabled_function if feature is on, otherwise disabled_function unless default value is set to True

it is possible to pass functions with args and kwargs using tuple, dict or FlagFunction

Change Log

0.4.4

  • add a variable for fake initialization

0.4.3

  • set level of logging

0.4.1

  • added get_variant function

unleash-django's People

Contributors

amiralaghmandan avatar amirali avatar amirmotlagh avatar partizaans avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

unleash-django's Issues

Client Initialization in Tests

I could not find any convenient way to have a fake initialized client in some environments like the test environment. As an issue example if there is no internet connection during tests some ugly errors are logged.

IMHO it's not bad idea to have a flag which controls the client fake initialization.
I'll try the PR.

Log Level

Currently, the logger verbosity level is not severe enough for production use. We'd better make the log level configurable.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.