Skip to content

sanguinedab/pycasbin-mongo-watcher

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PyCasbin MongoDB Watcher

MongoDB watcher for PyCasbin. It enables distributed policy synchronization across multiple Casbin instances using MongoDB Change Streams.

Installation

pip install pycasbin-mongo-watcher

Quick Start

import casbin
from mongo_watcher import new_watcher

# Reload policy on updates
def on_update():
    enforcer.load_policy()

# Create MongoDB watcher
watcher = new_watcher(
    dsn="mongodb://localhost:27017",
    db_name="casbin",
    collection="casbin_watcher",
)
watcher.set_update_callback(on_update)

# Initialize Casbin enforcer
enforcer = casbin.Enforcer("path/to/model.conf", "path/to/policy.csv")
# Bind watcher to enforcer
enforcer.set_watcher(watcher)

License

Apache-2.0. See LICENSE.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages