skillfed

rules

Awesome Django authorization, without the database

rules v3.5 563.4K downloads/30d#5,980 on PyPI1,978
Permissive license MIT AGING released

What it is and what it does

rules is a lightweight authorization framework that lets you define object-level permissions using predicates—callable functions that return True or False based on user and object state. Instead of storing permissions in a database, you compose predicates using logical operators to build rule sets that determine what actions a user can perform on specific objects. It integrates seamlessly with Django views, templates, and the admin interface, but can also be used standalone in non-Django contexts.

The core idea is simple: predicates are any callable accepting zero to two arguments (typically user and object), and you combine them with operators to express complex authorization logic. You add rules to a rule set, then test them against a user and object to get a boolean result. This approach avoids database queries for permission checks and keeps authorization logic in code where it's easier to version control and reason about.

Use it for:

  • Enforce object-level permissions in Django views—e.g., allow users to edit only their own posts or comments
  • Build custom authorization logic for REST APIs without storing per-object permissions in the database
  • Implement role-based or attribute-based access control using predicates that inspect user roles or object properties
  • Test authorization rules in unit tests by composing predicates without needing fixtures or test data
  • Protect Django admin actions—e.g., allow deletion only if the user is the object's owner

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

rules provides object-level permission checking for Django applications using rule-based predicates instead of database queries, and can also be used as a standalone predicate framework in other contexts.

Yes, if you need lightweight object-level permissions in Django and prefer logic-based rules over database-backed permissions. The package is stable (Production/Stable status), has no known vulnerabilities, and zero runtime dependencies. However, the aging maintenance status (last release 711 days ago) means you should verify compatibility with your target Django version and be prepared to maintain a fork if critical issues arise.

Install

rules on PyPI

pip

pip install rules

uv

uv add rules

poetry

poetry add rules

Installing rules

Before you install

Low install friction with no runtime dependencies. Maintenance status is aging—last release was 711 days ago (2024-09-02), though the repository remains active with recent commits and 1978 stars. Suitable for established projects but check if active maintenance matters for your use case.

License in practice

MIT license permits commercial and private use with minimal restrictions. You must include a copy of the license and copyright notice, but can modify and distribute freely.

Quickstart

pip install rules

import rules

@rules.predicate
def is_author(user, book):
    return book.author == user

rules.add_rule('can_edit_book', is_author)
rules.test_rule('can_edit_book', user, book)

Requires Python 3.8 or newer. Optional Django integration requires Django 3.2 or newer.

Verify before relying

  • Whether the aging maintenance status (711 days since last release) affects compatibility with current Django versions
  • Performance characteristics when evaluating complex predicate graphs at scale

Package facts

License MIT (permissive)
Python support not specified
Install friction low — pure-Python wheel
Runtime dependencies none
Maintenance aging — 711 days since the last release
Last repo commit
First released
Downloads 563,384/month — #5,980 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: rules-3.5-py2.py3-none-any.whl

Development Status :: 5 - Production/StableEnvironment :: Web EnvironmentFramework :: DjangoIntended Audience :: DevelopersLicense :: OSI Approved :: MIT LicenseOperating System :: OS IndependentProgramming Language :: PythonProgramming Language :: Python :: 3Programming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9

Tags

django object permissionsrule-based authorizationpredicate frameworkdjango access controlpermission decoratorsdecision tree permissionsdjango authorization without database
django-permissionsauthorizationpredicate-logic

More Application Frameworks packages