{"id":23159,"library":"rest-condition","title":"REST Condition","description":"Rest Condition provides a simple, declarative way to compose complex permission checks for Django REST Framework views using logical operators (&, |, ~). Current version is 1.0.3, with infrequent updates.","status":"active","version":"1.0.3","language":"python","source_language":"en","source_url":"https://github.com/caxap/rest_condition","tags":["django","django-rest-framework","permissions","authorization"],"install":[{"cmd":"pip install rest-condition","lang":"bash","label":"PyPI"}],"dependencies":[{"reason":"Core dependency for Django projects","package":"django","optional":false},{"reason":"Permission classes are used with DRF views","package":"djangorestframework","optional":false}],"imports":[{"note":"Correct import for the main composable permission classes.","wrong":"","symbol":"rest_condition","correct":"from rest_condition import C, And, Or, Not"},{"note":"C is a shortcut for creating a condition from a custom permission class. It's not required for basic usage but often used.","wrong":"from rest_condition import And, Or, Not, C","symbol":"rest_condition","correct":"from rest_condition import And, Or, Not"}],"quickstart":{"code":"from rest_framework.permissions import IsAuthenticated\nfrom rest_condition import And, Or, Not\nfrom rest_framework.views import APIView\n\nclass MyView(APIView):\n    permission_classes = [And(IsAuthenticated, ~Or(IsAdmin, IsOwner))]\n    def get(self, request):\n        return Response({\"message\": \"Hello\"})","lang":"python","description":"Define a view with combined permission checks using logical operators. Placeholder permissions IsAdmin and IsOwner should be defined elsewhere."},"warnings":[{"fix":"Instantiate the condition: `permission_classes = [And(IsAuthenticated, IsAdmin)]`","message":"rest_condition classes are not callable directly; they must be instantiated. For example, use `And(IsAuthenticated)` not `And`.","severity":"gotcha","affected_versions":"all"},{"fix":"Ensure no side effects in permission checks, or be aware of evaluation order.","message":"Order of conditions matters: `And(cond1, cond2)` short-circuits on first False, `Or` short-circuits on first True. Unexpected results can occur if side effects exist.","severity":"gotcha","affected_versions":"all"},{"fix":"Define custom permissions with explicit boolean returns.","message":"Permission classes used inside rest_condition must have `has_permission` or `has_object_permission` methods returning bool. Mixing with DRF's `SAFE_METHODS` pattern may cause confusion.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Use rest_condition classes: `permission_classes = [And(IsAuthenticated, IsAdmin)]` instead of `[IsAuthenticated, IsAdmin]`","cause":"Using a list of permission classes instead of a single condition instance.","error":"'list' object has no attribute 'has_permission'"},{"fix":"Ensure you instantiate the condition: `And(IsAuthenticated, IsAdmin)`","cause":"Calling a rest_condition class without parentheses, e.g., `And(IsAuthenticated, IsAdmin)` vs using `And` alone.","error":"TypeError: __init__() takes 1 positional argument but 2 were given"},{"fix":"Instantiate: `permission_classes = [And(IsAuthenticated)]`","cause":"Using an uninstantiated class reference in permission_classes, e.g., `permission_classes = [And]`.","error":"AttributeError: 'And' object has no attribute 'has_permission'"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}