dj-optimizely
Introduction
Database-backed storage for your Optimizaly datafile and utilities for using Rollouts in Django.
Features:
- Database-backed storage for Optimizaly datafile
- Webhook endpoint to recieve datafile updates
- The webhook payload contains the datafile for the primary environment. If the current environment is not the primary environment, the webhook call will trigger a fetch of your current environment's datafile. Only your current environment's datafile is stored locally at this time.
- On server start the datafile will be initialized via a pull based on the provided datafile url
- Currently only supports Rollouts. Check if a featuee flag is enabled.
Quickstart
Install:
pip install dj-optimizely
Add djoptimizely to INSTALLED_APPS:
INSTALLED_APPS = [
...
'djoptimizely',
...
]
Add djoptimizely.middleware.optimizely_middleware to MIDDLEWARE:
MIDDLEWARE = [
...
'djoptimizely.middleware.optimizely_middleware',
...
]
Specify additional required settings:
OPTIMIZELY_ENVIRONMENT = 'staging'
OPTIMIZELY_WEBHOOK_SECRET = os.getenv('OPTIMIZELY_WEBHOOK_SECRET')
OPTIMIZELY_DATAFILE_URL = os.getenv('OPTIMIZELY_DATAFILE_URL')
Specify optional callbacks. Both functions take the request as the first parameter:
OPTIMIZELY_USER_ID_CALLBACK = 'myapp.module.get_user_id'
OPTIMIZELY_USER_ATTRIBS_CALLBACK = 'myapp.module.get_user_attribs'
Default callbacks:
def get_user_id_default(request):
if request.user.is_authenticated:
return request.user.pk
else:
return request.session._get_or_create_session_key()
def get_user_attribs_default(request):
attribs = {
'is_authenticated': False,
'is_staff': False
}
if request.user.is_authenticated:
attribs['is_authenticated'] = True
if request.user.is_staff:
attribs['is_staff'] = True
return attribs
Add the webhook to urls.py:
path('webhooks/', include('djoptimizely.urls')),
Check if a feature should be enabled:
from djoptimizely.services import get_feature_enabled
if get_feature_enabled(request, 'cool_stuff'):
print('Cool!')
Check in a template
{% load djoptimizely_tags %}
{% feature_enabled 'cool_stuff' as show_cool_stuff %}
{% if show_cool_stuff %}
<p>COOL Stuff!</p>
{% endif %}
Generic view mixin:
If the specified feature_key is not enabled for request.user return a 404
from djoptimizely.mixins import OptimizelyFeatureViewMixin
from django.views.generic.base import TemplateView
class CoolView(OptimizelyFeatureViewMixin, TemplateView):
feature_key = 'cool_stuff'
...
Metadata
Release files for dj-optimizely 0.0.8
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| dj-optimizely-0.0.8.tar.gz | 7.2 kB | Without provenance | Details for dj-optimizely-0.0.8.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| dj_optimizely-0.0.8-py3-none-any.whl | Python 3 | none | any | Details for dj_optimizely-0.0.8-py3-none-any.whl |
Total release size: 18.1 kB
Release files / dj-optimizely-0.0.8.tar.gz
| Download URL | dj-optimizely-0.0.8.tar.gz |
|---|---|
| Size | 7.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3f5bf5da256832274f871c71efbbcbc4d29d26bf06360ca8abe5d16ce6f85559
|
|
BLAKE2b-256 checksum How to use checksums |
69f578fb574b135945abf8ca55366a84972b7ebb0565c0eab811ae0fd0196570
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/3.10.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.56.1 CPython/3.8.7
|
Release files / dj_optimizely-0.0.8-py3-none-any.whl
| Download URL | dj_optimizely-0.0.8-py3-none-any.whl |
|---|---|
| Size | 10.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1590ef69d9e66a409e025971b89c8dfd0f84f908a1703fce2bfe4732fe0a5622
|
|
BLAKE2b-256 checksum How to use checksums |
f244725b55911759a6e9b11e634b9bdb94dbfb1747a67e81e973f0321b9c22a7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/3.10.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.56.1 CPython/3.8.7
|
Security for dj-optimizely 0.0.8
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.