Skip to main content

Unleash Django utility package

Project description

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

1.0.0

  • BREAKING CHANGE: bump dependencies, this version requires UnleashClient>=6.4.0

0.4.4

  • add a variable for fake initialization

0.4.3

  • set level of logging

0.4.1

  • added get_variant function

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

unleash_django_util-1.0.0.tar.gz (7.8 kB view details)

Uploaded Source

Built Distribution

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

unleash_django_util-1.0.0-py3-none-any.whl (9.1 kB view details)

Uploaded Python 3

File details

Details for the file unleash_django_util-1.0.0.tar.gz.

File metadata

  • Download URL: unleash_django_util-1.0.0.tar.gz
  • Upload date:
  • Size: 7.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for unleash_django_util-1.0.0.tar.gz
Algorithm Hash digest
SHA256 d157059b18514b0f20559c9ffeba8277ea46526dede0276da92bd175759f06f7
MD5 b88908f17aff3c5ea15e478c6dc586ce
BLAKE2b-256 3d706947a5bcce4d0af8a62b0cfc8368cced339828085de6889a25107f5aad60

See more details on using hashes here.

File details

Details for the file unleash_django_util-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for unleash_django_util-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ebfa7115007da69885c9ec13da25acaf1f329e137d9be9bc997709b1eaa081fd
MD5 07957cc72522173de2382c1563898d17
BLAKE2b-256 55f76ee3389529f243ca08423a4d21673163eff01262f9ea95b10b39c022d607

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