Skip to main content

Lightweight feature flags for django

Project description

django-fflag

Build Status codecov

Lightweight feature flag for django.

Feature flag is useful technique to develop your software. When you implement new functionality in you project, you probably want to enable it gradually for some users.

django-fflags is realization of feature flag mechanism with following benefits:

  • flags can be enabled to some part of your users or concrete users list
  • flags part will be different and depends on your flag name
  • it will works with any users count

Learn more about feature flags: https://www.martinfowler.com/articles/feature-toggles.html

Installation

Install package:

pip install django-fflag

Add following configuration to settings.py:

INSTALLED_APPS = (
    ...,
    "fflag",
)

MIDDLEWARE = (
    ...,
    "django.contrib.auth", # FFlagMiddleware uses request.user.id
    "django.contrib.sessions", # FFlagMiddleware uses request.session to store unauthenticated client id
    ...,
    "fflags.middleware.FFlagMiddleware",
)

# Persistent cache storage strongly recommended for feature-flags.
# You can configure custom persistent cache using following config:

FFLAG_CACHE_NAME = "fflag"

CACHES = {
    ...,
    "fflag": {
        'BACKEND': 'django.core.cache.backends.db.DatabaseCache',
        'NAME': 'fflag_flags',
    }
}

Usage

When you write new code, you may wrap it with following if:

if request.fflag_enabled("my_new_feature"):
    ...

or without request:

if fflag_enabled(uniq_client_id, "my_new_feature"):
    ...

That means that your code will be not executed until feature flag is enabled.

To manage feature flags you may use following management commands:

  • manage.py fflag_list - print list of used feature flags.
  • manage.py fflag_list_enabled_for - print list enabled feature flags for specified id (usually user id).
  • manage.py fflag_get - print information for specified feature flag.
  • manage.py fflag_set_part - set feature flag enable part. For example 0.4 will enable functionality for ~40% of users.
  • manage.py fflag_add_part_ids - extend feature flag part enabled ids (usually user ids)
  • manage.py fflag_set_part_ids - override feature flag part enabled ids (usually user ids)

IMPORTANT NOTE: Feature flag will be invisible by management commands after fflag_enabled function will be called.

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

django-fflag-0.2.0.tar.gz (5.7 kB view details)

Uploaded Source

File details

Details for the file django-fflag-0.2.0.tar.gz.

File metadata

  • Download URL: django-fflag-0.2.0.tar.gz
  • Upload date:
  • Size: 5.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/42.0.2 requests-toolbelt/0.8.0 tqdm/4.46.0 CPython/3.7.6

File hashes

Hashes for django-fflag-0.2.0.tar.gz
Algorithm Hash digest
SHA256 a77e3270d8df3409b0f2a9cb0ef4dc76fbe5d72b49a05ba3e77b583a3912ac24
MD5 a2b6e85ad3dcd91e479b0464fc6afe15
BLAKE2b-256 5bfca385ca67ea22bdadc26f144209930186c53af3d49d9cab3edc44d5c17313

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