A Flipper Cloud (https://www.flippercloud.io/) package for Django apps.
Project description
django-flippy
A Flipper Cloud package for Django apps. (Not affiliated with the Flipper Cloud folks, just think they're a good idea.) Feature flags for Django projects, because why should the Rails people have all the fun?
Installation
# pip install django-flippy
Then add flippy
to your INSTALLED_APPS
in settings.py
.
Finally, ./manage.py migrate
to run the migrations.
Usage
from django.contrib.auth.models import User
from flippy import Flippy
from flippy.backends import DjangoBackend
f = Flippy(DjangoBackend())
# create a feature
f.create('my_cool_feature')
# enable for half of all users
f.enable_percentage_of_actors('my_cool_feature', 50)
# check if a given user should get the feature
# (depending on chance, the user may or may not be flagged in -- if so,
# crank the percentage_of_actors up to 100 if you want to confirm it worked)
u = User.objects.get(pk=1)
if f.is_enabled('my_cool_feature', u):
print('This user gets the cool new feature.')
else:
print('This user gets the old, less cool feature.')
Using Flipper Cloud
The above recipe only uses the local Django-based backend and does not connect you to
Flipper Cloud. There is a FlipperCloudBackend
which expects a Flipper Cloud token
passed in the constructor:
from flippy import Flippy
from flippy.backends import FlipperCloudBackend
f = Flippy(FlipperCloudBackend('MY-TOKEN-HERE'))
but be warned: this backend makes direct API calls for every operation. There will be work to make Flipper Cloud a viable backend without having to make an HTTP request for every operation, coming soon.
Other improvements will include ways to easily access these features from views, templates, etc.
Testing
We test with pytest
.
By default, tests which require an active Flipper Cloud account aren't run.
You can run them with pytest -m flippercloud
.
Note that you must set FLIPPER_CLOUD_TOKEN
in your environment for them to run.
Creating and testing a new backend
You may want to store your feature data differently. You can model your backend
off of flippy.backends.MemoryBackend
, extending flippy.core.BaseBackend
and
implementing all the methods. That interface is how Flippy
(the user side) will
expect to interact with you. You can take a look at tests/memory_backend_test.py
to see how to run a suite of tests against your implementation.
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
Built Distribution
Hashes for django_flippy-0.8.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 06e5eea2ad26b129ba56d38e06154e7be56de4a97e6f69052d67e95c59e05308 |
|
MD5 | 8cd4cfee4fee87e05138f6159e9b6258 |
|
BLAKE2b-256 | 37d1e812234555df4aea4fffdc61336552e21499771970e03fc1a6cffdf618b8 |