Skip to main content

Yet another dead simple feature switching library for Django.

Project description

# Django Hashbrown


Yet another dead simple feature switching library for Django.

Supports Django 1.8, 1.9 & 1.10.

## Installation

Django Hashbrown is [hosted on PyPI]( so
you can just install it using either:

$ pip install django-hashbrown


$ easy_install django-hashbrown

If you prefer to use the development version of it, you can clone the repository
and build it manually:

$ git clone
$ cd django-hashbrown
$ python install


## Usage

The main object to store feature switches data is `hashbrown.models.Switch`. This model has 4

* `label` - Short name to identify each Switch
* `description` - Longer description about what the switch is about
* `globally_active` - Marks the tag as active all the time
* `users` - M2M marking what users have the feature activated

### Python

The simplest way to work with Hashbrown is to use `is_active` method:

import hashbrown

if hashbrown.is_active('things'):

If the given switch doesn't exist it'll be created disabled by default. This
way `Switch` objects will never be on the database until code that checks it
gets executed.

Hashbrown switches can be linked to different users so only those people have
access to certain feature:

import hashbrown

if hashbrown.is_active('things', user_object):

### Django templates

Same way, you can use the templatetag `ifswitch`:

{% load hashbrown_tags %}

{% ifswitch 'test' %}
hello world!
{% else %}
{% endifswitch %}

Even with the user:

{% load hashbrown_tags %}

{% ifswitch 'test' user %}
hello world!
{% else %}
{% endifswitch %}

## Configuration

You can prepare your switches before they get created in your settings,
indicating that way either if it'll be enabled or disabled. You can add into
your `` something like:

'test': {
'globally_active': True
'things': {
'globally_active': False,
'description': 'This does some things'

So, when the switch "test" gets checked the first time, the switch will get
created globally active, while "things" won't be active but it'll have a

## Testing

Another useful feature is the ability to mock switches in your tests, so
you can write tests for any case you are covering. It'll look something like:

from hashbrown.testutils import switches

def test_things(self):
# whatever you wanna test

## Django management command

Django Hashbrown adds a 'switches' management command, which creates / deletes
switches defined in your HASHBROWN_SWITCH_DEFAULTS settings.

To create all switches listed in HASHBROWN_SWITCH_DEFAULTS:

python switches

Any existing switches already in the database will not be updated.

To create all switches and delete any switches *not* listed in

python switches --delete

You will be prompted for confirmation before the switches are deleted. Use
`--force` to delete the switches without confirmation.

## Acknowledgements

Django Hashbrown is based and takes some pieces of code from Django Gargoyle

Project details

Download files

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

Filename, size & hash SHA256 hash help File type Python version Upload date
django-hashbrown-0.7.0.tar.gz (8.9 kB) Copy SHA256 hash SHA256 Source None

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page