Skip to main content

Rule registry for django

Project description

This is a simple alternative to django-rules. The core difference is that it uses as registry that can be modified on runtime, instead of database models.

One of the goal is to enable developpers of external apps to make rules, depend on it, while allowing a project to override rules.

Example your_app/

# Everybody can read a blog post (for now!):
rules_light.registry[''] = True

# Require authentication to create a blog post, using a shortcut:
rules_light.registry[''] = rules_light.is_authenticated

def is_staff_or_mine(user, rule, obj):
    return user.is_staff or == user

# But others shouldn't mess with my posts !
rules_light.registry[''] = is_staff_or_mine
rules_light.registry[''] = is_staff_or_mine

Example your_app/

class PostDetailView(generic.DetailView):
    model = Post

class PostCreateView(generic.CreateView):
    model = Post

class PostUpdateView(generic.UpdateView):
    model = Post

class PostDeleteView(generic.DeleteView):
    model = Post

You might want to read the tutorial for more.

What’s the catch ?

The catch is that this approach does not offer any feature to get secure querysets.

This means that the developper has to:

  • think about security when making querysets,
  • override eventual external app ListViews,


  • Python 2.7+ (Python 3 supported)
  • Django 1.8+

Quick Install

  • Install module: pip install django-rules-light,
  • Add to settings.INSTALLED_APPS: rules_light,
  • Add in settings.MIDDLEWARE_CLASSES (or settings.MIDDLEWARE for Django 1.10+): rules_light.middleware.Middleware,

You might want to read the tutorial.

There is also a lot of documentation, from the core to the tools, including pointers to debug, log and test your security.


Run tests with the tox command. Documented patches passing all tests have more chances getting merged in, see community guidelines for details.


You could subscribe to the mailing list ask questions or just be informed of package updates.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for django-rules-light, version 0.3.0
Filename, size File type Python version Upload date Hashes
Filename, size django-rules-light-0.3.0.tar.gz (16.7 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page