Skip to main content
https://img.shields.io/pypi/v/django-rules-light.svg https://img.shields.io/github/actions/workflow/status/yourlabs/django-rules-light/ci.yml?branch=master

This is a simple alternative to django-rules. Its core difference is that it does not rely on models. Instead, it uses a registry which can be modified at runtime.

One of its goals is to enable developers of external apps to make rules, depend on it, while allowing a project to override rules.

Example your_app/rules_light_registry.py:

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

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

# But others shouldn't mess with my posts !
def is_staff_or_mine(user, rule, obj):
    return user.is_staff or obj.author == user

rules_light.registry['blog.post.update'] = is_staff_or_mine
rules_light.registry['blog.post.delete'] = is_staff_or_mine

Example your_app/views.py:

@rules_light.class_decorator
class PostDetailView(generic.DetailView):
    model = Post

@rules_light.class_decorator
class PostCreateView(generic.CreateView):
    model = Post

@rules_light.class_decorator
class PostUpdateView(generic.UpdateView):
    model = Post

@rules_light.class_decorator
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 you have to:

  • think about security when making querysets,

  • override eventual external app ListViews,

Requirements

  • Python 3.10+

  • Django 4.2+

Quick Install

  • Install module: pip install django-rules-light,

  • Add to settings.INSTALLED_APPS: rules_light,

  • Add in settings.MIDDLEWARE: 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.

Contributing

Run tests with the tox command. Documented patches passing all tests have a better chance to get merged in. See the contributing guidelines for details.

Resources

To ask questions or just get informed about package updates, you could subscribe to the mailing list.

Metadata

Release files for django-rules-light 0.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-rules-light 0.4.0
File Size Uploaded Provenance
django_rules_light-0.4.0.tar.gz 18.0 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for django-rules-light 0.4.0
File Interpreter ABI Platform
django_rules_light-0.4.0-py3-none-any.whl Python 3 none any Details

Total release size: 43.0 kB

Release files / django_rules_light-0.4.0.tar.gz

Download URL django_rules_light-0.4.0.tar.gz
Size 18.0 kB
Tags Source
SHA-256 checksum
How to use checksums
0e20506560be3ab066e417670b898159f923820ac8e0d78183fab1b6267807a3
BLAKE2b-256 checksum
How to use checksums
b57ac29d80455907954eef6d3e6993ada23248b78b3c42b6834393cc8017f4fd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.4

Release files / django_rules_light-0.4.0-py3-none-any.whl

Download URL django_rules_light-0.4.0-py3-none-any.whl
Size 25.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
92187178d01b3332b18b68e2069338d28b206124b1b1637322539f42c31c3d90
BLAKE2b-256 checksum
How to use checksums
beb257a479347f0ac3df7bfb962b0683e3e24a2aa2498fed376bab8f9c97491b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.4

Security for django-rules-light 0.4.0

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page