django-flippy


Namedjango-flippy JSON
Version 0.8.0 PyPI version JSON
download
home_pagehttps://github.com/vtbassmatt/django-flippy
SummaryA Flipper Cloud (https://www.flippercloud.io/) package for Django apps.
upload_time2023-09-05 17:53:38
maintainer
docs_urlNone
authorMatt Cooper
requires_python>=3.11,<4.0
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # django-flippy

A [Flipper Cloud](https://www.flippercloud.io/) 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

```ShellSession
# pip install django-flippy
```

Then add `flippy` to your `INSTALLED_APPS` in `settings.py`.
Finally, `./manage.py migrate` to run the migrations.

## Usage

```python
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:

```python
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.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/vtbassmatt/django-flippy",
    "name": "django-flippy",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.11,<4.0",
    "maintainer_email": "",
    "keywords": "",
    "author": "Matt Cooper",
    "author_email": "vtbassmatt@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/c3/26/bcf6b4e44d0465e17ba1c00c7ff16a22c2cbfa571820bfd7d7505c2d9758/django_flippy-0.8.0.tar.gz",
    "platform": null,
    "description": "# django-flippy\n\nA [Flipper Cloud](https://www.flippercloud.io/) package for Django apps.\n(Not affiliated with the Flipper Cloud folks, just think they're a good idea.)\nFeature flags for Django projects, because why should the Rails people have all the fun?\n\n## Installation\n\n```ShellSession\n# pip install django-flippy\n```\n\nThen add `flippy` to your `INSTALLED_APPS` in `settings.py`.\nFinally, `./manage.py migrate` to run the migrations.\n\n## Usage\n\n```python\nfrom django.contrib.auth.models import User\n\nfrom flippy import Flippy\nfrom flippy.backends import DjangoBackend\n\nf = Flippy(DjangoBackend())\n\n# create a feature\nf.create('my_cool_feature')\n\n# enable for half of all users\nf.enable_percentage_of_actors('my_cool_feature', 50)\n\n# check if a given user should get the feature\n# (depending on chance, the user may or may not be flagged in -- if so,\n# crank the percentage_of_actors up to 100 if you want to confirm it worked)\nu = User.objects.get(pk=1)\nif f.is_enabled('my_cool_feature', u):\n  print('This user gets the cool new feature.')\nelse:\n  print('This user gets the old, less cool feature.')\n```\n\n## Using Flipper Cloud\n\nThe above recipe only uses the local Django-based backend and does not connect you to\nFlipper Cloud. There is a `FlipperCloudBackend` which expects a Flipper Cloud token\npassed in the constructor:\n\n```python\nfrom flippy import Flippy\nfrom flippy.backends import FlipperCloudBackend\n\nf = Flippy(FlipperCloudBackend('MY-TOKEN-HERE'))\n```\n\nbut be warned: this backend makes direct API calls for every operation. There will\nbe work to make Flipper Cloud a viable backend without having to make an HTTP request\nfor every operation, coming soon.\n\nOther improvements will include ways to easily access these features from views,\ntemplates, etc.\n\n## Testing\n\nWe test with `pytest`.\nBy default, tests which require an active Flipper Cloud account aren't run.\nYou can run them with `pytest -m flippercloud`.\nNote that you must set `FLIPPER_CLOUD_TOKEN` in your environment for them to run.\n\n### Creating and testing a new backend\n\nYou may want to store your feature data differently. You can model your backend\noff of `flippy.backends.MemoryBackend`, extending `flippy.core.BaseBackend` and\nimplementing all the methods. That interface is how `Flippy` (the user side) will\nexpect to interact with you. You can take a look at `tests/memory_backend_test.py`\nto see how to run a suite of tests against your implementation.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A Flipper Cloud (https://www.flippercloud.io/) package for Django apps.",
    "version": "0.8.0",
    "project_urls": {
        "Homepage": "https://github.com/vtbassmatt/django-flippy",
        "Repository": "https://github.com/vtbassmatt/django-flippy.git"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "37d1e812234555df4aea4fffdc61336552e21499771970e03fc1a6cffdf618b8",
                "md5": "8cd4cfee4fee87e05138f6159e9b6258",
                "sha256": "06e5eea2ad26b129ba56d38e06154e7be56de4a97e6f69052d67e95c59e05308"
            },
            "downloads": -1,
            "filename": "django_flippy-0.8.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "8cd4cfee4fee87e05138f6159e9b6258",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.11,<4.0",
            "size": 15732,
            "upload_time": "2023-09-05T17:53:36",
            "upload_time_iso_8601": "2023-09-05T17:53:36.781525Z",
            "url": "https://files.pythonhosted.org/packages/37/d1/e812234555df4aea4fffdc61336552e21499771970e03fc1a6cffdf618b8/django_flippy-0.8.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c326bcf6b4e44d0465e17ba1c00c7ff16a22c2cbfa571820bfd7d7505c2d9758",
                "md5": "ff47db86e5b0e3d61de21511f7cc581d",
                "sha256": "c3e973a58f4260883e07af8d53f992bf38051925ed007f79a61374873a41d272"
            },
            "downloads": -1,
            "filename": "django_flippy-0.8.0.tar.gz",
            "has_sig": false,
            "md5_digest": "ff47db86e5b0e3d61de21511f7cc581d",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.11,<4.0",
            "size": 22117,
            "upload_time": "2023-09-05T17:53:38",
            "upload_time_iso_8601": "2023-09-05T17:53:38.337537Z",
            "url": "https://files.pythonhosted.org/packages/c3/26/bcf6b4e44d0465e17ba1c00c7ff16a22c2cbfa571820bfd7d7505c2d9758/django_flippy-0.8.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-09-05 17:53:38",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "vtbassmatt",
    "github_project": "django-flippy",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "django-flippy"
}
        
Elapsed time: 0.17045s