Redis watcher adapter for pycasbin
Project description
pycasbin redis watcher
Casbin role watcher to be used for monitoring updates to casbin policies
Installation
pip install pycasbin-redis-watcher
Basic Usage
Example used along with https://github.com/ScienceLogic/pycasbin/flask-authz
from flask_authz import CasbinEnforcer
from casbin_redis_watcher import RedisWatcher
casbin_enforcer = CasbinEnforcer(app, adapter)
watcher=RedisWatcher(redis_hostname, redis_port)
watcher.set_update_callback(casbin_enforcer.e.load_policy)
casbin_enforcer.set_watcher(watcher)
Using alongside UWSGI
This redis-watcher module starts separate processes which subscribe to a redis channel, and listens for updates to the casbin policy on that channel. When running within WSGI contexts (like uwsgi) you may want to start these processes as a postfork action. As is depicted below:
try:
from uwsgidecorators import postfork
print("Running in uwsgi context")
except ModuleNotFoundError:
print("Not running in uwsgi context")
postfork = None
if postfork:
@postfork
def load_watcher():
global casbin_enforcer
watcher = RedisWatcher(redis_info.hostname, redis_info.port)
watcher.set_update_callback(casbin_enforcer.e.load_policy)
casbin_enforcer.set_watcher(watcher)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pycasbin_redis_watcher-0.1.0-py3-none-any.whl.
File metadata
- Download URL: pycasbin_redis_watcher-0.1.0-py3-none-any.whl
- Upload date:
- Size: 3.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.7.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f3580de51e243819ef032493993af42fcc8aab450514f8d8f083c872029aea64
|
|
| MD5 |
f3f6914788b7ff272168fe313fc467eb
|
|
| BLAKE2b-256 |
72c3c491d30a13ee7f085068ff03e9e5213638623557706e08a5cdba2ad38abd
|