Install & Compatibility
Where this runs
tested against v1.0.3 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.732s · 72MB
glibcpy 3.10–3.95 runs
installs and imports cleanly · install 4.6s · import 0.664s · 72MB
71MB installed
● package 71MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
rest_condition
✓ from rest_condition import C, And, Or, Not
Correct import for the main composable permission classes.
rest_condition
✓ from rest_condition import And, Or, Not
✗ from rest_condition import And, Or, Not, C
C is a shortcut for creating a condition from a custom permission class. It's not required for basic usage but often used.
Define a view with combined permission checks using logical operators. Placeholder permissions IsAdmin and IsOwner should be defined elsewhere.
from rest_framework.permissions import IsAuthenticated
from rest_condition import And, Or, Not
from rest_framework.views import APIView
class MyView(APIView):
permission_classes = [And(IsAuthenticated, ~Or(IsAdmin, IsOwner))]
def get(self, request):
return Response({"message": "Hello"})
Errors
Common errors & fixes
'list' object has no attribute 'has_permission'
Using a list of permission classes instead of a single condition instance.
fixUse rest_condition classes: `permission_classes = [And(IsAuthenticated, IsAdmin)]` instead of `[IsAuthenticated, IsAdmin]`
TypeError: __init__() takes 1 positional argument but 2 were given
Calling a rest_condition class without parentheses, e.g., `And(IsAuthenticated, IsAdmin)` vs using `And` alone.
fixEnsure you instantiate the condition: `And(IsAuthenticated, IsAdmin)`
AttributeError: 'And' object has no attribute 'has_permission'
Using an uninstantiated class reference in permission_classes, e.g., `permission_classes = [And]`.
fixInstantiate: `permission_classes = [And(IsAuthenticated)]`
Upgrade
Version history
1.0.3latest on PyPI · released Nov 1, 2016
Audit
Dependencies
djangorequiredCore dependency for Django projects
djangorestframeworkrequiredPermission classes are used with DRF views